A couple of things amused me in the blog that Ovid linked to. Ninh writes
Come to think of it, I find it kind of insulting that PHP thinks you need ugly training wheels like this in the first place. Last time I checked, the world wasnââ¬â¢t filled with scrawny developers that would come crying to their mommies after getting their first facepalm of ââ¬ÅAmbiguousInvocationErrorââ¬Â.
Um, but isn't he tilting at windmills? I thought that the whole philosophy of PHP was "easy things as easy as possible". Which, if Larry's water bed theory of language design holds, means that something has to give elsewhere.
Meanwhile, as part showing that ::
works just fine in C++ as namespace and package separator, Ninh gives example code and notes
Yes, youââ¬â¢ve read this correctly. Unlike PHP, C++ will simply say that youââ¬â¢re a silly person to write ââ¬Åless-than-intelligentââ¬Â stuff like this in the first place and thinks it is the responsibility of YOU, the programmer, to solve this problem.
Except, here's how his C++ compiler tells you, the programmer, that you have conflicting Foo::bar
s:
$ c++ -o test test.cpp
/var/tmp//ccCahjBl.s:47:FATAL:Symbol __ZN3Foo3barEv already defined.
Here's what my compiler made of it:
g++ clash.cc -o clash
/var/folders/TZ/TZzOop8WEdSNgET6iqWhPE+++TI/-Tmp-//ccMPeaMa.s:49:FATAL:Symbol __ZN3Foo3barEv already defined.
Yes, such a clear, concise error message, isn't it? Includes the file name and the line number of the conflict, so I can go straight to it in my editor. A best practice that every other language should be following.
C++ is perhaps not the best example of scrutable error messages from compilers. (The single design decision in C++ with which I can wholeheartedly agree is "You don't pay for what you don't use. I'm not sure C++ always lives up to that in terms of the conceptual tax, however.)
Of course, not all compilers are stupid enough to leave the error reporting until assembly time:
tony@mars:~/play$ icpc test.cpp
test.cpp(11): error: "Foo" has already been declared in the current scope
namespace Foo {
^
compilation aborted for test.cpp (code 2)
Is it less inscrutable if you build with -g? Which, of course, the sensible C/C++ programmer will be doing anyway during development.
Wait, what am I saying? A sensible C hacker? Hah!