Developing Programmers .com

Local Search:



This site is optimized for standards so you can use any standards compliant browser:

Valid XHTML 1.0 Transitional
Valid CSS!
(RSS) RSS Feed

Web Search:
Google


Wednesday, 1 February, 2006

Wrong Code  

This week’s short article is once again referring to programmerJoel, aka the famous Joel Spolsky.

In his article, “Making Wrong Code Look Wrong“, Joel discusses the idea that besides having some style, whatever it might be, a key to good programming is to engineer the conventions for a project so that wrong things look wrong. This can be done by organizing code so that the main consequences of a line of code, and the semantics of the line of code, are visible locally, without having to search around the program to see what’s really going on.

Joel also points out the difference between “Apps Hungarian Notation” and “Systems Hungarian Notation”, which is basically that the prefixes used in Apps Hungarian Notation refer to the semantics of the variable (size, difference, relative to screen, etc) rather than the data type that the compiler is already watching for you. In Apps Hungarian Notation, or any other naming convention that values making semantics clear, you can see when you are doing something wrong like assigning a distance-from-window-edge variable to a distance-from-printed-page-edge variable.

Take a look through his article, it’s quite worthwhile especially if you’ve tried to make sense of Hungarian Notation before — you might have been looking at examples of the misunderstood version of Hungarian Notation.

Posted by sarah at 10:27 am in: Plugs , Style (3487 views)

2 Comments

  1. So, why not make safe_string and unsafe_string different types and let the compiler tell us when the code is wrong?

    Now, the answer to that is obvious, but I’m rather missing it from the article.

    Besides, like all obvious answers, it tempts one to think it’s wrong. If these problems can be solved as mechanically as he seems to imply, surely a mechanical tool ought to be devised? Especially since one already exists, addressed exactly to his example (Perl’s “taint” checks)? Admittedly, redesigning programming languages is rather beyond the scope of his article or this, but…

    Comment by jiri — On 1-2-2006 at 2:22:35 PM

  2. Actually, such a tool already exists for C, too - it’s called sparse and it’s used to check the Linux kernel.

    Comment by jiri — On 8-3-2006 at 12:58:05 AM

Please use the DP Forums for further discussion of this topic.