Tuesday, June 9, 2009

My experience with a programming error

Today I spent hours just because of a blunder in my programming. I am working on Esterel language and did some programming in that for last 6 months. In Esterel, a condition checking is done using '=' operator and the operator for assignment is ':='. There is limited support of data types in Esterel, hence, to get the support of structure kind of data types it takes support form C as the host language. I am programming some part of my project in C as the host language for Esterel. Here comes the blunder that took hours of my time. As I was doing programming mostly in Esterel for last several months I used the same '=' operator for condition checking in if condition in C. As we all know '=' operator in C stands for assignment. Since an assignment operator in an if condition is valid in C, the compiler does not generate any error. I spent hours checking my logic but all that was right even if I check for 20 times. Now my question is How do we get to know such kind of programming blunders we do????? I think the best possible option is that the compiler should give a warning but not an error. Generating a warning in this case is reasonable as most of the programmers do condition checking more often than an assignment in an if condition.

Here is a possible solution to get rid of such kind of errors apart from C compiler generating a warning. When you are in such kind of situation that all your logic is correct and the compiler does not generate any errors but still the program does not behave as you expect, ask one of your friend to check the code and there is a high probability that he will definitely catch those kind of silly programming errors.

No comments:

Post a Comment