Ehy dude, where did my frame go?

It is nearly three decades I write bugs code and I am maturing the idea that each new bug I find should inspire a way to avoid it in the future or, at least, to reduce the chance of falling again in the same mistake. During the past weeks my team and I discovered two bugs and here is my ideas for improving the software quality.
The first bug is likely to be the longest standing bug I had. As you may know, I am working on a proprietary field bus. We found evidences of the problem at least three years ago. Occasionally our devices lose a frame. It is not tragic – it is a frame in 250 – but, since the protocol does not account for transmission acknowledge, it may result in wrong device behavior.
We got the assembly driver from our customer, therefore the code is granted to be correct. They use the same code in hundreds of devices and they said they never have such a bad figure in frame reception.
This bug had a chance to live so long for two reasons – first, the customer accepted our firmware with this known problem; second we were quite convinced that this problem should have appeared in their devices as well.
An event broke this impasse – first we had big troubles in an installation and eventually it turned out that one device has a slightly defective crystal that caused major frame dropout, wreaking havoc of all the system. This led to some investigation of the hardware guys that told me that crystal precision was very critical in device correctness. The crystal component has a tolerance of 0.5% and our device starts behaving weird when the frequency goes 0.4% away from nominal frequency. This was clearly not acceptable and a solution urged.
I went to some fruitless investigations before discovering that another firmware, mainly developed by our customer, was much more reliable than ours. After much head-scraping and head-banging against the nearest wall, I went through the aging documentation that the customer gave us to integrate the bus driver.
There I found that it was required to set a global variable, let’s call it FLEX with half of the value of a global constant.
Then I turned to the code and found an old comment of mine that went like this /* FLEX and GIZMO seem not to be use anywhere in the code, they must be private variables */
Of course, removing the comment and properly initializing the variable sent the problem the way of Dodos.
How this could have been prevented? That’s a simple shot – avoid the programmer to manually set obscure and arcane magic values in oddly named global variable. Either provide a complete setup function, or let the magic value be computed at compile time.
I’ll write about the other bug, tomorrow. In the meantime your comments are welcome, as always.

xubuntu and my /var/storage

It was back in the mid-nineties, when I first received a Slackware 3 install CD. I somewhat recall the install process, the terror of wiping out the other OS from the single disk I had. Since then I tried many releases of RedHat and Fedora Core, until recently I turned to Xubuntu for old PCs.
I used Xubuntu also for my media server, which is a network-only small box filled with a 1Tb hd I keep beside my TV. This media server hosts my video and, most important, all my pictures. I have photographies back from 10 years ago, tons of photographies… when I stored (a downsized version of) them into my wife Digital Photo Frame, I counted 14000 pictures.
So, last Friday (Friday 17th, I am not superstitious, mind that) I had a couple of hours of free time and I decided to upgrade the XUbuntu version of my media server.
I saved main configuration files, a couple of packages I installed that were not part of the distribution. Since the linux is located on a CF card and the 1Tb disk is just data, I didn’t mind about backing it up. I mean I have a backup disk I sometimes sync with my actual data, but I didn’t feel the urge to do so.
I started the installation and selected to update the current installation.
After a while I heard my disk head tickling… and the fear rose. I went into a shell, checked for the mounted partition and found my data disk was mounted, issued a ls in the directory and found that more than half of the directories were gone.
Terrified I switched the box off, and turned to the other computer to search for an undelete.
What happened? My data disk was mounted under /var/storage. I choose this because this was a permanent presence in the file system and because under /var is where mysql and postgresql keep their database data. By analogy I thought it was a proper place for my media data base. Well I was wrong (or at least Xubuntu install program thought this was wrong), in fact Xubuntu upgrade wipes out the content of /var, maybe it preserves something, but nothing is asked.
Googling for the right words, I found the way to recover deleted files on a reiserfs partition. Information is a bit dated, but everything worked as expected. I guess I got back 90% of the original data. Recovered stuff was in /lost+found directory, some files had their real name, other files were renamed after their i-node number. Luckily being Picture, I could recover information from the Exif data.
Well… at the end it was just a big panic moment, but everything was sorted out. I have still maybe two/three evenings of work to put everything back in place.
As my esteemed colleague often says – if it nearly works that’s enough, do not change it or it breaks (in Italian sounds much better “Se tanto va che quasi basta, non toccar se no si guasta).

Filastrocca dei segreti pesanti

Ho nascosto quella cosa in fondo a meperché se non la vedo lei non c’è.
Non ne parlo per non essere più triste
perché se non la dico non esiste.
Ma laggiù in fondo a me nel buio denso
anche se non la vedo io ci penso
e lei beve quel buio come inchiostro
e cresce sempre più, diventa un mostro.
Ma io so cosa ai mostri fa paura:
il sole che taglia in due la notte scura.
Apro la mia finestra a questo sole
ed apro la mia bocca alle parole.
Ne parlo con la mamma, con l’amico…
tu mi spaventi Mostro ed io… ti dico!
E tu ti scogli in un po’ di porcheria.
Mi dai un ultimo morso e fuggi via.
Mi rimane una bella cicatrice dove
è scritto “Mostro morde, uomo dice!”
(da “Il segreto di Fata Lina”)

To the Moon and Blackwell

I’ve always been convinced that you don’t need big bucks to create masterpieces. Masterpieces are masterpieces regardless of the technology, the cast, the equipment, the AAA team. Masterpiece is when you’ve got a great inspiration and great capabilities. Technology is just something that is in your way.Recently I played two games that prove this theorem.
Blackwell Deception is an old-style point-n-click adventure. Do you remember the good ol’ Zak McKraken and the Alien Mindbenders? Or the more recent Monkey Island series? Well that’s the genre. But that’s just the technology. There’s a great story, greatly narrated through the pixellated characters. There’s this strange pair – a young woman and his uncle ghost. They help just passed away people to understand their new condition and leave this world. While you play you discover both the current story and the characters’ background – their lives. Actually there are 3 (at least) titles of this series, I played some, I’d like to play more, but I have a life. Nonetheless if you like either adventures or stories, give this a try, money will be worth spent.
To The Moon is a narrative RPG, really there is little G and not much RP, but there is a playable poetry. Beside if you are a bit clumsy – as I am – in adventures, and sometimes it happens to get stuck, this is the game for you. I never had a doubt about what to do or where to go.
The graphics is pixel art, classic RPG pixel art. But the story is light years ahead of everything I played. This is so gentle, so touching… I am just sad it is over.
There are two agents/scientists that help people in realizing their wish. When someone is about to die, they can help him (or her) in achieving their strongest wish they had in life.
So the scientists are called to help a dying men in realizing his wish – going to the moon. They travel back in memories, with the help of a virtual reality machinery, in search of the proper spot to insert new memories of his travel to the moon. The mission wouldn’t turn out so simple, but the story of the man, his infancy, his love, his passion, lived in a great flash-back, is something that ties you to the PC and won’t let you go. Here, too, your money will be well spent.

So I’d say, you’ve got no excuses, pick the technology you can afford and create your masterpiece.

Is this the time for Java?

Once upon a time I was a strenuous ZX Spectrum fan, then time changed, technology evolved and, fighting back my feelings, I switched to Commodore Amiga (yes, it took me a detour over the Amstrad cpc, to get ready for change).Then I was fond of the Amiga, but time changed again, Commodore filed bankruptcy and I changed to anonymous PC clone with Windows 3.1.
Sad story, time changes and you must adapt and change as well, saying goodbye to your comfortable little home.
Now I am faced with a hard decision and it seems that it is time for change again. For the incoming project at the company I work for, I will have to lead the development team (and likely to put in some project management as well, but this is another story) and I have been already told that I don’t have to expect we are going to hire top programmer. On the contrary the company is like to get some instances of Joe Slightly Below Average junior programmer.
The project itself is ambitious (as all projects we tackle), there will be Linux, IP communication, complex system, audio and video communication, proprietary and open field bus communication, zig bee localization and the like… So for sure the team will have to find as much as possible from COTS (Components Off The Shelf) and integrate them.
Now I have to select (apparently I am still free of doing this) the language for the main application. Would have been it my project I would have chosen C++ blindly – no discussion. I am also curious about the new C++11 and this would have been a perfect occasion for getting used to the new tools in the language.
But… I have to deal with junior, possibly below the average programmers (and to make things worse, the development team will be far away from me, but this is another story as well).
From my last weekly report:

I am still undecided about the language to use for this project. There are really only two (maybe three) alternatives.

    • Java. Java is quite accessible. It is likely that every college programmer has been exposed (at various degree) to Java. Java prevents you to do simple mistakes on pointers and memory management at the cost of allowing you to enter terrible pains and sufferance by mindlessly making complex mistakes. Java is mature and stable, performance could be sometimes troublesome. Integrating third part components is easy only if they are written in Java or have a Java wrapper.
    • C++. C++ is unfortunately a less obvious choice, many people have it on their resume, just to pair C, but are quite lost at what is C++ today. C++ helps you strongly in avoiding the terrible pains and sufferances of complex mistakes, by letting yourself tie a knot around your neck with simple errors of pointers and memory management. Although C++ is with us since a long time, the latest standard is still young and many programmers still don’t have a clue about the previous one. Performance is not an issue. Integrating third party components should be easy.
    • Python. Ok, I am not really a script language fan, but I reckon that for integration work, these could be the right tools. Write few “glue” code that just works and ignore the rest. Performance are not what you want to look at, but it is up to third party components to be quick. Though resources can be limited on an embedded system to use a scripting language as it was thought to be used.

Despite the silly wording, Java seems to be the reasonable answer, and for sure is the one preferred by management, but is it the right one?