Which programming language is more useful?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: Which programming language is more useful?

Post by sje »

Pradu wrote:
Pradu wrote:It can get cleaner too. I'll give two examples.
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 example

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
Be careful with this. If there are multiple class static initializations, all of which run before main() is called, there is no way to control the order of the initializations. Sometimes it might work, sometimes it won't. If the program has a dependency on the order of class initializations, sooner or later it will fail and it's a hard problem to detect and fix.
User avatar
michiguel
Posts: 6401
Joined: Thu Mar 09, 2006 8:30 pm
Location: Chicago, Illinois, USA

Re: Which programming language is more useful?

Post by michiguel »

Zach Wegner wrote: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.
I agree 100%.

Sherif, I was in your same situation and I have a strong opinion on this ==> Buy the classic "The C programming language" by Kernighan and Ritchie and learn it. It is a short book and if you are a skillful learner, your will be programming in C in no time. Of course, you have to like programming.

For a chess engine you do not need C++. IMHO, for people like you or me, C++ is the worst decision possible. If you like to go higher level for other reasons, then learn Python. If you are going to make a living out of programming, maybe C++ is for you.

I think it is more important to buy a good book on data structures, than learn specifics of a complex language as C++. Keep the language simple, and go deep into structures and algorithms. Besides, I believe this is more fun.

When I started programming, I started with Turbo Pascal (~80's). Later, I learned the Object oriented features of new versions (early 90's). It was cool to learn, but implied an effort that was not needed. I just did it as a hobby.

Learn C first, and then you will realize that you will never need C++ :-) You may like to learn it as a hobby, though (as I may like to do it some day).

Of course, this is my very humble opinion from a non-professional programmer.

Miguel
Pradu
Posts: 287
Joined: Sat Mar 11, 2006 3:19 am
Location: Atlanta, GA

Re: Which programming language is more useful?

Post by Pradu »

sje wrote:Sometimes it might work, sometimes it won't. If the program has a dependency on the order of class initializations, sooner or later it will fail and it's a hard problem to detect and fix.
True, this technique only guarantees that your static object will be constructed when entering main and destroyed when the program exists, you may not use this object before main. However, you would have to do this manually at the start of main anyways (if you didn't use this technique) which I think reduces modularity and therefore I use this technique.
playwaycool

Re: Which programming language is more useful?

Post by playwaycool »

swami wrote:
playwaycool 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.
http://wbec-ridderkerk.nl/html/enginesindex.htm

Use the dropdown list at the left to select engine and see which programming language It's been written in.



Yeah, I tried that but some programs are not listed and some are outdated! Hiarcs for instance is not listed among some others.
Pradu
Posts: 287
Joined: Sat Mar 11, 2006 3:19 am
Location: Atlanta, GA

Re: Which programming language is more useful?

Post by Pradu »

sje wrote:there is no way to control the order of the initializations
I guess if you need to use code for other static objects that are constructed before main you must be sure the static object is initialized:

Code: Select all

#include <stdio.h>

struct A
&#123;
    static bool initialized;
    static int a;
    A&#40;) &#123; initialize&#40;); &#125;
    static void initialize&#40;)
    &#123;
        if&#40;!initialized&#41;
        &#123;
            /* other initializtion code */
            a = 3;
        &#125;
    &#125;
&#125;x;

bool A&#58;&#58;initialized = false;
int A&#58;&#58;a;


struct B
&#123;
    B&#40;)
    &#123;
        A&#58;&#58;initialize&#40;);
        printf&#40;"%d\n",A&#58;&#58;a&#41;;
    &#125;
&#125;y;

int main&#40;)
&#123; return 0; &#125;
playwaycool

Re: Which programming language is more useful?

Post by playwaycool »

I agree 100%.

Sherif, I was in your same situation and I have a strong opinion on this ==> Buy the classic "The C programming language" by Kernighan and Ritchie and learn it. It is a short book and if you are a skillful learner, your will be programming in C in no time. Of course, you have to like programming.

For a chess engine you do not need C++. IMHO, for people like you or me, C++ is the worst decision possible. If you like to go higher level for other reasons, then learn Python. If you are going to make a living out of programming, maybe C++ is for you.

I think it is more important to buy a good book on data structures, than learn specifics of a complex language as C++. Keep the language simple, and go deep into structures and algorithms. Besides, I believe this is more fun.

When I started programming, I started with Turbo Pascal (~80's). Later, I learned the Object oriented features of new versions (early 90's). It was cool to learn, but implied an effort that was not needed. I just did it as a hobby.

Learn C first, and then you will realize that you will never need C++ :-) You may like to learn it as a hobby, though (as I may like to do it some day).

Of course, this is my very humble opinion from a non-professional programmer.

Miguel[/quote]




Miguel, Your suggestion is very logical along others as well. I don't mind how hard is the language is! My point is really which one is more useful for a starting project like a chess engine. I guess my point is if C is just as sufficient as C++ when it comes to a chess engine then it would make more sense to learn C and can learn C++ later if needed. If speed is one issue and that is what differentiate both languages then I can see C++ is better deal for a chess engine and therefore it would be up to me whether to learn C first to get myself started and then upgrade to C++ but bottom line is for someone like me C or C++ will not make too much difference for learning purposes, C might be slightly easier but from someone that have 0 experience both languages should be just as hard! and since I may not need C and all intended project is meant to be for C++ I guess I will have to challenge myself to learn C++ anyway, but again I see the major chess program is C++ so that alone gives a hint to me somewhat hehe.
playwaycool

Re: Which programming language is more useful?

Post by playwaycool »

playwaycool wrote:I agree 100%.

Sherif, I was in your same situation and I have a strong opinion on this ==> Buy the classic "The C programming language" by Kernighan and Ritchie and learn it. It is a short book and if you are a skillful learner, your will be programming in C in no time. Of course, you have to like programming.

For a chess engine you do not need C++. IMHO, for people like you or me, C++ is the worst decision possible. If you like to go higher level for other reasons, then learn Python. If you are going to make a living out of programming, maybe C++ is for you.

I think it is more important to buy a good book on data structures, than learn specifics of a complex language as C++. Keep the language simple, and go deep into structures and algorithms. Besides, I believe this is more fun.

When I started programming, I started with Turbo Pascal (~80's). Later, I learned the Object oriented features of new versions (early 90's). It was cool to learn, but implied an effort that was not needed. I just did it as a hobby.

Learn C first, and then you will realize that you will never need C++ :-) You may like to learn it as a hobby, though (as I may like to do it some day).

Of course, this is my very humble opinion from a non-professional programmer.

Miguel



Miguel, Your suggestion is very logical along others as well. I don't mind how hard is the language is! My point is really which one is more useful for a starting project like a chess engine. I guess my point is if C is just as sufficient as C++ when it comes to a chess engine then it would make more sense to learn C and can learn C++ later if needed. If speed is one issue and that is what differentiate both languages then I can see C++ is better deal for a chess engine and therefore it would be up to me whether to learn C first to get myself started and then upgrade to C++ but bottom line is for someone like me C or C++ will not make too much difference for learning purposes, C might be slightly easier but from someone that have 0 experience both languages should be just as hard! and since I may not need C and all intended project is meant to be for C++ I guess I will have to challenge myself to learn C++ anyway, but again I see the major chess program is C++ so that alone gives a hint to me somewhat hehe.[/quote]
Aleks Peshkov
Posts: 892
Joined: Sun Nov 19, 2006 9:16 pm
Location: Russia

Re: Which programming language is more useful?

Post by Aleks Peshkov »

Most C programs are already C++ programs. Any C program can be easily refactored to compile under C++ without warnings. No reason to use parts of C++ that you do not understand in your first programs.

There are good reasons to use const modifiers, references instead pointers, variable declarations at any place and so on for faster generated code.

There are good reasons to start from C++ Standard Template Library but not from <stdio.h> and their friends.
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 »

michiguel wrote:For a chess engine you do not need C++. IMHO, for people like you or me, C++ is the worst decision possible.
I most definitely belong to the same class of people as you and Sherif, but I don't quite agree. I think a sane subset of C++ is a better option than plain C. The stronger typing, in particular, is a huge win for me, and helps me find a lot of stupid bugs at compile-time. Strings, namespaces and templates are also very useful.
If you like to go higher level for other reasons, then learn Python.
Python isn't too bad, but I would rather recommend Common Lisp, Haskell, Objective Caml or Ruby.
If you are going to make a living out of programming, maybe C++ is for you.
I don't think I agree here either. It is easier to find interesting jobs in non-mainstream programming languages. In a typical C++ or Java job, you'll get colleagues who learned C++ or Java in college in order to get a job, and never bothered to learn anything more, because they didn't have to. In a typical Haskell or Common Lisp job (I make a living from Common Lisp myself), you'll get colleagues who are sufficiently passionate about what they do to study new and exotic languages to expand their horizons and learn new ways to think about about computing. These people are a lot more interesting to work with.

I think jobs in non-mainstream languages are usually also better paid, but I could be wrong.

Tord
User avatar
Roman Hartmann
Posts: 295
Joined: Wed Mar 08, 2006 8:29 pm

Re: Which programming language is more useful?

Post by Roman Hartmann »

I would recommend that you learn C first. The programming language isn't that important anyway and as C is more or less as subset of C++ you will waste less time learning the syntax of a programming language.

Rather spend your time on the project than trying to understand all the concepts in C++.

In theory C++ forces the programmer to produce clean and nice structured code but it's easy to create messy code with either C or C++.

Roman