Month: December 2007

I am very old

It is official, at least according to the young man (he’s 20, I can’t call him a boy) I give private programming lessons to. He said that his class is full of “old people” – most of them is even 30 or older! Scary! Anyway I have been programming for more years of my life than not and most of them have been spent on the C language. Maybe that classifies me as very old nonetheless. After all C had been designed and developed nearly 4 decades ago, when I was 4.
One of the question in an exam attended by my tutored boy was:

Define the result of the following expression given x=N and y=k

x = (y+1>x) ? x++ : y++;

Suddenly a bell rang in my head. Red alert was buzzing at full-volume, but another bell was ringing as well.
The main red alert was labeled as “Undefined Behavior”. Every bad thing could happen when U.B. is invoked by the unknowing programmer. If he is lucky then he just gets something out of the order he expects, otherwise he can blow everything up.
Back in the days where Real Men wrote their own compiler, the C designers decided to relax some constraints in the language semantics so that more aggressive optimizations could be implemented in the compilers. So within a C expression it is not defined the relative order of the side effects. If two or more side effects apply to the same operand, then you have a problem. Moreover the assignment operator (=) in the C language is just an operator with a side effect, so the expression:


is undefined behavior.
The day after I investigated on the C language FAQ and found that the ternary operator (? 🙂 introduces sequence points (a jargon to say that all the side effects have to happen before a given point in a language phrase), so the expression may, after all, be well defined.
The scaring part is that a random C programmer like me, with over 20 years of exercise in the language, could be baffled by such expression and unable to tell apart the result of such a line.
And that’s why the second buzzer triggered. Why young blank minds have to be troubled with such visions? If a program contains one expression like that chances are high that it is a bug. If it is not a bug you may well count it as such because you are going to have a hard time figuring out what’s going on in that code.
There are some values in programming that ought to be taught before putting hands to the keyboard. Simplicity is one of the most valuable principles – keep it simple. You have to understand it, even after months, others have to read and understand it as well.
Simplicity is meant to fight against the common distortion of the young programmer trying to assert himself considering (and unfortunately, writing) “concise, hard to read” for good code. “Hey, I bet you cannot find what this piece of code does”.
I think teachers should make serious effort, especially when dealing with languages such as C, where cryptic and short code could be easily written, to discourage one-liner approaches and striking that the great programmer is the one who is able to tackle complex subjects with simple and clear code.
Writing this could be another sign of my age…

Just in case

The Times reports that Canterbury Archbishop stated that the Three Wise Men (the Wizard Kings in Italian) are nothing but legend. He goes further – “there was no evidence that there were any oxen or asses in the stable. The chances of any snow falling around the stable in Bethlehem were ‘very unlikely’. And as for the star rising and then standing still: the Archbishop pointed out that stars just don’t behave like that.”Browsing through older news, the same Archbishop took a strong position against the teaching of creationism in schools.
Enlighted, isn’t he? Just in case you feel shocked by these news maybe you want to reassure yourself that the Earth is indeed flat.

Disappointingly Short

There are events you can’t miss. If you have an Xbox 360 you simply cannot afford to miss Gear of Wars, Bioshock and the most unmissable ever Halo 3. With over 4 million copies sold in pre-order alone and a 93% score in average is hardly something you can heart-lightly miss or ignore. So I diligently bought my copy and started playing it. The game story is set just after the end of Halo 2. I am not a 3D guru, so the graphic let me quite unsurprised – Halo 2 had a superb outlook on the Xbox 1, while XBox 360 sported Gears of War and Bioshock that trained us to take for granted such high levels of details. So the start of Halo 3 in a wide open jungle wasn’t really astonishing, was more a … well, yes, good sort of thing.
The game is nonetheless very polished, you find enemies, weapons and vehicles, lots of funny stuff.
The most annoying piece of the game is the AI of the jeep driver that quite often get stuck into some dead end, leaving the player an easy target for incoming enemies.
The story is good, is somewhat more understandable of that of Halo 2, nonetheless is quite fictional for the game progressing, just blast away your enemies, try to not hit your friends, that’s all.
There are a couple of points were the sense of wonder brutally kicks-in, the ending level is epic. Although I miss the awe I felt back in Halo 2 when I discovered I could jump on the insectoid-mecha and bring it to a grinding halt.
But the worse part, the really bad thing is that this game is short! Really short, you can cut through it like a knife through a piece of butter and around in the same time. 8-10 hours even for me that can qualify something more than casual gamer.
The XBox live for sure brings oxygen to the game, adding value, but if you, like me, have not the on-line option, than this game is hugely overpriced.
My vote is 6 of 10.

Freedom for Rights

Before entering in the main theme, I’d like to state it clear – it happened sometimes I downloaded some AVIs or MP3s via eMule for personal use, though I am far from being addicted to this practice. Usually I prefer to spend money on these stuff either by rent or by purchasing the real thing, or to label it as too expensive for me (the same label I tagged with, over the time, a great deal of stuff). Despite of what the supporters of the free-download-for-all say, I am not convinced that it has to be a right the downloading of a recent movie for watching.Movies, musics, games, programs cost money to produce, a great effort that needs to be paid back. I don’t see any viable way of sustaining these industries but buying their goods (Scott Adams explains why much better than I could ever aspire to… at least in English).
The outcome of the recent Radiohead’s experiment about spontaneous payment for music stresses this point – many of those downloaders wouldn’t buy either at a much lower price.
There are good alternatives, even for item with the “too expensive for me” label – consider renting, borrowing from a friend or from the public library, wait for the item to reach the budget price range.
What I see is that in the name of freedom to spread other people IPs the Internet is more and more constrained, inspected and our freedoms of speech, opinion and thought are more and more restricted. Take for example the recent news from France or the recently adopted DMCA-like ruling in Switzerland and Canada. That means that some sort of filter thoroughly analyzes everything goes to and from your Internet pipe.
It is true that wouldn’t be illegal downloads, the same kind of deep inspection could have been ascribed to terrorist threats or any other form of crime prevention. The problem is that the former contributes to the idea that privacy for sure (and maybe some other rights) have to be sacrificed in the name of any kind of crime prevention – how trivial or grave doesn’t matter.