More Code Haikus

Just in case you wondered, my colleague Jean-Eric Waroquier is the greatest guy ever. He is sweet, easy going, always willing to help and insanely smart, the best colleague one can ever dream of.

And the anecdote below won’t change a thing about how I feel about him.

I woke up this morning (A bit later than I should have: I have some trouble adjusting back to my normal routine right after New Year) to see an email from Jean-Eric asking for help, a system he was working on going bananas, memory corruption, Windows blue screen and more of the same. Jean-Eric is experienced and very autonomous. He does not call for help unless he feels really stuck in a bad way, so I called him back immediately. We talked it over for a while, decided on a number of action points to better diagnose the cause of this error, and I rushed to the shower to get to the office as soon as possible to help him out with this.

No need to rush: by the time I had gotten out of the shower, Jean-Eric had already solved the problem, a small mistake that did not get caught earlier because he did not compile with all checks enabled. The culprit was a small YAFL loop written as:

FOR i := 0 TO boundExp.SIZE DO

while the correct expression would have been:

FOR i := 0 TO boundExp.SIZE-1 DO

since YAFL array elements are numbered from 0 to n-1, n being the size of the array.

It is a rookie’s mistake (even more so considering that this is by no mean a YAFL exclusive: C’s, C#’s and Java’s array are similar in this regard), but even the most experienced software engineer can be forgiven for missing a -1 once in a while.

It is precisely because of these (very few) errors made by even (very much) experienced developers that ad hoc notations that simplify the protocol for concepts (in this case, an array) are worthwhile. For instance, YAFL supports an ad hoc construct to have a loop go over all the valid index values of an array or a list, and the code above could have been written as:

FOR i IN DOM boundExp DO

in effect recognizing the partial function intrinsic nature of arrays, freeing the developer from the implementation details that specify that array elements must be numbered from 0 to n-1. This notation does not make any difference in terms of performance: the code that will be generated is absolutely identical to the verbatim FOR loop starting at 0 as given above.

Which may not have been the case: a more aggressive compiler could forego array index checks based on the i variable based on the fact that it was declared a going over the valid domain of boundExp.

I can really see how someone could shrug, and minimize the importance of such notations.

But they do make a difference (Ask Jean-Eric if you don’t trust me on this). Such syntactical capabilities are by no mean revolutionary. They are at best evolutionary. They improve the quality of the software we write and maintain, by reducing the number of mistakes we can make, by reducing the number of moving parts.

By avoiding bugs, one at a time.

12-01-2017 - By in

Leave a Reply

Your email address will not be published. Required fields are marked *