While having a good intention behind it, the idea is actually just a fix for a defficient language, namely C and C++. If
typedef
were not a mere type alias, but a true new type, this convention would be (almost) unneccessary as the compiler could catch all errors. For example:
typedef int Temperature;
typedef int Volume;
int f(Temperature a, Volume b)
{
return a+b;
}
Although it is meaningless to add temperature and volume quantities, this is perfectly legal C and C++ code, because
Temperature
and Volume
are mere int
.C++ templates have strict compile-time type-checking, but the syntax is unfortunately just horrendous.
1 comment:
If the code needs some mechanism by which a type of a variable is obvoious from its name, it is poor code indeed. Simony's idiocy was just an extension of our old FORTRAN rule for making i-n starting variable names integers.
Post a Comment