Thursday, August 21, 2008

Easy C

After reading this 'Daily WTF' I first laughed, but then I suddenly noticed the this particular line:
/* arithmetic operators */
#define MOD %

.. when I realised this actually solves one of my little annoyances that I had for as long as I program in C or C# : I never remember the 'modulo' operator !
Since it's not something you need everyday I always end up looking at some kind of standard C manual to find out what it was. And nine out of ten times I first hit a compilation error because I use the (non existent) mod(x) function. I think this has to do with the fact that the '%' sign is not in any way related to a 'real' mathematical operator like +, -, / or * . Probably the C language developers just felt that the modulo operation should be a keyword, and the % was the last unused character on the keyboard.
And what about the '==' versus '=' mistake, often marked as the most frequently made mistake in C programming ? Using just ' #define EQUALS == ' would really eliminate this type of error. So maybe there is something to say for this 'Better C'. If it helps you in writing programs faster because you it makes things look more natural to you, then why not do it like this ?

No comments: