2014-07-14

What do you need a debugger for?

In my many years of experience in programming I have noticed that there are some programmers who refuse to use a debugger, or try to use the debugger as little as possible, as in, only when they run out of alternative options. They tend to rely solely on the diagnostic log to troubleshoot problems in their code, so their code tends to spew thousands of lines of log entries per second, and they keep trying to divine the causes of exceptions by just looking at post-mortem stack traces.

Quite often these people do not understand what usefulness others find in debuggers.  I once requested the lead developer of a certain shop (Powernet, Athens, Greece, circa 2000) to enable debugging for me on their development web server so that I can run my debugger on the web site that I was developing in that shop, and she asked me "what do you need a debugger for?" Luckily, she proceeded to fulfil my request after a couple of long seconds of me staring blankly at her.

Listen folks, if you want to be called a "programmer" and if you want to be worth the cost of the keyboard you are pounding on, the debugger needs to be your absolute first tool of choice at the slightest need for troubleshooting, not your last tool of choice, not even your second tool of choice. Companies that develop IDEs go through huge pains to provide us with nice sleek and powerful debuggers so that we can do our job better, don't you dare let their efforts go to waste.

A call stack trace in the diagnostic log of your program will tell you which function was called by which function, and that's all.  This is enough in many simple cases, but when things get just slightly complicated, (and they usually do,) it is not enough.  Lacking any additional information, what you end up doing is theorizing about what might have happened instead of looking and seeing what has happened.

2014-06-04

Pronouncing the name of your web server

A memo to developers all over the world whose native language is not English:
Sign of the Apache Web Server
Folks, just so that you know, the world famous Apache Software Foundation which lends its name to its world famous Apache Web Server is not pronounced uh-pach;  it is pronounced uh-pach-ee.  The final letter is not a silent "e", it is a loudly and clearly pronounced "e".

There exist two words in English which are spelled "Apache";  one is of French origin, and according to dictionary.com it means "a Parisian gangster, rowdy, or ruffian".  This one does end in a silent "e", but it is not the one that the Apache Software Foundation was named after.  The other word is of Mexican-Spanish origin, it means "a member of an Athabaskan people of the southwestern U.S.", it ends in a definitely non-silent "e", and it is the word you are looking for.

Head over to dictionary.com to check out these two words and click on the little speaker icons to hear their pronunciation: http://dictionary.reference.com/browse/apache

Also, in the Wikipedia article about the Apache Software Foundation (http://en.wikipedia.org/wiki/Apache_Software_Foundation) we read:
The name 'Apache' was chosen from respect for the Native American Apache Nation, well known for their superior skills in warfare strategy and their inexhaustible endurance. It also makes a pun on "a patchy web server"—a server made from a series of patches—but this was not its origin.
And as a side note to fellow USAians: The same applies to the world famous Porsche brand of cars: the final "e" is not silent.  Please quit saying porsh; it is por-sheh.  See: http://youtu.be/4OuPY-1snyw

2014-05-13

Picture of Earth from Orbit in Cosmos S01E07

Nowadays the interwebz abounds with beautiful images of our Earth from orbit. Lately I have picked up the habit of trying to figure out what part of our world is visible when I see such an image. It is usually quite a puzzle, since the scale of the picture is not always obvious, parts of it are always obscured by clouds, the North can really be anywhere, and worst of all, countries are not painted with different colours! (Duh!) I am usually successful in this, but today I had a real tough one.

A couple of seconds into Cosmos: S01E07, there is a picture of Earth from orbit. Click on the picture below and see if you can identify the visible land before reading further down.



You might think that it is really obvious, but then try to verify your hypothesis by comparing the picture above against google earth, and whoops, you will see that you were wrong.

So, what's going on?

2014-05-12

"By using this site, you agree to the use of cookies."

If you live outside of Europe you might be lucky enough to have no idea what this is all about, but if you live in Europe you are probably sick and tired by now of this message popping up every time you first visit a site:
"This site uses cookies to help deliver services. By using this site, you agree to the use of cookies." [Learn more] [Got it]
The creators of these sites are not to blame for these messages; they are being forced to display them against their will, (and waste money and resources in doing so,) in order to comply with EU regulations. These messages are mandated by law.

I mean, really, how about this:
"This site uses the Helvetica font to help deliver services. By using this site, you agree to the use of Helvetica." [Learn more] [Got it]
Or this:
"This site uses TCP/IP to help deliver services. By using this site, you agree to the use of TCP/IP." [Learn more] [Got it]
All these statements make precisely the same amount of sense: none.

The legislators who came up with the one about cookies are a bunch of technically illiterate ignoramuses who, in a fashion typical of politicians full of shit, have the audacity to be legislating on things they have absolutely no clue about.  They should be removed from office and prohibited from ever holding any job other than milking goats.

2014-04-23

Stackoverflow.com question deleted within 2 minutes.

This question was sighted on stackoverflow.com on Thursday, April 30, 2013.  It was deleted within 2 minutes from being posted, but not before I managed to take a screenshot of the summary.

It is funny when you can tell what's wrong with the code by just looking at the summary!

2014-03-31

Fixing the AutoCloseable interface of Java

Java 7 introduced the AutoCloseable interface, which is roughly equivalent to the IDisposable interface of C#, to be used in synergy with the new try-with-resources statement, which is equivalent to the using-disposable construct of C#.

The problem with Java's AutoCloseable interface is that its close() method is declared to throw a checked exception: void close() throws Exception. This is a problem if you are one of the many programmers who prefer unchecked exceptions over checked ones, because it forces you to deal with checked exceptions every time you write a try-with-resources statement, despite the fact that none of your classes ever throw any checked exceptions on close().  Simply declaring that your class implements AutoCloseable forces checked exceptions upon you.

Luckily, there is a fix for this.  Here it is:
public interface AutoCloseable2 extends AutoCloseable
{
    @Override
    void close();
}
There, I fixed it for you.

By declaring a new interface which redefines the close() method as not throwing any checked exceptions, the problem goes away.


P.S.

I just looked at the Oracle documentation for the AutoCloseable interface and found out that this had already been anticipated:

"[...] subclasses of the AutoCloseable interface can override this behavior of the close method to throw specialized exceptions, such as IOException, or no exception at all."

2013-07-08

Solved: svchost.exe high CPU and memory

A few days ago one of the svchost.exe processes on my machine (Win7 64) started exhibiting this annoying behavior: it will start with about 30 to 40 megabytes of memory, which stays roughly constant for a while, but then later it begins bloating, slowly but surely, possibly at a slightly exponential rate, until a few hours later it is taking up so many gigabytes that I cannot work on my computer anymore. So, I have to stop what I am doing, save everything, and restart the computer, only to have to go through the same ordeal a few hours later.

On at least two occasions I have witnessed this happening along with unreasonably high CPU utilization, up to a full CPU core.

Obviously, this started happening after I installed or tweaked something, but I did not notice the precise point in time that it started happening, and my machine is a busy machine, so I had no suspects to name.

I looked around the interwebz for a solution, but to no avail.  People give some good troubleshooting hints, but nobody seems to have an actual solution.

The svchost.exe process which causes the problem contains the following services:


2013-07-07

A monstrous Visual Studio 2010 intellisense bug

I had this happening on my development machine, (I use C# on VS2010) so I went over to The Code Project and asked if anyone else could reproduce it, and sure enough, it has been confirmed.
Steps to reproduce:

Create a new project, make it a C# console application, use all default settings. Open the generated Program.cs file and replace its contents with the following:

namespace ConsoleApplication1
{
    public class ParameterAttribute: System.Attribute
    {
    }

    class Program
    {
        [Parameter( name:"foo" )]
        int Field1;

        static void Main( string[] args )
        {
        }
    }
}



I know, there is an error in the code; please bear with me:


2013-06-07

Vintage stuff from my days of 320x200-pixel 256-color VGA

Techniques demonstrated:

  • Ultra-fast font rendering
  • Ultra-fast bitmap scaling
  • Ultra-fast bitmap rotation
  • Projection of 3D structures to 2D for rendering
  • Invisible surface detection
  • Ultra-fast rendering of lines and polygons directly into video RAM
  • Gouraud shading
  • Ultra-fast dithering
  • A voxel rendering experiment
  • A tiled floor rendering experiment

Summary (just give me the TL;DR)

A collection of very short YouTube videos of graphics demos that I did all by myself at home for fun back in the mid-nineties (when I was in my twenties) rendering pixels directly into the video RAM of the 320x200-pixel, 256-color palette VGA without the use of any libraries. Everything is in C or C++ with the crucial routines written in 80386 assembly, in some cases generating machine code on the fly.

2013-06-05

A few samples of my work on Darkfall Online

The development of a game like Darkfall Online in a country like Greece was a rather unlikely thing to happen, so I consider myself very lucky that it happened and that I was part of it.  Here is the wikipedia page for the game: https://en.wikipedia.org/wiki/Darkfall

The funding came from a Greek-Libyan family which has made enough money out of oil-related construction to be able to afford the luxury of investing on something fun, rather than on something with a high ROI, or even a guaranteed ROI. Thus Razorwax, a promising team of Norwegians some of whom were already published in the gaming industry, was brought to Greece to build Darkfall.  I was the first Greek programmer hired, and I worked primarily on the GUI of the game. I stayed with the company for about a year after the game was released.

Me at Aventurine, in 2004. Click to enlarge.
What follows is a rough diagram of the design of the GUI that I built for Darkfall: The graphics engine (written by a colleague in C++) provided me with just two asynchronous primitives, one for drawing textures, and one for drawing text. The layer we called middleware (written by another colleague, also in C++) provided me with the functionality of the "GetTextExtents" Win32 GDI function, and with an interface to the browser window (encapsulated instances of Microsoft Internet Explorer.)