views:

200

answers:

3

For example:

on rising edge (reset):
sync = defaultValue;
...
... various processing constructs ...
...
if (event == someEvent)   // Back at the Batcave
    // The vilianous Fat finger Syndrome
    // strikes again!
    synch = someEventProcessing()
...
... various processing constructs ...
...
someSyncProcessing(sync)  // Foiled again!

All occurances of the varible "sync" should have been spelled "sync" instead of "synch." I even read the line with the incorrect spelling and my brain "tokenized" it's symbolic meaning.

I looked at the code for a couple days before I found the typo. How do you prevent this when the language doesn't generate any errors? There was a work around in the code because somebody couldn't find the source of the "Black magic" causing the program's errant behavior. This obscurred the problem even more. (This code was actually paraphrased from a verilog program. But seems like it could be a problem in any language that allow this type of thing.)

+3  A: 

If your compiler does not provide a tool to spot these kind of troubles, you don't have much to hope for. I would recommend a very strict unit testing policy. At least it will make it easier to pinpoint the syndrome occurrence.

A possible (NB: possible) strategy is to take all the unique identifiers, one by line (e.g. replace all spaces with returns) and then filter them through a sort | uniq. It will, hopefully, allow you to get a better view of strangely typed identifiers.

You can also reduce such occurrence by using tab-completion in your editor. vim, for example, has a very useful function (Mosh_tab_or_complete) to perform autocompletion.

Stefano Borini
Adding a script to do something like sort | uniq sounds like a good idea. No identifier should only occur once in your code normally. What did you mean "(NB: possible)"? The tab completion also sounds like a good idea, although I'm not a vim fan. (I wind up aborting out most of the time, cause I forget the keystrokes.)
NoMoreZealots
I suggest you to add the -n switch to uniq, so to add the occurrence count. The NB refers to the fact that if you have something like hello= 5 instead of hello = 5 you will get two identifiers "hello=" and "hello". This is not a big issue, you have to play with regexps a bit, but for a large codebase, and languages without distinction of keyword from identifier (e.g. fortran) you cannot be 100 % sure. Fortran, however, has the IMPLICIT NONE directive, so it's not an issue, unless you have very old codes with so many implicit declarations to make the use of IMPLICIT NONE too time demanding.
Stefano Borini
A: 

Unit testing. Using TDD you write tests to define the expected behavior, then write the code to implement the behavior. Set up your expectations and mock objects then test that the mock objects had the correct methods called. Check that your data now has the correct values.

tvanfosson
HDLs are way ahead of software on this. You almost never compile before testing with simulation. (You can't exactly embed printfs in logic.)
NoMoreZealots
A: 

Just remember to take it slow. Too many programmers rush and make mistakes like this. I know writing in Verilog is not very user friendly so you have to be extra careful in this case.

ChaosPandion
Yeah true. I like the syntax better than VHDL, but our HDL expert is leaning towards VHDL because it place and routes more consistenly. My opinion is both languages still need work.
NoMoreZealots