Which programming language is more useful?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
Andres Valverde
Posts: 557
Joined: Sun Feb 18, 2007 11:07 pm
Location: Almeria. SPAIN

Re: Which programming language is more useful?

Post by Andres Valverde »

playwaycool wrote: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.
My two cts :

Don't forget Pascal. It's a nice entry point. There is a bunch of engines written in Pascal, some of them very strong (Delfi,Booot, Spiderchess...). Easy to learn, easy to debug and fast enough.

There is a free compiler for all plattforms :

http://www.freepascal.org

Also a nice IDE :

http://www.lazarus.freepascal.org/

And of course Delphi, which creates a slightly faster code although there is no Windows 64 bit version.

There is a big problem though : When you get used to Pascal you won't like to go to C or whatever :-)
Saludos, Andres
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Which programming language is more useful?

Post by mcostalba »

playwaycool wrote:I have 0 experience with programming
I strongly suggest you to get your hands dirty a bit before to start thinking about chess engines...any language is suitable to learn the metodology and the "logic"...you can even start from excel macros or something like that.

Programming languages are different, but the underlying logic is the same for all of them.


If you find it difficult to learn by yourself, then I suggest to buy/get some good beginners book and play with that....I warn you though...reading about progamming is ABSOLUTLY not enough...it is like trying to learn to go by bicycle looking at tour de france on the TV.

If after a while you still want to program, then you can ask yourself again the same above question...you will have more clues to answer it.

Good luck!
PK
Posts: 893
Joined: Mon Jan 15, 2007 11:23 am
Location: Warsza

Re: Which programming language is more useful?

Post by PK »

I've programmed my first engine in Delphi, which is basically Pascal with bells and whistles, and liked it very much. It's easier to learn and leaves less room for errors. The real problem with using Pascal is not with writing, but with reading - eventually one might want to read other program's sources, and they are written mostly in C, be it with plusses or not. Come to think about it, we even lack good didactic chess peograms in Pascal.
MattieShoes
Posts: 718
Joined: Fri Mar 20, 2009 8:59 pm

Re: Which programming language is more useful?

Post by MattieShoes »

For chess engines specifically, C or C++ as noted. As for programming in general, I'd pick a higher level language (ie. java, C#) to start with.

I suppose it depends on what you want. Higher level languages tend to hide some of the ugliness that goes on under the hood but they tend to be slower. I think this makes learning basic concepts about things like classes, functions, loops, data structures, and so forth much easier (because you're not worrying about things like pointer arithmetic, pointers to pointers, how multiple inheritance works, what #typedef means, annoying treatment of strings, etc.

One could write a very clean, functional engine in high level languages that will beat the pants off most people. It'll never be as fast as ones written in C or C++, but lets be honest, your first attempt at an engine wasn't going to be anyway. :-)
Tord Romstad
Posts: 1808
Joined: Wed Mar 08, 2006 9:19 pm
Location: Oslo, Norway

Re: Which programming language is more useful?

Post by Tord Romstad »

mcostalba wrote:Programming languages are different, but the underlying logic is the same for all of them.
Many people think so, but I don't agree, and I think most people who make such claims have never been exposed to any languages apart from descendants of Algol (like C, Pascal, Java, C#, etc.). Once you move to other paradigms, you'll quickly be forced to think about algorithms and data structures in new and initially completely alien ways. Try a concatenative language like Forth or Factor, a lazy, purely functional language like Haskell, a dynamic object-oriented language like Smalltalk, or a logic language like Prolog.

I find that learning new programming languages is an fun, addictive and often mind-bending experience, as long as the new languages are sufficiently different from those I already know (going from Pascal to C, for instance, wouldn't be a big change).

Tord
bhlangonijr
Posts: 482
Joined: Thu Oct 16, 2008 4:23 am
Location: Milky Way

Re: Which programming language is more useful?

Post by bhlangonijr »

Tord Romstad wrote:
mcostalba wrote:Programming languages are different, but the underlying logic is the same for all of them.
Many people think so, but I don't agree, and I think most people who make such claims have never been exposed to any languages apart from descendants of Algol (like C, Pascal, Java, C#, etc.). Once you move to other paradigms, you'll quickly be forced to think about algorithms and data structures in new and initially completely alien ways. Try a concatenative language like Forth or Factor, a lazy, purely functional language like Haskell, a dynamic object-oriented language like Smalltalk, or a logic language like Prolog.

I find that learning new programming languages is an fun, addictive and often mind-bending experience, as long as the new languages are sufficiently different from those I already know (going from Pascal to C, for instance, wouldn't be a big change).

Tord

This kind of discussion is like talking about religion with others: People tend to "pull for" what they feel more comfortable with. Even if they do not know the other side.

In my professional life Java is everywhere literally. But my personal preference is C/C++. Whatever. Both are powerful, native code and you can write elegant source.

BTW, there's a fun website benchmarking languages:

http://shootout.alioth.debian.org/

Regards,
Uri Blass
Posts: 10310
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: Which programming language is more useful?

Post by Uri Blass »

MattieShoes wrote:For chess engines specifically, C or C++ as noted. As for programming in general, I'd pick a higher level language (ie. java, C#) to start with.

I suppose it depends on what you want. Higher level languages tend to hide some of the ugliness that goes on under the hood but they tend to be slower. I think this makes learning basic concepts about things like classes, functions, loops, data structures, and so forth much easier (because you're not worrying about things like pointer arithmetic, pointers to pointers, how multiple inheritance works, what #typedef means, annoying treatment of strings, etc.

One could write a very clean, functional engine in high level languages that will beat the pants off most people. It'll never be as fast as ones written in C or C++, but lets be honest, your first attempt at an engine wasn't going to be anyway. :-)
What about writing a chess interface?
What is the simplest chess interface with free source code to learn from it
and which computer language is best to use for it.

What are the computer languages that are practically used for
chess sites like
http://chess.emrald.net/ or
http://chesstempo.com/
Daniel Shawul
Posts: 4185
Joined: Tue Mar 14, 2006 11:34 am
Location: Ethiopia

Re: Which programming language is more useful?

Post by Daniel Shawul »

If you have to pass around pointers of objects, c becomes ugly quickly. For a chess program C may be just enough, especially when you take in to account that most program alone,and that they know the ins and outs of their program by heart. But for everything else there is no doubt c++ is better. It is more elegant and robust IMO.
Tord Romstad
Posts: 1808
Joined: Wed Mar 08, 2006 9:19 pm
Location: Oslo, Norway

Re: Which programming language is more useful?

Post by Tord Romstad »

Daniel Shawul wrote:If you have to pass around pointers of objects, c becomes ugly quickly. For a chess program C may be just enough, especially when you take in to account that most program alone,and that they know the ins and outs of their program by heart. But for everything else there is no doubt c++ is better.
I think almost the opposite: A chess program is one of the very few types of software where I would prefer using C++ over C. C has one huge advantage over C++: It is much easier to interface with C code from other languages. This advantage isn't all that important for a chess program, but very important in may other types of software projects. For the majority of complex real-world applications, writing most of the program in some high-level language and a few low-level functions in C where necessary will be a simpler and more robust solution than writing everything in C++.

Tord
User avatar
Zach Wegner
Posts: 1922
Joined: Thu Mar 09, 2006 12:51 am
Location: Earth

Re: Which programming language is more useful?

Post by Zach Wegner »

Pradu wrote:
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.
It can get cleaner too. I'll give two examples. First keeping this in mind:
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.
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.

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 8-)
There are no doubt advantages to C++. The code you mention is cleaner (at least the searching/evaluating part, the "back end" of that would be pretty ugly IMO). I'm talking about the C/C++ -> assembly translation. But what you say illustrates the point. With the functors it looks like you are just calling a simple function(), but in reality it is adding a parameter to the call stack that you don't notice. With C you know exactly what calls are being made.

Also, the search function you mention is IMO bad design. You want all the board data declared once as a class. Including it again in the search function is bad. So maybe you could use board.movestack[] rather than board->movestack[], but thats it. And either way you are still passing around a pointer and doing an indirection. C just makes sure you know it (and also allows you to not pass it to certain functions where you don't need it).