Learning to code by doing exercises

I like to learn new programming languages, but it’s hard to find books that offer actual hands-on exercises. Sure, answering questions regarding a language or programming in general might help to understand the concepts. But I’m the type of person with a “learning by doing” mentality and thus I prefer practial training. Okay, I could set myself some tasks but I’m really bad at coming up with ideas and I think that practice should go hand-in-hand with theory.

When I wrote the application for my master thesis (which I’ll go into detail in another post) I had to learn a new programming language (Chapel), but besides simple tutorials I only had the official documentation for help, which is understandable since the language is rather unknown. In the end I did well because I had a specific goal in mind, but I’m also an intermediate programmer and mostly learning a new language means “learning a different syntax” when you already can code.

I’m currently trying to learn PHP5 since I have a chance to get hired as a PHP developer but I can’t find any resources that offer exercises beyond the usual questions (What’s a variable, what’s an array, etc.). I did the Code Academy course, but that one is really lacking. So if you know anything, let me know. In the meantime, I’ll list here some excellent books for learning to code with actual exercises.

Books for Beginners

  • Programming from the Ground Up by Jonathan Bartlett – If you like to go bottom-up, this one is for you. You are going to learn to code in Assembly and get an insight into how computers work. Later on the book moves to some C. This book was actually used as the lecture notes in the third semester system programming course of my bachelor degree studies. I read it mostly on my way to and from college (via train) since it’s more of a theoretical book, but it’s written so well that I make this little exempt from my rule. It’s free to download.
  • A Byte of Python by Swaroop C H – A well written introduction to Python. It may not contain explicit exercises, but it encourages the reader to type in every example, since it’s more than a simple usage example aggregation. It’s not only useful for beginners but also for experienced coders who don’t know Python. Also free to download.
  • Learn Python the Hard Way by Zed A. Shaw – It sounds more intimidating than it actually is. This book focus entirely on exercises and requires you to type everything by your own. It’s NOT recommended for experienced programmers since it focuses a bit too much on strings and it can get really tedious. It used to cost only $2.99 for the PDF version when I bought it but now it’s almost $30 since it includes lesson videos. But you can read it for free online.
  • Learn Ruby the Hard Way by Zed A. Shaw – This is basically Learn Python the Hard Way, but for Ruby. It contains the exact same exercises tailored for Ruby. Unlike the Python version this one still costs $2.99 for the PDF version, but it also can be read online for free.
  • Learn Java the Hard Way by Graham Mitchell – Despite the name it’s not by Zed A. Shaw, but it’s inspired by his books and his similarly structured, containing solely exercises with short explanations instead of long explanations with almost no exercises. It’s also a bit more bearable for experienced programmers. Unlike Zed’s books this one can’t be read for free online (except for a few sample exercises) and costs $19.95, which includes future versions.
  • Learning GNU C by Ciaran O’Riordan – While it’s not complete (a few lessons are missing), and is probably never going to be completed, it’s a good introduction to C. GNU C that is. The target platform is GNU/Linux (don’t want to get interjected) or GNU/Hurd, so if you like to do your work on Windows you’ll be out of luck. It’s freely available in HTML or PDF.

Books for Experienced Programmers

  • Learn C the Hard Way by Zed A. Shaw – Zed again, but this time it’s getting serious. This book is NOT for beginners, because it skips the explanation of all the usual terms (what’s a variable? String? Function?, etc.) and goes deeper into actual Computer Science, as you’ll not only learn to code in C but also basic algorithms and data structures. You will also learn to create your own library and set up Makefiles. Before I read that book I was mostly indifferent towards C, but now I’m loving it and it’s most likely my favourite language now. It’s still a work in progress and can be read for free as HTML since no PDF version exists yet.

The lists are going to be updated if I encounter more useful books.