[Original blog post by Gil Moskowitz - 09/08/2015]
A software guy I know recently said that he prefers PHP to C++, something about C++ being "too fussy". I didn't comment at the time but the issue is an interesting one and is relevant to the haxTuple bug derby and xTuple application scripting.
int tmpid = _warehouse->id(); // C++
Both of these set a temporary variable tmpid to the internal ID number of a warehouse. Both call the id() method or function of the _warehouse object.
What changed to give the following code?
int tmpid = _warehouse->id; // C++
No parentheses after the id. What happens when we try these?
The C++ line won't even compile, so you won't be able to run it to see the incorrect behavior. This is C++ being fussy. Instead of trying to do what you've asked, the language just complains that you made a mistake - something about type mismatches, casting pointers to int, or nonexistent variables - and does nothing.
Which is worse:
- A script that's quick to write and tries its best to do what you've asked and sometimes gets it wrong?
- A C++ compiler that says that you're not making any sense and makes you fix basic problems before it'll even try?
Does language choice matter? Often
Is one better than the other? Often
"Hey!!!!" you say, "That doesn't help!"
I know. That's why we have and use many programming languages. Developers have our favorites, of course, but the solutions to some problems are better expressed in certain languages than others. In addition, certain kinds of bug just cannot appear when you use certain languages and other kinds of bug are easy to introduce:
- Lest you think this is particular to this family of languages, consider SQL: It takes about half as much typing to wipe out an entire table as a single row. On the other hand, either would require at least a score and possibly hundreds of lines of C++ working directly with the disk files, what with locking and all.
There's no substitute for understanding your programming language - its power and its shortcomings.