Ask HN: Books that teach programming by building a series of small projects?
Which are some of the best books that take a project based approach in teaching programming to a beginner?
Which are some of the best books that take a project based approach in teaching programming to a beginner?
It was my first introduction to rust and the book was quite enjoyable. It starts off with teaching you the very basics of a command line (what it means to exit, true, or false, etc) and each chapter has you recreate a popular command line tool (like grep, cal, tail, wc) while introducing a new rust concept.
The book also does TDD, test driven design, by first teaching you how to create these tests then in subsequent chapters having the tests prewritten for you.
It's definitely worth a look, the author has a great writing style as well that isn't as monotonous as most programming books I've read.
[1] https://www.oreilly.com/library/view/command-line-rust/97810...
edit: Based on your "It was my first introduction to rust" comment I think maybe you meant programming beginners?
The book basically uses the crate clap to create all the CLTs, along with specific crates for regex and creating ascii tables for the cal clone.
Many of the books being suggested in the other comments are available as well (will definitely start Hands-On Rust because it seems very cool, and Practical Common Lisp shortly afterwards).
Out of all the "tutorial" offerings I only pay for three services:
O'Reilly (four years so far)
Educative.io (two years)
Frontendmasters (eight years)
Every year I test out other services (pluralsight, lynda/linkedin learning, egghead, etc) but outside of one or three core offerings they don't seem to be a good value for what I want.
Compare this to pluralsight, which I feel like 80% of the courses are just regurgitating the documentation back to the user very poorly, or udemy that whose courses are typically stretch to 20-40 hours when they topic barely warrants 4 hours (see any frontend course).
I like educative.io because they are the best interview prep site out there IMO, I also enjoy some of their specific topics outside of interview prep (devops, concurrency, threading, etc); what's nice about educative.io is that it's all text based, I read way faster than I can watch. Also helps that they had a really good discount a few years ago that I'm still using (something like 3 or 4 years for the price of a single year).
O'reilly is great because, as I stated elsewhere, they have an enormous collection of books not just from O'Reilly but Packt Publishing, Manning, Apress, No Starch Press; they also have decent video courses from the same publishers as well.
There are very few technical books I'm willing to buy a physical copy of, I don't live in a large space so I have limited area for the books I do have, I do however like reading technical books. I'm also grandfathered in at a previous price point, so I feel like I'm "forced" to get my moneys worth. So reading 12-15 books is the "worth it" spot for me.
- 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...
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...
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.
Do you just search for projects in the language your using on github?
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).
Yes for example https://nostarch.com/inventwithpython and https://nostarch.com/big-book-small-python-projects
Not only is the book free to read (although I would suggest to pay for it if you like it!) The code to parse binary files actually "inspired" my design of an actual production application which was very flexible, succinct and, most importantly, so fast I had to spend a lot of effort convincing people the numbers are actually true.
It taught me some important lessons about how you can achieve performance with Lisp languages and the real reasons for the power of macros. Not too shabby for the first book on Lisp I red!
In lisp (and code is data, data is code), the function is also a list, so you would be able to use all the normal programming tools to iterate over the list, add new items to the list, etc, which can change how the function runs.
If I have a function Foo that adds two numbers together. How is that represented in lisp (as a list you say?)? How would one alter that function/lisp-list: to multiply numbers instead?
Edit: a macro example, which I think may be the more common route of doing this type of stuff? https://lisp-journey.gitlab.io/blog/common-lisp-macros-by-ex...
I'm only a beginner in lisp too, but it as simple as
(defun add-numbers (a b) (+ a b))
if you look at it as "everything between () is a list" then you'll find the above code is actually: [word word [word word] [word word word]]
to get it to multiply numbers instead, you'd just get the last item of the list `(+ a b)` -- replace the first item `+` with `*` (using other list functions, etc..) and then re-evaluate the entire list again,So now your function will multiply values instead of adding them..
The "power" aspect comes from the fact that we use "other list functions" to change the code, ie: code is data that we can manipulate.
note, probable errors, like I said, I'm new
You shouldn't do it in any Lisp production code. E.g. in ANSI Lisp, self-modifying code is undefined behavior. Even if you get some expected results, it may not work portably, and won't work if the code is compiled. Compiled Lisp code doesn't have a list representation any more.
Code-is-data lets us have a transformation pass on the code with application-defined rules, before it is interpreted or compiled. This is a recursive step that returns a new version of the code based on the old
In my opinion the 'everything is an expression' is the really tasty part of the lisps, which goes well with quoting.
I think top comment does a good job explaining that while I'd get the same functional result, Python objects have tons of abstraction behind them that make them harder to work with than lisp combinations.
(defmacro when (condition &body body)
`(if ,condition
(progn ,@body)))
That's not a new function that's been returned, just a new expression which can then be read (and macro expansion can be a repeated process as its read so you can use nested macros in macros in macros, even recursive macros but take care there).You can use macros as you describe, in a manner similar to a Python decorator, but that's only one of many possible uses.
They're just very simple macros based around the `if` special form. Because they're macros, they can just treat the body as data, i.e. it's not executed as part of argument resolution.
If you wanted to make a `when` function in Python, the "body" would have to be a callable like a lambda or named function.
I know this probably isn't the most compelling use case but I found it to be a really simple way to understand some of the benefits of macros and how they could be used elsewhere.
(analyze 1 2 expensiveComputation)
In python, to prevent evaluating all arguments when running analyze, I'd have to pass expensiveComputation as a callable or a function partial and remember to call it if I need it.
Whereas in lisp, I can pass whatever expensive variable I want into the macro because it will only get evaluated when using (expensiveComputation ...) and that's baked into the language.
Consider you want to implement printf that is compatible with C printf.
As the function implementor, you want something like printf("%d", 5+2, anExpensiveFunctionThatProducesAString()) do the right thing and print "7" on the terminal, but you get many more options and mechanisms you can use when implementing it in Lisp vs other languages.
Every other language:
* every time printf is called, all of the arguments have already been evaluated. There is no way to avoid calling the expensive function when the format indicates the result is not needed.
* every time the function runs you have to parse the format string. You could try and be smart and cache parsing results but this will quickly make it very expensive and complex and might cause problems when format strings are generated dynamically.
* your function cannot make use of the fact that both the format string and the argument never change
Lisp macro:
* you can decide to only evaluate arguments when they are needed,
* you can notice that the format string is static and output code IN PLACE of the macro based on this information. This means you have the option to make parsing happen only at compile time if it is possible.
* you can analyse the arguments further and decide to output code that does princ('7') IN PLACE of the macro. The resulting code will have no operations to parse or analyse anything and will always execute quickly and efficiently.
In general this is the way I think about Lisp macros vs functions in other languages:
"Lisp macros allow you to run logic at compile time that can create code dynamically that does exactly what you need it to do, no more, no less, based on macro arguments and/or unevaluated macro arguments and/or the environment."
Lisp macros are ultimate in building abstractions. Where in other languages you have to contend with the language always "sticking out" of your abstractions -- there is only so much you can do to hide the underlying language, in Common Lisp you can always hide the language completely. Implementing your abstraction is taking a data structure (can be for example an XML file) and running an arbitrary logic to generate another data structure (a function) that is then outputted in place of the macro. If the XML describes your binary file structure, the macro can take those descriptions and generate perfect parsing code that does exactly what is needed without any extra stack frames, conditionals, syntax artifacts, etc.
In a similar vein, there is The Architecture of Open Source Applications which is great:
There are some follow ups to the final project I like
Compile to WASM so you can run on the web: <https://hands-on-rust.com/2021/11/06/run-your-rust-games-in-...>
Port to the Bevy ECS: <https://saveriomiroddi.github.io/learn_bevy_ecs_by_ripping_o...>
But what sets this course apart from any other are the coding challenges. Following the thought process of a programmer in real time, watching him making mistakes and hunting for bugs is invaluable.
He uses p5js, a javascript library for graphics. The lessons are geared towards generative art but cover a broad range of topics including machine learning.
https://www.apple.com/swift/playgrounds/ (I've had more success introducing programming with this than with any of the links below; it's a very compelling intro for those who already own an iPad/Mac, and the core concepts are generalisable to other languages/environments even if it's specific to Apple's APIs and hardware.)
~~~
For Python:
https://automatetheboringstuff.com
https://nostarch.com/big-book-small-python-projects
~~~
For JS:
https://eloquentjavascript.net (project-based and for beginners)
https://javascript30.com (not for total beginners or self-study, would need a friend/tutor)
More beginner-focused alternatives are https://www.freecodecamp.org and https://thejsway.net.
Disclaimer: I've been teaching programming professionally for 15+ years and wrote the latter.
That's what I tell everyone
I think cloning is more the way to go. Pick some existing project/product and copy the essential components. Less choices, doesn’t have to end up getting used.
Proj-based learning is really fun to both create and consume imo.
So maybe showing the building blocks and letting you use them for something. You could perhaps show 2 or 3 suggested projects that are built with the building blocks. You show the generic version of the blocks, and then you figure out how to tweak them to make one of the 2 or 3 suggested projects.
Sort of buying the legos and then showing what you could do with them. But building it is up to you.
Now I've learned better I try to channel my learning energies into extending my portable, reusable library that solves common problems I can iterate, improve and port into future projects.
https://lets-go-further.alexedwards.net
That book is a follow-up to an easier book [1] that I also bought, but ended up skipping since I was only interested in writing JSON APIs.
I think it's a good method for experienced programmers, who are self-taught (like me) or just want to brush up some skills and knowledge.
Yes, you stay engaged, but there is also something to be said about porting code between different languages. The differences, strengths, weaknesses etc. stand out more, similarities become more clear and things that seem different, but are analogous emerge.
You will be forced to read more carefully and, more importantly, you will make typing mistakes. Hunting down your own mistake will teach you the subtleties of the syntax as well as further increase your understanding of the code.
For more advanced programmers, there is also the challenge of translating the code into another language entirely, which requires a actual semantic understanding of the code.
Also once the project is done, adding small additional bonus features will further deepen your understanding.
1. Typing out the code.
2. Going off route. Change things. Personalize examples. Break things and fix them.
3. Look up the docs for the language/framework/library and see how you can extend the project after each chapter.
It has a collection of blogs for building various small projects to learn different languages.
* Projectbook https://projectbook.code.brettchalupa.com/
* Project Based Learning https://github.com/practical-tutorials/project-based-learnin...
This is a bit on the edge of the domain that you're asking about (not really for beginners, and proofs are perhaps a somewhat niche type of programming) but I learned a lot from this and many people don't seem to know it, so I think it belongs in the list.
I thought the little projects you build along the way struck a good balance of interest, e.g. you're building a snake game by section 2 (but crucially you've already been exposed to how to think about data so you're not just dropped into the deep end with some boilerplate to fiddle with).
Anyway, i could write tons of praise for this book but it's convinced me to ditch python for teaching newbies and i LOVED python for getting newbies started real quick with projects for years.
One striking difference compared to most "beginner languages" is the Lisp-like syntax. I think focusing on problem solving rather than learning syntax is a great goal, but does this particular choice of a language make it harder for your "students" to continue learning in another language?
I'm assuming they would switch to a more popular language at some point (with syntax that resembles C), so I'm curious what that transition is like for beginners.
https://www.amazon.com/Road-learn-React-pragmatic-React-js/d...
Available free online at https://third-bit.com/sdxjs/
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.
For intermediate programmers, Build Your Own Redis[2] is a WIP book I am currently writing.
So I dug into it a bit, and from the introduction I see it's "mostly C with some C++ features". But if you're going to require C++ features/libraries and a C++ compiler, then it's not C. So why not just say it's C++? I guess another way to ask is: what makes it "mostly C"? Is it a market capture decision? Is there some interesting language tradeoff involved?
The chapters are structured so you are building 2 projects at once. One where you follow along with the chapter material with example code and explanations. And a second in the exercises.
I really like it because it introduces the concepts in the context of a project, but you can't get stuck because the code is there too. Then you need to really apply it in the exercises on your own project, without the example code.
http://raytracerchallenge.com/
It’s not really for beginners though, but maybe possible to start it together with a beginners book in a language of choice. It starts with points, vectors and matrixes, but gets more advanced later on. It’s around 250 pages and there’s basically no code provided, just test scenarios and a bit of pseudo code.
He's also written another book on mazes, but I haven't had the chance to read it. I wish there were a similar book on 2D graphics, which are plenty complex themselves.
https://www.goodreads.com/en/book/show/927128.Mud_Game_Progr...
I was failing my computer science classes first semester. Towards the end of the semester I sat down in the library for a few days and just went page by page typing every example and compiling it. Aced every IT class I had the next few years. I attribute that book to making everything "click" for me.
Once you understand the beginner concepts that book shows, then you as an individual would know where to look to gain improvement.
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.
Not to mention they're all freely available and give excellent value for both time and money: https://inventwithpython.com/
Was a really fun read.
So my rosetta code only allows you to implement the main part of the thing yourself. But it's not appropriate for beginners. It's more appropriate for teaching a new language to someone who is already an intermediate programmer.
[0] https://cloudresumechallenge.dev/docs/the-challenge/ [1] https://cloudresumechallenge.dev/book/
It teaches you step by step the basics of programming (loops, function calls etc) using a scratch-like programming language.
FREE https://leanpub.com/rubyisforfun - Ruby Is For Fun, I made the book so you do a lot of exercise. There is around 80 exercises in total.
Rewritten as a course:
Highlights https://automatetheboringstuff.com https://inventwithpython.com/bigbookpython
I still can't really code, but I can have a lot of fun tinkering because of that book.
In the domain of theoretical physics, I highly recommend, "From Newton to Mandlebrot".
I would start by examining that assumption: it varies from one person to the next. If you like the project approach then great, go for it, but for other people it can be better to exercise individual features of the language in isolation until they are well understood, rather than trying to put a lot of half-understood features together into a more complex program. I have gotten into trouble over this myself a few times, and now definitely prefer the piecewise approach to the project approach.
You will create a MP3 database, a web server, a spam filter, a HTML generator. Really practical!
https://news.ycombinator.com/item?id=22299180 Ask HN: What are some books where the reader learns by building projects?
You build a whole computer from scratch through small projects.
Sure, you want learn a specific language, but you’ll grock programming in general.
My strategy is to get to the 10th chapter of the book skipping the exercises, then go back and try them with a better overall understanding of the language and its nuances.
Great series.
The original was in Ratfor, which is a Fortran dialect. That being similar syntax but more limited than C is not a bad intro language.
- Find a recent book (< 2 yrs old) on LibGen.is
- OR, a Udemy.com video series (note: never pay more than $12 or so-- the promo rate. If you see a higher price, just create a new email & user account (or reset cookies?) and you'll see the promo price again)
- Visit: Roadmap.sh to get a sense of a learning roadmap what knowledge to build.
- Use a search engine to answer questions, such as "free learning resource for learning <XYZ thing>"
There's a world of difference in motivation when building something you want to exist, versus building a project because a book told you so.
It's lots of small problems that seem like projects and I've found it fun to expand on the examples on your own beyond what the book asks.
Recently all mainstream "learn to code" sources realised just making you memorise concepts doesn't work and started changing curriculum, but before that happens...
The best 2 resources I found are: - https://learnprogramming.online/ - https://scrimba.com
Both are project driven and won't hand-hold you if you want to continue, you need to proceed based on a mastery learning method.
I don't think that works as well when it is some random project from the book. Like, sure, better than dry code, but I'm far more motivated to learn when I also make something for me.
Having a nice curated problem put in front of me sets me off and it's easy from there.
But I think for more intermediate or advanced programmers it is very beneficial to go about a project in a more self-driven, free form way. Software design, exploration, research, reading specs and so on are half of the work (or more) in programming.
What I would have loved to realize when I was younger is that there's nothing you can't write. It might be a drastically simplified version compared of the real thing, but you can absolutely do it.
An operating system, a browser, a web server ("from scratch") a programming language, a video game (with a custom engine)... It's all possible with enough effort. And even if you don't want to do the up-front work yourself, it is easier to find cool, guided projects out there if you already know what you want.
A Common Sense Guide to Data Structures and Algorithms by Jay Wengrow * 2nd Edition * not only covers the theory really well but goes on to provide code examples in popular high level languages explaining when and how best to use them usefully. At the end of each section are prompts where you extend the lesson into a small project and each chapter builds on the last. The author has a github repo so you can compare your project solution to his. It made a rather dry topic extremely fun and approachable.
https://upload.wikimedia.org/wikipedia/commons/a/aa/Write_Yo...
_____
Python Crash Course by Eric Matthes has a section dedicated to projects.
I really liked this book.
This is what taught me Python.
I knew C before.
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.
and http://newcoder.io Both take the student through the process of building one fully-functional application.
This is an excellent resource.
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
[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.")Which book would you recommend to improve architectural design decisions, developing complex systems, etc? But on actual examples, e.g. by building a series of projects, or parts of it?
“Assembly Language, Step by Step”
Check those out.
But also pretty much every book does that.