c vs c++

Discussion of chess software programming and technical issues.

Moderator: Ras

c or c++ ?

c
24
48%
c++
26
52%
 
Total votes: 50

Michel
Posts: 2292
Joined: Mon Sep 29, 2008 1:50 am

Re: c vs c++

Post by Michel »

C is a reasonable compromise between assembly and a high level language.

Most OS'es are entirely written in C (I think only a tiny part of the Linux kernel is assembly, the part which is concerned with locking primitives for SMP).
Tord Romstad
Posts: 1808
Joined: Wed Mar 08, 2006 9:19 pm
Location: Oslo, Norway

Re: c vs c++

Post by Tord Romstad »

I have no love for either C or C++, and although D and Go are better in some ways, I'm not able to get very excited about these either. The low-level programming language I would prefer to use is BitC, but of course it's never going to take off.

For most of my high-level programming needs, I'm very satisfied with Common Lisp and Haskell, while Factor and Smalltalk are also fun to play with. Common Lisp has always been the language that pays my bills.
User avatar
Laskos
Posts: 10948
Joined: Wed Jul 26, 2006 10:21 pm
Full name: Kai Laskos

Re: c vs c++

Post by Laskos »

Tord Romstad wrote:I have no love for either C or C++, and although D and Go are better in some ways, I'm not able to get very excited about these either. The low-level programming language I would prefer to use is BitC, but of course it's never going to take off.

For most of my high-level programming needs, I'm very satisfied with Common Lisp and Haskell, while Factor and Smalltalk are also fun to play with. Common Lisp has always been the language that pays my bills.
Do you know where to get a free Common Lisp compiler for Windows, with IDE? I tried GNU Common Lisp, it translates into something which needs a C compiler. I read that the free version of LispWorks 6.01 doesn't compile.

Kai
User avatar
Don
Posts: 5106
Joined: Tue Apr 29, 2008 4:27 pm

Re: c vs c++

Post by Don »

Tord Romstad wrote:I have no love for either C or C++, and although D and Go are better in some ways,
D is better in almost every way - it's easy to compare because it's really like a super-dialect of C++ with functional programming thrown in. So you can do a case by case comparison of the choices the creator of D took.

Go of course cannot be compared so easily, as it's an apples to oranges comparison.

I wanted to also take a look at bitc and Lissac, but they both seem to be a dead end.


I'm not able to get very excited about these either. The low-level programming language I would prefer to use is BitC, but of course it's never going to take off.

For most of my high-level programming needs, I'm very satisfied with Common Lisp and Haskell, while Factor and Smalltalk are also fun to play with. Common Lisp has always been the language that pays my bills.
SuneF
Posts: 127
Joined: Thu Sep 17, 2009 11:19 am

Re: c vs c++

Post by SuneF »

ethanara wrote:I was talking 100% about exe performance
I did read in a java book that in some tasks java would be faster than c++
If you will i give you example and execution time.
Do you guys think java would be faster than c c++ in a chess engine?
Or would it be faster to make a multi-language like c java chess engine?
Bye
Ethan Ara
Java is JIT compiled, meaning the java machine will delay the translation of code till runtime. This is what makes java so portable and in principle it could be faster than any C program. If the java machine was really good it could optimize for the specific CPU and even do JIT profiling making the program run faster and faster. This is the theory though in practice perhaps due to Java's safety features like exception handling and bounds checking it doesn't appear to be true.
Daniel Shawul
Posts: 4186
Joined: Tue Mar 14, 2006 11:34 am
Location: Ethiopia

Re: c vs c++

Post by Daniel Shawul »

I like java too even though I started using it only past couple of months.
It has a lot of libraries that could have saved me a lot of development time.
C is not even the best high level language for number crunching. FORTRAN is better , faster and has many libraries c could never have.
I don't see too much of a difference in c and c++ for chess applications, because you would not use many features c++ anyway.
A chess engine is not the best application to learn an OOP language.
User avatar
Don
Posts: 5106
Joined: Tue Apr 29, 2008 4:27 pm

Re: c vs c++

Post by Don »

SuneF wrote:
ethanara wrote:I was talking 100% about exe performance
I did read in a java book that in some tasks java would be faster than c++
If you will i give you example and execution time.
Do you guys think java would be faster than c c++ in a chess engine?
Or would it be faster to make a multi-language like c java chess engine?
Bye
Ethan Ara
Java is JIT compiled, meaning the java machine will delay the translation of code till runtime. This is what makes java so portable and in principle it could be faster than any C program.
The phrase "in principle" is misleading because in practice it will never be faster than C given equally good compiler implementations.

In principle C could do all of the thingsJIT does with PGO. In principle every language could anticipate the programmers intent and even use different algorithms. (I wanted bubble sort, but the compiler detects that I have implemented a bubble sort and substitutes a quicksort.)

But in practice Java is a big problem for chess programs, primarily due to memory issues (memory management and lack of fine control over memory layout.)

Maybe in a more distant future these problems will be solved with Java, but then it has become a new language and it's already showing signs of age (as is C and C++) so it's probably a moot point.

I tihnk it's a safe bet to say that we will never see a top 10 program written in Java. If it happens it will not be because it was written in Java but because the programmer wrote a far superior program (and would have done much better in C.)


If the java machine was really good it could optimize for the specific CPU and even do JIT profiling making the program run faster and faster. This is the theory though in practice perhaps due to Java's safety features like exception handling and bounds checking it doesn't appear to be true.
User avatar
edlich
Posts: 8
Joined: Wed Jul 13, 2011 12:00 pm
Location: Berlin

Re: c vs c++

Post by edlich »

Concerning the speed comparison there are lots of nice benchmarks outside to answer some questions: http://shootout.alioth.debian.org/ or http://dada.perl.it/shootout/
Don wrote:
Tord Romstad wrote:I have no love for either C or C++, and although D and Go are better in some ways,
D is better in almost every way - ...
I really would like to support the excitement for D. One upon a time I have listed a bunch of advantages in the chessprogramming wiki here: http://chessprogramming.wikispaces.com/D-Proglanguage
Closures and a D-language subset for functional programming is one of the many examples.

Thus it would be interesting to know why still so many chess developers decide to to go for C++. Is it a mass effect? Is it the amount of available (clonable? ;-) chess code? Or something more I miss? (and keen to learn!).

Best
Stefan Edlich
rbarreira
Posts: 900
Joined: Tue Apr 27, 2010 3:48 pm

Re: c vs c++

Post by rbarreira »

edlich wrote:Concerning the speed comparison there are lots of nice benchmarks outside to answer some questions: http://shootout.alioth.debian.org/ or http://dada.perl.it/shootout/
Don wrote:
Tord Romstad wrote:I have no love for either C or C++, and although D and Go are better in some ways,
D is better in almost every way - ...
I really would like to support the excitement for D. One upon a time I have listed a bunch of advantages in the chessprogramming wiki here: http://chessprogramming.wikispaces.com/D-Proglanguage
Closures and a D-language subset for functional programming is one of the many examples.

Thus it would be interesting to know why still so many chess developers decide to to go for C++. Is it a mass effect? Is it the amount of available (clonable? ;-) chess code? Or something more I miss? (and keen to learn!).

Best
Stefan Edlich
Compiler quality, portability, API maturity, performance and famliarity/popularity are all advantages of C/C++ over D.
SuneF
Posts: 127
Joined: Thu Sep 17, 2009 11:19 am

Re: c vs c++

Post by SuneF »

Don wrote:
SuneF wrote:
ethanara wrote:I was talking 100% about exe performance
I did read in a java book that in some tasks java would be faster than c++
If you will i give you example and execution time.
Do you guys think java would be faster than c c++ in a chess engine?
Or would it be faster to make a multi-language like c java chess engine?
Bye
Ethan Ara
Java is JIT compiled, meaning the java machine will delay the translation of code till runtime. This is what makes java so portable and in principle it could be faster than any C program.
The phrase "in principle" is misleading because in practice it will never be faster than C given equally good compiler implementations.

In principle C could do all of the thingsJIT does with PGO.
I'm not so sure. With late binding at runtime you would know the instruction set of the CPU, whether it was AMD, Intel, PIV, Core2, 64-bit, number of cores, SSE and so on. A smart (really smart) java machine would be able to optimize for the specific platform. The PGO might also perform differently on AMD vs Intel, or small caches vs large caches etc.. so many variables.
In principle every language could anticipate the programmers intent and even use different algorithms. (I wanted bubble sort, but the compiler detects that I have implemented a bubble sort and substitutes a quicksort.)

But in practice Java is a big problem for chess programs, primarily due to memory issues (memory management and lack of fine control over memory layout.)

Maybe in a more distant future these problems will be solved with Java, but then it has become a new language and it's already showing signs of age (as is C and C++) so it's probably a moot point.

I tihnk it's a safe bet to say that we will never see a top 10 program written in Java. If it happens it will not be because it was written in Java but because the programmer wrote a far superior program (and would have done much better in C.)
It probably stands to lose a few hundred Elo given the same program written in Java, but then the point is you wouldn't have the same program in Java. The 50% time saved hunting bugs is 50% more time to develop new algorithms and tricks in java.