Lurker News
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?

Comments (203) 92 threads

azemetre4 replies#
While not for beginners, if you'd like to learn rust I recently finished "Command line Rust" [1].

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...

adolph#
Came here to mention just that book. It is excellent.
lifewallet_dev#
Thank you! I needed this one, how fun, I did this when learning Haskell, now I can do it with Rust.
dbalatero1 reply#
Just to clarify, when you say "not for beginners" do you mean beginners to Rust or programming in general?

edit: Based on your "It was my first introduction to rust" comment I think maybe you meant programming beginners?

azemetre1 reply#
Sorry, I meant that you need some programming experience. It will not teach the basics of if loops, making structs, etc; it's a good introduction to rust, prior programming experience required.
mrmuagi1 reply#
I'm assuming you also need to understand pointers and memory layout perhaps?

Continue this thread — 1 reply

racl1011 reply#
Glad we can buy the book standalone without getting a membership to O'Reilly.
azemetre3 replies#
I may sound like a shill but I think paying for O'Reilly is worth it. You get access to many books and videos outside the O'Reilly publisher. Definitely worth it, I tend to read a tech book a month (maybe 2 if it's "light.")

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.

racl1011 reply#
That's fair. I think some people just like the option of buying the book.

Continue this thread — 1 reply

digianarchist#
It's free if you have a Toronto Public Library card.
shrugsworth1 reply#
I'm curious why you pay for those services and not the others. Is it a matter of topics, teaching style?

Continue this thread — 1 reply

kennyfrc5 replies#
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/

darreninthenet4 replies#
Is Shaw's first Python book any good?
kennyfrc#
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.
cameron_b#
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...

danpalmer1 reply#
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.
cameron_b1 reply#
despite my other comment here I do agree with you on this, especially remembering his comments on test tools, nose for example

Continue this thread — 1 reply

mayankkaizen#
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.
7speter1 reply#
> and from reading open source code.

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

kennyfrc#
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).

Zhyl3 replies#
Specifically "Automate the Boring Stuff with Python" is my favourite Al Sweigart book.
michaelcampbell#
I'm not much of a Python guy, but concur with this; I enjoyed this book and did get something out of it.
downrightmike#
Best explanation of Regex that I have ever seen
taffit#
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/

jypepin#
I learnt ruby with Zed Shaw’s Learn Ruby the Hard Way. Was a really great experience!
twawaaay3 replies#
My favourite is "Practical Common Lisp" by Peter Seibel (https://gigamonkeys.com/book/)

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!

halkony5 replies#
I've been learning lisp this past week. I think I get the main idea of "code is data and data is code", but I struggle to understand how it's more powerful than, say, making a function factory in Python.
agumonkey#
maybe a function factory is just an OO pattern for return closures, it's difficult to not perceive things from 'now', but i'll be frank i 1) never liked DP 2) couldn't spend more than 5 minutes reading about them as it seemed more verbose and redundant
majormunky2 replies#
I'm also learning lisp, mainly as a part of learning emacs, so I may not be super accurate here. In python, when you have a reference to a function, its a bit opaque, you can tell the thing is a function, but I don't think you can really go into the function object, and alter it lets say. You may be able to using the AST or something, but its not a "first-class" thing you can do.

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.

altruios2 replies#
Such a concept could use an example to solidify that point.

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?

Continue this thread — 2 replies

kazinator#
This is not what "code is data" is supposed to mean. It means "source code is data": the source code of Lisp is a data structure.

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

cess111 reply#
Not sure what you mean by "function factory", could you elaborate? Isn't it metaclasses and decorators that are used for metaprogramming in Python?

In my opinion the 'everything is an expression' is the really tasty part of the lisps, which goes well with quoting.

halkony1 reply#
My naive interpretation of `defmacro` is passing data into a function to return another function. From my python POV that would be the same as returning a callable from a function (decorators being one example).

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.

Continue this thread — 1 reply

kfoley1 reply#
I used to have the same issue understanding the benefit. One simple example that helped it clicked for me was considering the `when` or `unless` macro.

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.

halkony#
So let's say i have a lisp macro along the lines of

(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.

twawaaay#
There is a number of reasons that make Lisp macros so much more powerful than functions in any other 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.

peterhil1 reply#
I was going to suggest this. It's cool that you build a file based database (IIRC) and query language in the third chapter!
twawaaay#
Also with so little actual code. This cemented my interest for Common Lisp at the time I was reading it.

Continue this thread — 1 more reply

Continue this thread — 4 replies

Load more comments