I have 0 experience with programming but I have a bit of somewhat of a talent with learning skills. I'm somewhat interested to program a new engine but I'm far from it at this point, I still have to learn a language which will take time and patience. However I'm interested to know which programming language is useful for long term and what is the main advantages? The two language I'm referring too are C & C++
Also is there a list of all chess engines with their language? I'm confused on some few engines whether they're programmed in C or C++ or any other. Hiarcs is one of the programs I'm not sure about to be exact.
Which programming language is more useful?
Moderators: hgm, Rebel, chrisw
-
- Posts: 4675
- Joined: Mon Mar 13, 2006 7:43 pm
Re: Which programming language is more useful?
I'll guess that most chess programming efforts started it the past decade have used C++. There's quite a learning curve for a newcomer although there are some decent tutorials available for free on the net.
Some will claim that using anything other than assembly language (or C, the 21st century assembly language) will result in an unnecessarily slow program. These folks may be safely ignored on this point.
A full featured C++ chess program will have from fifty to a hundred different classes with perhaps five of these seeing nearly all of the coding. So if you use an object oriented language, spend a lot of time in the design stage working out class definitions and inheritance relationships.
Suggestion: Instead of having your first program be a general chess engine, try for a much simpler movepath enumerator (i.e., perft). You'll learn a lot including what not to do. Then toss that program and start a real chess program from scratch.
Some will claim that using anything other than assembly language (or C, the 21st century assembly language) will result in an unnecessarily slow program. These folks may be safely ignored on this point.
A full featured C++ chess program will have from fifty to a hundred different classes with perhaps five of these seeing nearly all of the coding. So if you use an object oriented language, spend a lot of time in the design stage working out class definitions and inheritance relationships.
Suggestion: Instead of having your first program be a general chess engine, try for a much simpler movepath enumerator (i.e., perft). You'll learn a lot including what not to do. Then toss that program and start a real chess program from scratch.
Re: Which programming language is more useful?
sje wrote:I'll guess that most chess programming efforts started it the past decade have used C++. There's quite a learning curve for a newcomer although there are some decent tutorials available for free on the net.
Some will claim that using anything other than assembly language (or C, the 21st century assembly language) will result in an unnecessarily slow program. These folks may be safely ignored on this point.
A full featured C++ chess program will have from fifty to a hundred different classes with perhaps five of these seeing nearly all of the coding. So if you use an object oriented language, spend a lot of time in the design stage working out class definitions and inheritance relationships.
Suggestion: Instead of having your first program be a general chess engine, try for a much simpler movepath enumerator (i.e., perft). You'll learn a lot including what not to do. Then toss that program and start a real chess program from scratch.
Right, I agree with you. Since there are plenty of engines that is programmed in C++ that has be with a good reason. We will see what the future will bring!
-
- Posts: 287
- Joined: Sat Mar 11, 2006 3:19 am
- Location: Atlanta, GA
Re: Which programming language is more useful?
Some have started C then switch to C++.sje wrote:I'll guess that most chess programming efforts started it the past decade have used C++.
There is some truth to this and without a good understand of how C++ code get translated it becomes very easy to misuse C++ features from a performance perspective. I think for people coming from C, the most important thing to learn is how C++ would be translated equivalently in C. For example C++ classes can be translated as C structs with C++ member functions being equivalent C functions having an extra parameter (the "this" pointer). Indeed, in C++ structs and classes are identical (the difference being that struts default to public access and classes default to private access).Some will claim that using anything other than assembly language (or C, the 21st century assembly language) will result in an unnecessarily slow program.
I believe careful use of C++ should be as fast if not faster (eg. function pointers vs inlinable Functors although you would never use function pointers in a chess program...) as C.
For learning C++, I'd recommend with learning C first, then try out C++. "Write great code" volume 1 and 2 by Randall Hyde is a great book to help learn a little on how to translate C++.
-
- Posts: 1922
- Joined: Thu Mar 09, 2006 12:51 am
- Location: Earth
Re: Which programming language is more useful?
I think C would be easier for a beginner to learn. No need to learn about namespaces, inheritance, operator overloading, polymorphism, etc. C++ has some nice features, but they won't really be useful until you know a lot about programming (and it would be bad to try and use them before then). It's a classic beginner's mistake to hear about the wonders of object oriented programming and then make every thing an object. This is inevitably slow. IMO you should learn C first and then decide if you want to learn C++.
Also, in my highly subjective opinion, C is a much more elegant language, since it matches in my mind what the CPU is doing. For every piece of code I write, I more or less know what the assembly is going to look like. When you see C++, you start have to dealing with function tables, templates, etc. It gets messy.
Also, in my highly subjective opinion, C is a much more elegant language, since it matches in my mind what the CPU is doing. For every piece of code I write, I more or less know what the assembly is going to look like. When you see C++, you start have to dealing with function tables, templates, etc. It gets messy.
-
- Posts: 287
- Joined: Sat Mar 11, 2006 3:19 am
- Location: Atlanta, GA
Re: Which programming language is more useful?
It can get cleaner too. I'll give two examples. First keeping this in mind:Zach Wegner wrote:Also, in my highly subjective opinion, C is a much more elegant language, since it matches in my mind what the CPU is doing. For every piece of code I write, I more or less know what the assembly is going to look like. When you see C++, you start have to dealing with function tables, templates, etc. It gets messy.
Imagine that instead of passing a board-pointer/tree-stack everywhere (say search), you instead create a search class which makes this passing implicit by containing a board ... making the code look cleaner. Inside the search function you can simply refer to movestack[n] instead of searchthread->movestack[n]. You don't have to give extra arguments to search.For example C++ classes can be translated as C structs with C++ member functions being equivalent C functions having an extra parameter (the "this" pointer). Static class variables and member functions in a C++ struct is the same thing as global variables and functions in C.
How about creating Evaluator functor whose () is a function overloaded to take in a board pointer. This is just like eval(board*)! Then in your search you can create a static member Evaluator eval and call eval(board). Now imagine you wanted to create a type of Evaluator which allows you to change the evaluation weights. You can create a seperate class which overloads the () as well and swap out static Evaluator eval; with Evaluator2 eval and call eval just the same way! You can then create two different searches and with different Evaluator2s and have them play each other
Last edited by Pradu on Wed Mar 25, 2009 6:16 am, edited 4 times in total.
-
- Posts: 6640
- Joined: Thu Mar 09, 2006 4:21 am
Re: Which programming language is more useful?
http://wbec-ridderkerk.nl/html/enginesindex.htmplaywaycool wrote:
Also is there a list of all chess engines with their language? I'm confused on some few engines whether they're programmed in C or C++ or any other. Hiarcs is one of the programs I'm not sure about to be exact.
Use the dropdown list at the left to select engine and see which programming language It's been written in.
-
- Posts: 287
- Joined: Sat Mar 11, 2006 3:19 am
- Location: Atlanta, GA
Re: Which programming language is more useful?
And when it doesn't get cleaner, just use C style C++.It can get cleaner too.
-
- Posts: 287
- Joined: Sat Mar 11, 2006 3:19 am
- Location: Atlanta, GA
Re: Which programming language is more useful?
Incorrect terminoloty, I hate how the forum doesn't let you edit after 15 minutes...Pradu wrote:How about creating Evaluator functor whose () is a function overloaded to take in a board pointer.
How about creating an Evaluator functor whose () is a function takes in a board pointer.
-
- Posts: 287
- Joined: Sat Mar 11, 2006 3:19 am
- Location: Atlanta, GA
Re: Which programming language is more useful?
Another example. Suppose you would like to generate databases at program startup but you don't want to remember to do this or you would like this code to be kept out/hidden. You could create a "static class" and create an instance of that class. For examplePradu wrote:It can get cleaner too. I'll give two examples.
struct MagicMoves/ZobristKeys/whatever
{
static members variables rmagic, bmagic...
MagicMoves() { ... initialization code ... }
}; //create an instance of MagicMoves in magicmoves.cc and it will be created at startup without you thinking about it