So I was in this discussion today about modernizing our style or at least make it more available to all the engineers working on the product. The modernizing, steams from the fact that the coding standard was developed 15 years ago, when Java was still in its cradle. No IDEs existed yet and no one even considered a Java coding standard.
I guess historically most Java developers came from C++, hence it became natural to use the same habits. Therefore our coding standard contains remains of these habits. Like fields are prepended with 'm_'. Fields/local and arguments use some pseudo-hungarian notation to indicate the use and type of variables and constants. Some examples being:
- c for counters like 'int Foo'
- i for integer like 'int iFoo'
- a for arrays like 'int[] aFoo'
For those who remember the hassle of dealing with strings in C, I would like you to recollect BSTR (Binary strings) and char*. One is zero terminated by a single char '/0' the other includes the length in the first 4 bytes and is zero terminated by two characters '/0/0'.
Since any real world program would contain both types of strings it made perfect sense to use some notation of indicate what type of string was dealt with:
- bstrMyString for BSTR*
- pszMyString for char*
Another interesting argument is that we want to be able to see what type a field is directly from its name. Since we are using the normal Java Bean pattern, it doesn't really work though:
public int getFoo()
{
return m_iFoo;
}
int iFoo = m_iFoo; // fine and dandy
int iFoo = getFoo(); // how can we be sure what getFoo() returns an int
The argument to keep hungarian notation in Java is and will always be about religion and out of sentimental reasons. One factor could be that cosmetically the code looks more advanced more like C code? I cannot explain it in any rational terms though.
Anyways, the commute went fine today, the first couple of miles took 40 min though because of some accident at 128/rte 3. which meant that I missed my sons baseball game tonight.
No comments:
Post a Comment