Ask HN: Books that teach programming by building a series of small projects?

473 points by newsoul ↗ HN
It is common knowledge that when first learning programming, one should start with small projects to build something real rather than learning rules and syntax of the language only.

Which are some of the best books that take a project based approach in teaching programming to a beginner?

203 comments

[ 9.6 ms ] story [ 665 ms ] thread
If they don't exist, this is a good idea for anybody looking for a project to write a programming book
There are many, but the field is still wide open. Anyone with a particular domain experience should find a market.

There are lots of starting from scratch guides, and few focused guides.

for subject in ["Finance", "Contact Management", "Service Desk Automation", "Web Apps from scratch", "Web Apps on someone else's API", "Baseball Metrics"]: for language in ["R", "Go", "Python3", "Rust", "Lisp"]: print(f"Examples for {subject} in {language} would make a good book.")

edit: no idea how to smash indent-formatting into MD-for-HN

Prefix each line with two spaces, per the formatdoc page [0]

[0] https://news.ycombinator.com/formatdoc

  for subject in [
   "Finance",
   "Contact Management",
   "Service Desk Automation",
   "Web Apps from scratch",
   "Web Apps on someone else's API",
   "Baseball Metrics"
  ] : for language in [
   "R",
   "Go",
   "Python3",
   "Rust",
   "Lisp"
  ] : print(f"Examples for {subject} in {language} would make a good book.")
If we're talking a complete beginner with maybe only "hello world" level skills I recommend the Lego BOOST set: https://www.lego.com/en-fi/product/boost-creative-toolbox-17...

It teaches you step by step the basics of programming (loops, function calls etc) using a scratch-like programming language.

Not a book, but CS50x is a freely available course with high quality videos and lecture notes. The lecture exercises are programming projects of sorts. It teaches programming from scratch with C and then Python. Plus, since a lot of students take it, there are lots of online resources with tips, like the CS50 subreddit.

https://cs50.harvard.edu/x/2023/

CS50x and CS50web are fantastic. web is a bit outdated but it doesn't matter because the projects are so good.
There’s quite a few:

- Zed Shaw’s Learn More Python the Hard Way[1]

- Brian Hogan’s Exercises for Programmers (best for beginners or for learning a new language)[2]

- Hal Fulton’s The Ruby Way[3]

- Chris Ferdinandi’s Vanilla JS Academy[4]

- Marc-Andre Cournoyer’s Great Code Club (it’s old, and the community doesn’t exist anymore, but i think he still maintains it)[5]

- A few python books from No Starch Press (notably those authored by Al Sweigart)

I learned the most as a beginner from Zed Shaw’s work, and from reading open source code.

Once you’re done with the initial “learn from tutorials” phase, there’s no better resource than reading open source code.

[1] https://www.amazon.com/Learn-More-Python-Hard-Way/dp/0134123...

[2] https://www.amazon.com/Exercises-Programmers-Challenges-Deve...

[3] https://www.amazon.com/Ruby-Way-Programming-Addison-Wesley-P...

[4] https://vanillajsacademy.com/

[5] https://www.greatcodeclub.com/

Is Shaw's first Python book any good?
If you’re a pure beginner with zero programming experience, yes. If you’ve programmed a few scripts and have done a flask web app, his first book might be too easy.
I found his Learn Python3 The Hard Way to be a great series of exercises if you're starting out or starting again. You won't find -everything- on any topic, but the exercises are complete enough to get you rolling and seed the sort of patterns that will make you successful in looking for more material.

I had a little bit of Python(2) under my belt from general curiosity, and I've done some C++ in high school so I have some "CS Theory"

There is a "more" python version out now https://learncodethehardway.org/more-python-book/

Amazon ( the "newer" version proposed is not, it's his python2 book ) https://www.amazon.com/Learn-More-Python-Hard-Way/dp/0134123...

Shaw has had some strong opinions that have gone significantly against the mainstream viewpoint in Python. Whether he's right or not doesn't really matter - as an educator that is targeting the mainstream it's fairly important to stay on that and not introduce personal bias around these things. Unfortunately his criticism was often not very constructive.
despite my other comment here I do agree with you on this, especially remembering his comments on test tools, nose for example
Yeah, he pushed back hard against the Python 3 migration, by picking on a small number of trade-offs that he personally didn't like and using that to conclude that the entire endeavour was doomed. The Python 3 migration wasn't flawless by any means, but it was better than he made out.

I know his "criticism" also held back many from moving their libraries to Python 3 by sowing doubt in the community, and ultimately may have slowed down adoption overall.

If you ignore his strong opinions, it can be good. Although he was (is?) very much hated back in the day (when Python 2 was still mainstream), many many noobs did benefitted from his book. So I'd say give it a try.
> and from reading open source code.

Do you just search for projects in the language your using on github?

Yes, and I would typically search for simple projects using keywords such as “micro”, “small”, “tiny”, or “pico”.

I would then try to re-implement the “getting started” code in the readme from scratch, like a little programming puzzle. If I can’t figure it out, I‘ll add in some debugger breakpoints, inspect the stack trace to understand how it works, then code the needed methods / classes as I go.

If you’re a ruby programmer, soveran’s work in github can be read in a day or two. I specifically like cuba (micro webframework) and mote (microtemplate).

Specifically "Automate the Boring Stuff with Python" is my favourite Al Sweigart book.
I'm not much of a Python guy, but concur with this; I enjoyed this book and did get something out of it.
I would also recommend "Automate the Boring Stuff with Python" [1], as you are learning hands on with some practical stuff: from generating Excel-files to PDFs, from sending e-mails to work with files and folders. At the end you will have some tools to automate some of your daily tasks for real. Oh, and it's free to read as well.

[1] https://automatetheboringstuff.com/

I learnt ruby with Zed Shaw’s Learn Ruby the Hard Way. Was a really great experience!
I can recommend "Programming: Principles and Practice Using C++", although the fact that it uses C++ as a first language can be a downside to some.
Not a book, but check [Build your own X](https://github.com/codecrafters-io/build-your-own-x), a compilation of well-written, step-by-step guides for re-creating our favorite technologies from scratch.
It was better when Daniel maintained it.
>> one should start with small projects to build something real rather than learning rules and syntax of the language only.

Yes, but don't overlook the great learning that is gained, at the beginning of any learning, by studying from many different sources (aka good books). It seems that something magical happens when you do this: the confrontation of ideas from different sources can make you better absorb ideas and resolve any doubts that you didn't understand before.

Peter norvig’s paradigms of artificial intelligence programming, despite its age, is a delight.

https://norvig.github.io/paip-lisp/#/

But is that suitable for a beginner?
Yes, it is. It’s not about machine learning, neural networks but the more approachable AI of the 80s.
Haven't tried his, but can GPT3 write code that results in 1980s style AI?
It depends on what you mean by beginner, but I would say for someone who has been futzing with a couple of js boot camps or building some php websites, it’s what takes you from hacking to software development. Completely new to programming, maybe, if someone has a background in maths or physics and has a sense of “rigor” in thinking.

But, of all the books I worked through, this is the one I remember just having tons of fun because the examples are so cool and the code so… clear. I think norvigs programming course in python (which I only skimmed) could be a great modern equivalent.

When I was young, I went about it the opposite way. I thought of some small project and researched how to implement it, then moved on to something bigger. Everybody is different of course, but I felt like I learned more having to figure out how to go about implementing each myself.
Learn Swift in 100 days. It start with the basics using Swift Playgrounds. But as soon as possible, it starts with building apps.

https://www.hackingwithswift.com/100

Came to say the same thing - plus, there's a great 100 Days of SwiftUI as well, which gets nontrivial apps running pretty quickly.
"Hands on Rust" teaches Rust by building a rogue like game step by step. Before that there's a chapter where you rebuild Flappy Bird from scratch that teaches the "basics" before diving into more advanced concepts in the rogue like. I liked the approach and recommend the book but it's fast paced and expects quite a bit from the reader (it's excellent if you have some programming experience already but probably daunting as a true first book imo).
checkio.com for increasing challenges in Python or JS.

But also pretty much every book does that.

I don't know why jtimiclat's comment recommending Al Sweigart's books got downvoted and faded out, they are indeed quite good for beginners wanting to get their hands dirty with programming instead of cramming it in an academic way.

Not to mention they're all freely available and give excellent value for both time and money: https://inventwithpython.com/

This book is still in progress but I've gone through some of the chapters and have enjoyed it. Rust from the Ground Up: https://leanpub.com/rust-from-the-ground-up

I was looking for a book that had offline projects I can work on while on flights, and this book focuses on rebuilding linux utilities using rust. The other nice part is that you get a better understanding of linux internals.

I believe the author is also responsive on the rust subreddit.

Thanks for the kind words! I'm desperately polishing the next chapter for publication...
great to see you on HN as well! I haven't revisited the book in a while but I really liked the chapters I did work on. I have another flight coming up soon so maybe I'll try another chapter :)
Common Lisp: A Gentle Introduction to Symbolic Computation(https://www.cs.cmu.edu/~dst/LispBook/) has you build a number of small applications, like a substitution decipher application, a plotting function, and more, which it calls "keyboard exercises".