Programming language choice, why C\C++ ?
Moderators: hgm, Rebel, chrisw
-
- Posts: 234
- Joined: Sat Jan 17, 2015 11:54 pm
Programming language choice, why C\C++ ?
why are most engines (especially very strong ones ) written in C\C++ , is it due to a performance difference and if so how large is it "given the fact that algorithms are way more important than small optimizations" ?
-
- Posts: 893
- Joined: Mon Jan 15, 2007 11:23 am
- Location: Warsza
Re: Programming language choice, why C\C++ ?
Big folks write in C/C++ because of speed. Small folks, including myself - because there is much more code to read and learn from in C/C++ than in any other language.
Pawel Koziol
http://www.pkoziol.cal24.pl/rodent/rodent.htm
http://www.pkoziol.cal24.pl/rodent/rodent.htm
-
- Posts: 199
- Joined: Sun Nov 03, 2013 9:32 am
Re: Programming language choice, why C\C++ ?
The language 'should' be irrelevant.
All compilers 'should' produce perfect/fastest code.
You 'should' use the language that you feel most comfortable with.
Now in the real world.............................
All compilers 'should' produce perfect/fastest code.
You 'should' use the language that you feel most comfortable with.
Now in the real world.............................
-
- Posts: 12542
- Joined: Wed Mar 08, 2006 8:57 pm
- Location: Redmond, WA USA
Re: Programming language choice, why C\C++ ?
C and C++ are about 1/3 faster to twice as fast compared to CLR type languages or Java.
Most engines are written in C or C++ due to this small speed difference and also due to popularity. If you want to find an example of something it is easy to find in C++ or C and harder to find in other languages.
Fortran, for instance, should produce exactly the same speed quality as C, but Fortran engines are so rare, you won't find many examples of how to do things.
Most engines are written in C or C++ due to this small speed difference and also due to popularity. If you want to find an example of something it is easy to find in C++ or C and harder to find in other languages.
Fortran, for instance, should produce exactly the same speed quality as C, but Fortran engines are so rare, you won't find many examples of how to do things.
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
-
- Posts: 4367
- Joined: Fri Mar 10, 2006 5:23 am
- Location: http://www.arasanchess.org
Re: Programming language choice, why C\C++ ?
Speed, and portabilty. But there is a downside. I think it was Bjarne Stoustroup who said, you can shoot off your foot with C. But you can shoot off your whole leg with C++.
--Jon
--Jon
-
- Posts: 100
- Joined: Fri Sep 19, 2014 5:03 am
Re: Programming language choice, why C\C++ ?
A funny quote.jdart wrote:Bjarne Stoustroup who said, you can shoot off your foot with C. But you can shoot off your whole leg with C++.
But to be more apt, you can shoot off your foot in C, plus leave a huge hole in the earth under your foot, with one line of code.
You can Whole.Leg.Yours->shoot.off in C++, but it would take an entire development team one man-week to figure out whose leg is missing
-
- Posts: 433
- Joined: Fri Jan 16, 2015 4:02 pm
Re: Programming language choice, why C\C++ ?
I chose Go for readability and development speed. I managed to build a whole suite of tools around the engine (testing framework, tuner, analyzer, epd solver, etc) with very little effort and very few external libraries.
The compiler is getting better every the release, and the gap of the generated code quality is small enough. I even helped improve the compiler so that zurichess doesn't suck. Currently it's missing the popcnt intrinsic, but it's going to be added in Go1.9 after I proposed the math/bits library [1].
I'm a mainly C++ developer at work (with some Python & Go in between), but I would stlll not choose C++ for any of my personal projects. It's very verbose compared to Go and the public libraries are either very verbose or very complex.
[1] https://github.com/golang/go/issues/18616
The compiler is getting better every the release, and the gap of the generated code quality is small enough. I even helped improve the compiler so that zurichess doesn't suck. Currently it's missing the popcnt intrinsic, but it's going to be added in Go1.9 after I proposed the math/bits library [1].
I'm a mainly C++ developer at work (with some Python & Go in between), but I would stlll not choose C++ for any of my personal projects. It's very verbose compared to Go and the public libraries are either very verbose or very complex.
[1] https://github.com/golang/go/issues/18616
zurichess - http://www.zurichess.xyz
-
- Posts: 373
- Joined: Wed Mar 22, 2006 10:17 am
- Location: Novi Sad, Serbia
- Full name: Karlo Balla
Re: Programming language choice, why C\C++ ?
From the very beginning, C was a small, simple and close to the hardware language. It is also character economic language, without a lot of "begin" and "end" type keywords. One can learn C basics in less than a week. C++ is more or less the super-set of C, and a lot of programmers just use a C++ compiler to write enhanced C code.MahmoudUthman wrote:why are most engines (especially very strong ones ) written in C\C++ , is it due to a performance difference and if so how large is it "given the fact that algorithms are way more important than small optimizations" ?
On the other hand, for languages like C# you really need to know what you are doing to write an efficient code. The standard is still changing and without much experience, in programs for crunching numbers (like chess) there is a big chance to end up burning 90% CPU cycles on creating objects and collecting garbage.
Best Regards,
Karlo Balla Jr.
Karlo Balla Jr.
-
- Posts: 931
- Joined: Tue Mar 09, 2010 3:46 pm
- Location: New York
- Full name: Álvaro Begué (RuyDos)
Re: Programming language choice, why C\C++ ?
That's exactly the way I see it. Notice that if you are not careful with C++, you can still spend the majority of your time allocating memory, initializing it and deallocating it.Karlo Bala wrote:From the very beginning, C was a small, simple and close to the hardware language. It is also character economic language, without a lot of "begin" and "end" type keywords. One can learn C basics in less than a week. C++ is more or less the super-set of C, and a lot of programmers just use a C++ compiler to write enhanced C code.MahmoudUthman wrote:why are most engines (especially very strong ones ) written in C\C++ , is it due to a performance difference and if so how large is it "given the fact that algorithms are way more important than small optimizations" ?
On the other hand, for languages like C# you really need to know what you are doing to write an efficient code. The standard is still changing and without much experience, in programs for crunching numbers (like chess) there is a big chance to end up burning 90% CPU cycles on creating objects and collecting garbage.
C and C++ allow you to waste very little CPU in anything that is not the computation you are trying to do, but a beginner might have a hard time taking advantage of this. For instance, if your move generator returns a std::list<Move>, I expect your engine will be very slow.
-
- Posts: 433
- Joined: Fri Dec 16, 2016 11:04 am
- Location: France
- Full name: Richard Delorme
Re: Programming language choice, why C\C++ ?
Speed? Why not D, fortran, pascal, java, ada, go, rust? They are similar in speed to C or C++ (they all have a gcc or llvm backend). And if you really want speed asmfish is a convincing proof that the only solution is an assembly language.jdart wrote:Speed, and portabilty.
Portability? Who cares? If it runs under Windows/intel, it's enough (Houdini for example runs only under windows).
When I developed amoeba using the D language, I was very surprised that no chess engine has ever been written in D. I am still wondering why people stick to C or C++.
Richard Delorme