Archive for May, 2010

Only Your Opinion

No Comments »

WTFBWA friend of mine once worked on some code with a number of other people. At some point he found a large chunk of code that was unreachable, yet someone was working on it. After some inquires about the nature of the code, the person working on it got quite hostile, claiming the code was crucial and was in fact reachable. At some point a manager intervened. This manager listened to both parties and sumed up the problem. “So you claim the code will never be executed and you claim the code is crucial.” Both, my friend the coder and the other person agreed. Without much further thought, the manager decided that the other person should keep working on their code, claiming: “This is really a no-brainer. Since you both did not list any negative performance consequences, we don’t change anything.” When my friend emphasized again that the code was unreachable he was met with “But that is only your opinion.”


Can Someone Please Help Me

No Comments »

solidcodeIf I had a dime for every time I had to read a request like the one below, I’d still be reading comp.lang.c instead of the .moderated version.

> Dear everyone,
>  Can someone please help me on my HW.
>  I'm trying to write a program that will
>  display the following:
>
>      *
>     ***
>    *****
>   *******
>   *******
>    *****
>     ***
>      * 


As you can see on the left, Richard J. Heathfield has a different, much funnier, approach. It almost makes me go back to the unmoderated group, almost. (Thanks, John)


Post Assignment

No Comments »

A while back, I designed a domain specific language. It combines the good of APL, C, Pascal and SQL. For example, the token ‘=‘ is not used, ‘:=‘ is the assign-token and ‘==‘ is the equal-token. Like C, it uses only ASCII characters and, like APL, it has a minimalistic, mathematical notation. There is no muli- or list-assign, like in Python and Perl, eventhough code like this: ‘(a,b,c) := (b,c,3);‘ just looks so cool and intuitive. But, it did not fit the syntax, it would make it hard to parse (both for humans and for the LR parser) and most of all it went against the minimalisticity. Than I came up with ‘=:‘, the post-assignment operator. It took me but five minutes to implement. It is a regular assignment but returns the old lvalue. For example ‘a =: 3;‘ would assign ‘3‘ to ‘a‘ and return what ever value was in ‘a‘ before. Post-assignment; analogous to the post-increment from C. IMHO, It makes the above shift even more elegant to read: ‘a =: b =: c =: 3;‘. It was love at first sight! However, the smartest person I know (and first programmer in this language) did not see the need for this opperator and neither did anyone else. So I swallowed my pride and removed the ten odd LOCs. I cried myself to sleep that night.


I’m Aware My Code Is a Sad Affair

No Comments »

I was recently asked to hunt a bug in some of my old code. It was a shell script generating Postscript, generating .PNG files for a website. It had “organically” grown over some years and started generating bad Postscript starting May 1st. Since Postscript is well designed and has good error handling, it did not take long to find the problem. The word May had not been replaced by a 120 (the year day number of May 1st). Here is a sniped:

sed-error

Note the ‘r’ that should be a ‘y’ in the center LOC. My bad. However, I realized that, in theory, this error could have been caught (by sed) because the second /[Mm]ar[^ ]*/ would not ever be satisfied. Sadly, I can’t make sed find my bad code, but I can dream, can’t I?