Tord Romstad wrote:I never thought I would find myself defending C++, a language I detest. In this case, however, I still have to disagree with Carey.
Carey wrote:As for additional C++ features... although C++ can certainly allow you a certain amount of organization improvements and programmer productivity, it's not really capable of providing any higher performance than what C can.
In fact, due to the extra difficulty of optimizing C++ code, it's likely to be somewhat worse. Maybe not a lot, but at least a little. At best, no faster than C.
I think you are wrong. Different programming languages are optimized for different purposes. Some languages make it easy to write fast programs, but difficult and time-consuming to write 100% correct programs. Other languages make it easy to write correct and bug-free code, but more laborious to produce very fast programs. C occupies the extreme end of the easy-to-make-it-fast-but-hard-to-make-it-correct side of the spectrum.
Certainly no disagreement there.
I'd have to categorize C as a language that should never have become popular.
C was definetly a hacker's language. A system programming language.
Not something meant for the general public.
C++ is also close to this end of the spectrum, but is not quite as extreme.
C++ is not inherently slower than C, it just requires some more effort, knowledge and familiarity with the compiler to produce the fastest possible code with C++.
It's not so much the language, as the compilers having considerable difficulty optimzing it.
A lot of compiler writers objected pretty loudly to the inventive nature of the C++ standardization process, but the people doing the inventing were too excited about adding new features to be concerned about how much effort it would take to implement them efficiently. Or even if they could be implemented efficiently.
With sufficient expertise, it should sometimes even be possible to achieve faster code with C++, because templates make it possible to do more computations and code generation at compile-time, and because stronger typing probably makes some types of optimization easier for the compiler.
I have to disagree about both of those cases.
There is absolutely nothing in C++ that can't be achieved (with effort!) in C.
C++ can not be any more efficient that C can be. It can only be different styles of programming etc.
The different style may end up resulting in better efficiency, but that is due to the style and not the language.
And with the compiler probably implemented mostly in C, and sharing the back-end with the C++ compiler, it's kind of hard to argue that C++ can be inherently faster than C.
As for 'stronger typing' in C++... Hah! What a joke.... You are talking to an ex-Pascal programmer. Compared to Pascal, C++ has no type checking at all.
You have no idea how much I wish that C & C++ had decent type checking. Not quite as much as ISO Pascal, but at least half way there.
I looked at alternative languages for chess programs several times in the past few years. FreePascal, GNU Pascal, Modula-3... Either they have been abandoned, are near death, or the code produced is so bad I'd be almost better off with interpretive BASIC. (But all this is a side rant...)
It's also not a trivial task to seperate good C++ classes and features out of a chess program.
A chess program just doesn't seem to want to be organized in good OOP style.
Perhaps not, but there is no reason to use OOP just because you use C++. At least to me, OOP is not among the most compelling advantages of C++ compared to C. Stronger typing, exception handling and real strings are far more important.
Tord
I guess some of that comes from some discussions I've had with other people not here in the forum. In some of those talks, the goal was to try and break chess up into reasonable OOP chunks, instead of simply doing a C style chess program in C++.
We were never able to really break it up into reasonable chunks and keep things isolated.
I don't think C++'s slightly improved type checking is any significant benefit. Just not strong enough to really stop a programmer from making mistakes.
I don't think exception handling is all that useful for chess, either. And it doesn't come free. (Not expensive, but not free.) There are some places it could be handy, but not really enough to be worth the extra cost.
As for the strings.... I'm not sure there are any C programmers that like C's version of string handling. Not a major aspect of a chess program, but...