what are good books for learning to program C/C++

Discussion of chess software programming and technical issues.

Moderator: Ras

Stephan Vermeire (Brutus)
Posts: 34
Joined: Sun Oct 12, 2008 6:32 pm

Re: what are good books for learning to program C/C++

Post by Stephan Vermeire (Brutus) »

hawkeye wrote:I was wondering about what would be a good book(s) for learning to write code? I know nothing about it but would like to learn.


Steve
I can really recommend C++ for dummies:
http://www.amazon.co.uk/gp/search?index ... 0764568523

Stephan
User avatar
michiguel
Posts: 6401
Joined: Thu Mar 09, 2006 8:30 pm
Location: Chicago, Illinois, USA

Re: what are good books for learning to program C/C++

Post by michiguel »

mcostalba wrote:
michiguel wrote:
mcostalba wrote:
michiguel wrote:You can learn C even if you know nothing about how a processor works.
And please explain me how you justify you have stuff like integer, unsigned integer, long, long long, char, unsigned char, etc... just to say "an integer number".

And this is just a very silly example, but the list of stuff that exsists just because of how things are represented in hardware is very long in C, and _has_ to be like this given the reason why C was invented for.
If you read K&R II book, you learn whatever is needed to get you going. It is not that complicated.

Miguel
I have read it many years ago, thank you :-) ...and I am already going BTW
It was NOT a suggestion for you!
Miguel

But "not complicated" doesn't mean elegant or logical or well designed from a learning point of view. C was not borne to be a language from where to learn how to program (Pascal was), but not because it is complicated, but because has a lot of tricks and low level design compromises so to be powerful and useful mainly by system programmers in the real world, not in a laboratory.

Regarding Python et similars, they are interesting of course, but far from the chess engine applications, if this is his intended ultimate target it would be better to start with something well designed and so with a good attitude toward being a learning tool but not too far away from what is commonly used to build up a chess engine.
User avatar
Roman Hartmann
Posts: 295
Joined: Wed Mar 08, 2006 8:29 pm

Re: what are good books for learning to program C/C++

Post by Roman Hartmann »

ilari wrote:C is a small language, and thus easy to learn. "The C Programming Language" by K&R is very good.
...
Fully agree. If you're going to learn C, this is the book you want.

Roman
hawkeye
Posts: 62
Joined: Thu Apr 03, 2008 8:54 pm

Re: what are good books for learning to program C/C++

Post by hawkeye »

My ultimaye goal is to try my hand at wring a chess engine. I would take a look to find out what all is involved and get some ideas. Which would be the better language to learn?

Thank you much,

Steve
Venom

Re: what are good books for learning to program C/C++

Post by Venom »

Hi Steve,

A good no-cost solution to get your feet wet might be to check out free e-book http://www.mindview.net/Books/TICPP/Thi ... CPP2e.html

Bruce is a great teacher. You will need to get acquainted with a compiler but a realistic goal would be to give yourself 3-6 months with the book to get a good working knowledge of the material.

Learning basic programming part is not too tough, but _chess engine programming_ is definitely tough. I got my BSCS about 5 years ago, and have been learning chess engine development for about 6 months now as a hobby. I can honestly say that it has been the most challenging and rewarding experience so far. Not to try to discourage, but the amount of coding and the resulting complexity can get very high even for someone already beyond basics.

A great exercise once you get a handle on the basics would be to create a tic-tac-toe engine. The game itself is simple, but it still contains a taste of the concepts of a chess engine without the overwhelming complexity, e.g., turn-based, board representation, move legality, search, and evaluation (win-lose-draw).

Give yourself a realistic target for success and incrementally challenge yourself. When you are ready, there will be plenty of great resources for help and example code to learn from. Good luck in your quest :)
Aaron Becker
Posts: 292
Joined: Tue Jul 07, 2009 4:56 am

Re: what are good books for learning to program C/C++

Post by Aaron Becker »

I'll add a recommendation for "The C Programming Language" by K&R. It's clear and concise, and I think C make a lot more sense as a first language than C++.
Richard Allbert
Posts: 794
Joined: Wed Jul 19, 2006 9:58 am

Re: what are good books for learning to program C/C++

Post by Richard Allbert »

I have quite a few books for c++, the best learning books from these are

Accelerated c++ (König, Moo)
Essential c++ (Lipmann)
Schaum Outlines c++

Then, what helped as a general reference was

c++ for game programmers (Mike Dickheiser)

which had lots of tips on topics such as structure, preventing programs making hidden object copies, etc,

Regards

Richard
MattieShoes
Posts: 718
Joined: Fri Mar 20, 2009 8:59 pm

Re: what are good books for learning to program C/C++

Post by MattieShoes »

It may depend on your style of learning...

Be aware that learning to program requires a HUGE time investment... Kind of like playing a musical instrument, it isn't really rewarding until you've spent a lot of time doing bad renditions of Mary had a little lamb.

Most important I think is to write LOTS of code. I don't think there's any way around that -- You have to spend hours and hours and hours doing it, figuring out what you did wrong, and doing it again.

As for books, I prefer the "cookbook" style books... Rather than trying to lay out the language, it gives you specific examples to accomplish specific tasks. That makes it more concrete for me, less abstract, so I absorb the information faster. I end up getting the more abstract data through inference.

Language probably isn't that important, but one with C-like syntax is preferable I think, since a berjillion ubiquitous languages all share a lot of the syntax rules of C. And once you're proficient in one language, learning other languages is far easier.
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: what are good books for learning to program C/C++

Post by mcostalba »

MattieShoes wrote: Be aware that learning to program requires a HUGE time investment... Kind of like playing a musical instrument, it isn't really rewarding until you've spent a lot of time doing bad renditions of Mary had a little lamb.
Great truth !
MattieShoes wrote: Most important I think is to write LOTS of code. I don't think there's any way around that -- You have to spend hours and hours and hours doing it, figuring out what you did wrong, and doing it again.
Even grater truth !
MattieShoes wrote: And once you're proficient in one language, learning other languages is far easier.
Final truth :-)


P.S: Learning programming is easier when you are a kid, not because you are better but because you have more attitude at wasting your afternoons in front of a monitor doing the most silliness stuff without even bothering what are you doing. I have started when I was twelve with a monitor in front of me and a keyboard under my fingers doing all the possible and a good amount of the impossible stuff out of a computer and the only worrying thing was my mom that come to badly rescue me at dinner time :-)