Which programming language is more useful?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
Bo Persson
Posts: 243
Joined: Sat Mar 11, 2006 8:31 am
Location: Malmö, Sweden
Full name: Bo Persson

Re: Which programming language is more useful?

Post by Bo Persson »

michiguel wrote:
Bo Persson wrote: If you want a new book about programming, aimed at beginners, try this:

http://www.research.att.com/~bs/programming.html
Thanks, I may go to the library and see whether I can read something interesting and learn. I mean it. However, I wonder the suitability of this book for a beginner in this hobby. That type of beginner is not the same as a comp. sci. first year college student. Just peeking at the sample pages available in that website I see the typical examples of a display model, oriented to teach OOP. IMHO, that is exactly what a beginner should be avoiding. Paticularly, if the goal is to write later a chess engine.

I would agree that C++ will be better than C if there is a book that teaches it as an "improved C", with better type checking, libraries, and that's it. Is there any? I believe that most of the whistles and bells will be distracting for a hobbyst, at least at the beginning. That was my point.
It teaches C++ as a language in its own right. That's why you should not start with C, and then "upgrade". C++ really is a different language!

If you already know how to program, you can learn C++ from "Accelerated C++", which also is C++ only - no C!

http://www.acceleratedcpp.com/

It teaches the use of the C++ standard library, containers, iterators, overloads, generic functions, and user defined classes, before going into the really difficult stuff like pointers and arrays. :-)

Think about it!

michiguel wrote:
michiguel wrote: 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).
Bo Persson wrote: Learn C++ first, and you will realize that you will never need to learn the ugly and very dark corners of the C standard library, with functions like strcpy, malloc, memset, or others with easy to learn names like strpbrk, strxfrm, wcsncpy, and sscanf.

There are large parts of the C runtime that you hardly ever use in a C++ program. Why start out trying to learn that?

Very few C++ programmers find it easier to have functions like abs, labs, cabs, and fabs for the absolute value of different types, when std::abs works for all of them.
You don't need anything of that to write a chess engine. The only thing I use from above is malloc in a couple of places, and that is wrapped in another function.

Miguel
No, so why do we say "learn C first", if you don't need it anyway? Cut to the chase, and learn the useful stuff first!

There is a lot of C that is of very little use, once you have learned the better ways of C++. So start there!
Karlo Bala
Posts: 373
Joined: Wed Mar 22, 2006 10:17 am
Location: Novi Sad, Serbia
Full name: Karlo Balla

Re: Which programming language is more useful?

Post by Karlo Bala »

Bo Persson wrote:
michiguel wrote:
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%.
I disagree about 98%!
michiguel wrote: 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.
That's the 1970's!

If you want a new book about programming, aimed at beginners, try this:

http://www.research.att.com/~bs/programming.html
michiguel wrote: 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).
Learn C++ first, and you will realize that you will never need to learn the ugly and very dark corners of the C standard library, with functions like strcpy, malloc, memset, or others with easy to learn names like strpbrk, strxfrm, wcsncpy, and sscanf.

There are large parts of the C runtime that you hardly ever use in a C++ program. Why start out trying to learn that?

Very few C++ programmers find it easier to have functions like abs, labs, cabs, and fabs for the absolute value of different types, when std::abs works for all of them.
Interesting!
I like C++ and I'm using it, but for IO & string manipulation I always use standard C runtime lib. :roll:

P.S.
I think that MODULA 2 is good programming language (for start), but I don't know if there is decent compiler (best I know is TOPSPEED MODULA 2 from 80's)
Best Regards,
Karlo Balla Jr.
MattieShoes
Posts: 718
Joined: Fri Mar 20, 2009 8:59 pm

Re: Which programming language is more useful?

Post by MattieShoes »

Haha, I write in C++ and use memset all the time. Is there some simpler C++ alternative to this to zero out a history table?

Code: Select all

memset(history, 0, sizeof(history));
Come to think of it, I occasionally use strcpy (but only on C strings with a proper terminator of course!)
And sscanf too... Whee!

I guess I really just know C and C#, and my C++ is a bit fuzzy. :oops:

I swear, the lack of standardized regex support in C/C++ is half the reason I end up using stuff like perl and C#
Dave Gomboc

Re: Which programming language is more useful?

Post by Dave Gomboc »

MattieShoes wrote:I swear, the lack of standardized regex support in C/C++ is half the reason I end up using stuff like perl and C#
An open-source implementation of the forthcoming C++ standardization of regex support has been available for some time already (see http://www.boost.org/).
wgarvin
Posts: 838
Joined: Thu Jul 05, 2007 5:03 pm
Location: British Columbia, Canada

Re: Which programming language is more useful?

Post by wgarvin »

MattieShoes wrote:Haha, I write in C++ and use memset all the time. Is there some simpler C++ alternative to this to zero out a history table?

Code: Select all

memset(history, 0, sizeof(history));
Come to think of it, I occasionally use strcpy (but only on C strings with a proper terminator of course!)
And sscanf too... Whee!

I guess I really just know C and C#, and my C++ is a bit fuzzy. :oops:

I swear, the lack of standardized regex support in C/C++ is half the reason I end up using stuff like perl and C#
I think the common belief that many people have that the C++ way of doing things like file IO or string formatting is somehow "better" than the C way, is a fallacy. The C ways are simple to use, the C++ ways are more complex and error-prone. Since the C standard library is still around, why bother with the more complex C++ crap for things that already work just fine in C?

The things about C++ that I think are actually more useful than C89 are:
class methods, operator overloading, inline functions, virtual functions, declaring variables wherever you need them instead of all at the top, and *some* uses of templates.

STL is a pile of crap compared to the container class hierarchies of good languages, but if you're stuck using C++ then using STL is often a lot easier and quicker than not using it. String manipulation using C++'s std::string class is also often easier than the C way. If you don't care too much about low-level performance or code bloat, the STL containers can be really handy.

On the other hand, there are a lot of bad things about C++ (or things that are easily misused, at any rate). See here for some good examples: http://yosefk.com/c++fqa/
Yes that site seems kind of biased, and a few years ago when I first found it (at a time when I had put down C++ and been solely a Java coder for years) I found myself wanting to argue against some of the FQA's criticisms of C++. But now after a few years of C++ again, when I read through the FQA, I find myself agreeing with nearly every point.
Hart

Re: Which programming language is more useful?

Post by Hart »

I am looking for the quickest out-of-the-box free C/C++ compiler and preferably bare-bones IDE. Anybody know where I can find this? Also, I would prefer to use binaries directly rather than something bundled with an installer that will touch my XP registry, but I can live with an installer if I have to. Any help would be appreciated.
playwaycool

Re: Which programming language is more useful?

Post by playwaycool »

Thanks all for the reply. I think i should ask this instead of making new topic. Programming chess engines under C++ will be under Console application or Windows Application? It's probably naive question to ask but I just wanted to make sure. I'm taking good guess it must be console application and GUI (interface) perhaps should be programmed under Windows 32 application perhaps?




I decided to challenge myself and learn C++ right away! If it's too hard I will try C or try even easier language but for now I'm going to spend time with C++ and see how well I will enjoy learning that
Gian-Carlo Pascutto
Posts: 1243
Joined: Sat Dec 13, 2008 7:00 pm

Re: Which programming language is more useful?

Post by Gian-Carlo Pascutto »

Hmm, I've used all of these at some point:

Code::Blocks
Dev-C++
Microsoft Visual Studio Express
Qt Creator

I think all of those require an installer, because you want at least to have the compiler binaries in the PATH.

I would not bother to learn Win32 programming. Learn Qt, wxWidgets, or another portable GUI toolkit. If you only care about Windows, just .NET may even be a better choice. It'll help you get things done faster than pure Win32. You can write 99% of an engine without having to care what platform it is running on (pondering is usually the first thing that causes problems).

Boost, which was linked above, is also good to learn. It should be considered an essential part of C++ programming nowadays.
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Which programming language is more useful?

Post by mcostalba »

MattieShoes wrote:Haha, I write in C++ and use memset all the time. Is there some simpler C++ alternative to this to zero out a history table?

Code: Select all

memset(history, 0, sizeof(history));

Code: Select all

*history = EmptyHistory;
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: Which programming language is more useful?

Post by sje »

When I first leaned C over thirty years ago, I was struck by the resemblance of scanf()/printf() functions with the horrible old Fortran read/write/format statements. I thought to myself that there must be a better way, and the C++ formatted character streams are that better way.

Don't bother learning C when C++ is available.