12 ms·
Zed finishes Learn Python The Hard Way
- geoscopic 16y agoCool. Why isn't it 1.0?
- shin_lao 16y agoUnless I'm mistaken there's no chapter about functional programming in Python (lambda functions, filter(), map() and reduce()). I really think it's acceptable to introduce these function to newbies, I'll go as far as saying it's actually a good thing. I like the chapter on automated testing.
- charlief 16y agoWhile I do agree those principles are useful, I think introducing those topics would diverge the focus of the book. I think the goal was of introductory nature not comprehensiveness.
- danieldk 16y agoThere are some great beginner's books out there that barely cover functional constructs (e.g. PragProg's 'Learn to Program'). But I have always felt that such an omission is really a bad mistake. map/fold/filter introduce two very important ideas: - Higher-order functions - Many tasks are just list transformations What makes things more painful is that Java is so omnipresent in CS education. Since Java only contains such concepts implicitly (and require a lot of verbosity), I haven't encountered many (if any) Java books that go into functional concepts. It's like learning UNIX without covering pipes. Sure, you can work with UNIX, inadvertently emulate it using redirections from and to files. But it will never be as effective.
- zedshaw 16y ago"Higher-order functions, ... list transformations" you just said four words that are an entire book on their own.
- danieldk 16y agoSure, that's why Graham Hutton can do it in one chapter. Most books discuss lists and functions anyway, and from there is not such a big step to give an introduction to lambdas/closures, maps, folds, and filters. It's not as if we are discussing monads (which are also easy to understand, given a good teacher).
- zedshaw 16y agoDoubt it. He may have used a chapter of text to explain something, but who he explained it to probably could understand it in a chapter of text.
- steveklabnik 16y agoThe Python community has frowned on functional programming, reduce isn't in basic Python anymore, and they almost took out lambda: http://www.artima.com/weblogs/viewpost.jsp?thread=98196 http://www.artima.com/weblogs/viewpost.jsp?thread=98196
- RyanMcGreal 16y agoStrange that they took out reduce() but not map() and filter(), which you can easily replicate with list comprehensions.
- steveklabnik 16y agoYeah. The argument is based on reduce not being clear and easy to understand, which is frustrating to those of us who actually find map/reduce/filter to be more clear, not less.
- ubernostrum 16y agoreduce isn't in basic Python anymore It's in a module in the standard library, a module which contains a bunch of tools for working with higher-order functions. Or, in other words, if you've got a Python 3.x installed, you've got a reduce function available. The only difference is that it's no longer in the default global namespace (map and filter still are, of course). This matches up pretty cleanly with my actual experience of writing Python; I've written a hell of a lot of Python code these past 6-7 years and so far as I can recall I've never used reduce. (and if you want to get picky about this, keep in mind how much of Haskell requires import statements to get at -- moving less-commonly-used stuff into standard modules is not a bad thing at all)
- tdavis 16y agoDitto for generators. In the process you could introduce pipelining and thus give a window into the Unix way which is probably pretty relevant for a newcomer. Or I've just been around too long to know what's relevant for a newcomer.
- jokull 16y agoYeah generators are awesome. +1 for a chapter on them with small sprinkles of functional programming.
- jerf 16y agoHe didn't cover defining first-class functions that I could see in a quick check, didn't cover generators, and I think most disappointingly, didn't cover __metaclass__. That's some critical stuff for Python programming right there, everybody needs __metaclass__. Ahem. You have to pick what to cover. For a beginning Python book, I'm underwhelmed by the need to drag an entirely new and foreign(-to-Python) paradigm into the beginning Python. I say this as someone who does a lot of functional programming, someone who is using a lot of lambda, filter, map, and reduce is someone who is stubbornly refusing to program with the native idioms, which are named functions (defined inline is fine), list comprehension or loop, list comprehension or loop, and loop respectively. It is not that enormous a gain, and will lose from Python fighting you all the way. (Plus you'll probably miss some opportunities to use generators, overload the special methods, and the other things you can do with native idioms, if you're trying to program Haskell in Python.)
- sharms 16y agoI have programmed literally hundreds of thousands of lines of python without using classes or __metaclass__, as a counter example. When dealing in industry, we can't always hire the best talent, so there is no need to make things overly complex. Simple solutions work best for a lot of scenarios, and I haven't been limited by it yet. Not to bash Perl, but the whole reason we write in Python is because there were too many people on our team writing in Perl using too many obscure constructs that took too long to review / revise (especially years later when team members changed and code was forgotten in parts)
- araneae 16y agoMeh. I just sent this to a friend of mine that knows nothing about coding, but is taking a class (biology) that uses python. She really has no need of functional programming, she just needs to know how to survive her problem sets. I think that's the audience.
- zedshaw 16y agoExactly. I taught programming, not dogma. Frankly, if I can teach two paradigms, and one is easy to explain while the other is hard, well I'm going to teach the easy one to explain. Functional programming is just hard to explain to people who know next to nothing. Especially in a language like Python where the functional concepts are kind of half-assed.
- zedshaw 16y agoYou are not mistaken, there is no chapter on functional programming. Why? Because "The Little Schemer" is a way better book for teaching better functional programming than I could possibly do in a Python book. Python's functional concepts are just not really that great, so I couldn't explain them very well.
- illumen 16y agoIf you're not teaching pythons functional concepts, then you're not teaching python. However I think you have accidentally... consider this short example which shows off first class functions, map, reduce, no side effects, and filtering. [(lambda a,b,p:(a+p,b+p))(x,y,2) for x in (1,4) for y in (10,15,22) if x*y > 25] Python does functional programming without people even knowing that it is functional programming :)
- MrJagil 16y agoI am learning python through this book at the moment. It is my first attempt at learning to code, so I have nothing to compare it with, but I must say that this book is very good. My only gripe is that he poses certain questions/exercises that he fully expects us to solve, one way or another. But if we cannot; we're screwed. He does not give the answer. It has only happened once so far, but that was enough for me to miss out on what seems like a pretty crucial part of the book.
- mechanical_fish 16y agoHe does not give the answer. Welcome to graduate school! (And, for that matter, real life.) As in grad school, the secret is: If you can't figure it out, ask around. Form teams that stay up until 3am waving their hands and sketching on chalkboards. If nothing else, it's a bonding experience that you'll treasure for life.
- MrJagil 16y agoI get your message, but the problem is this is not grad school. This is a book; one way communication. I have no one to ask, as I am the only one I know who has an interest in coding. Of course I can always ask on the web, but having to break off from coding, pose a question, and then wait for it to get answered before I can continue really breaks up my learning curve.
- davidw 16y agoYou could ask on #python on the freenode irc network.
- volski 16y ago>Of course I can always ask on the web, but having to break off from coding, pose a question, and then wait for it to get answered before I can continue really breaks up my learning curve. You're skipping a vital step. Searching for the answer on the web. Most of the time the question you want to ask has already been answered.
- RexRollman 16y agoZed, May I suggest making it available in other formats, assuming that it is possible, once it is finished? Perhaps as text or HTML files in a tarball? Or even as an epub (for Nooks and iPad)?
- midnightmonster 16y agoIn the absence of an epub, GoodReader on the ipad is very handy for reading PDFs as books. The type is a little small on this document, but I am able to read it without zooming and panning.
- cmsj 16y agoWhat does GoodReader have over using iBooks? I've mostly just used it for storing manuals for tech products so far, but it seems like a reasonable way to read PDFs.
- pchristensen 16y agoMainly performance and options. Page turns, navigation, zooming are all faster. iBooks is my favorite eBook reader but GoodReader is noticeably better for reading pdfs. A mandatory app for iPad, along with Dropbox, SimpleNote and Instapaper.
- ludwigvan 16y agoAlso you can crop the margins of pages so that they fit better without zooming in. It can convert pdf to text on the fly too, though of course there are formatting issues.
- FraaJad 16y agoThe source files are written in rst(ReStructured Text) format, the standard documentation format for Python. Specifically using [Sphinx](http://sphinx.pocoo.org http://sphinx.pocoo.org). One of the default output formats IS HTML. Build instructions on *nix: $ fossil clone http://learnpythonthehardway.org lpthw.fossil $ mkdir lpthw $ cd lpthw $ fossil open ../lpthw.fossil $ make html $ open _build/html/index.html To install sphinx: $ easy_install sphinx or $ pip install sphinx Here you go: a zipped file containing HTML files on google docs. https://docs.google.com/leaf?id=0BzdipdlNhpRrNWNmYjFlNmMtZTlhNC00NTk2LWE1NmItNzYyYTgwZDY1NzEx&sort=name&layout=list&num=50 https://docs.google.com/leaf?id=0BzdipdlNhpRrNWNmYjFlNmMtZTl...
- SteveC 16y agoMongrel 2 and now a book on Python. The man is a machine.
- regularfry 16y agoIf I remember correctly, he's also currently unemployed. This may be relevant :-)
- jonknee 16y agoHe does more without a job than most people do with one.
- Luyt 16y agoHe's also planning to give python classes: http://codelesson.com/python http://codelesson.com/python (discussed in http://news.ycombinator.com/item?id=1724354 http://news.ycombinator.com/item?id=1724354)
- boundlessdreamz 16y agoWasn't he employed with dropbox?
- lrm242 16y agoHe was.
- zedshaw 16y agoI am, but to be honest, I got more done when I had a job. See all those sites? I did all of those, wrote for them, worked on LPTHW, wrote mulletdb.com, hacked on lamson, a few other projects, and still played guitar about 4 hours a day. Now that I'm just working on Mongrel2 it feels like I do less. Weird.
- nocman 16y agoGeez, man. Do you ever sleep? :-) Oh, and just out of curiosity, what guitar music are you spending the most time on? Is it mostly your own stuff, or are you learning a lot of things written by others?
- atomical 16y agoI was looking forward to reading through this until I found out that I will go insane. -- It was a joke.
- VMG 16y agoThe last chapter (Advice From An Old Programmer) is very thought-provoking and slightly unnerving for someone who is studying CS
- trop 16y agoIt's a lovely chapter! Thanks for pointing it out. Programming as an intellectual activity is the only art form that allows you to create interactive art. ... . The world needs more weird people who know how things work and who love to figure it all out. It's inspiring to see him talking about the beauty of (software) engineering as a means of making which has the quality of an art.
- VMG 16y agoThe chilling part is Programming as a profession is only moderately interesting. It can be a good job, but if you want to make about the same money and be happier you could actually just go run a fast food joint. You are much better off using code as your secret weapon in another profession. People who can code in the world of technology companies are a dime a dozen and get no respect. People who can code in biology, medicine, government, sociology, physics, history, and mathematics are respected and can do amazing things to advance those disciplines. I have always had the suspicion that this is the case but now I have some validation
- 2mur 16y agoYes. As a physician (pathologist) who is also a hobby-hacker that is particularly inspiring.
- jamie_ca 16y agoNice, but that's an annoying license. I'm tempted into porting his assignments to Ruby, but do to licensing I'll need to do them completely separately - I can't make a cohesive document out of it. Ah well. His prerogative I suppose. Just makes me feel like "teaching people to program" isn't his primary goal.
- zedshaw 16y agoDon't copy, imitate. The book was very easy to write. Just lay out 52 exercises, 26 for super basic stuff, 26 for progressively more advanced stuff. Take about an hour or two every night and write a couple. Pretty simple really. You may not have my style in your writing, but you'll definitely get a book that is more Ruby than what I've written. One warning though, if you think it'll be better to have the book crowdsourced, think again. Programmers seem to be pretty bad at teaching programming, so it's best to just write your book and have people give you feedback as you go.
- utefan001 16y agoI have read the first 20 pages. Excellent! Very well done. Great advice. Fun / proven way to learn. Thanks Zed!!
- zedshaw 16y agoYou're welcome. Remember if you run into errors, just submit a ticket for it on the learnpythonthehardway.org web site and I'll fix them up.
- gbrindisi 16y agoI am training myself in Python with this book from a week or so. I know how to code in other languages and programming basic so I am not a first time coder... yet this little book is absolutely useful and I am enjoying it exercise after exercise. Learning trough practice FTW! Thank you Zed.
- zedshaw 16y agoFantastic. Keep on plugging through and if you hit any problems just ask me. I'm on twitter @zedshaw so just ask and I'll help.
- emehrkay 16y agoVery nice. I just randomly choose to view the arguments unpacking section and found a defect (no example given on pg 36 for passing in only two args instead of all three, but later cited as "see how I passed in two args"). Created a ticket.
- zedshaw 16y agoThanks, I think I fixed it but the ticket is kind of vague: http://learnpythonthehardway.org/tktview/08a86ff3098eae91d8c3f9d562200cd6a8b7ab48 http://learnpythonthehardway.org/tktview/08a86ff3098eae91d8c... Update it for me if I didn't understand what you think should be done.
- emehrkay 16y agoYeah that's it exactly. You never show python script.py only two_args Just the traceback. It might be confusing to a newbie.
- statictype 16y agoLoved the final chapter. At the end of the day, it's not about functions or closures or monads. It's about building something interesting or useful. Whether you used php or arc is not relevant.
- Tarks 16y agoThankyou Zed, I'm going to give this a proper read-through before probably using it to help teach a friend how to learn to program.
- zeemonkee 16y agoI recommended this to a new hire (frontend HTML/JS guy, but wants to learn Python). He really found it easy to get into, and appreciated the exercises. Thanks for publishing it.
- instasaint 16y agoIf I were to type all 52 exercises from the book and use 2to3 tool, would it convert to a Python 3 book?