Zed finishes Learn Python The Hard Way
sheddingbikes.com
sheddingbikes.com
Now that I'm just working on Mongrel2 it feels like I do less. Weird.
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?
Of course they would probably consist of him saying "find something that pisses you off.Then fix it" over and over.
That MIGHT just be the secret to Zed's success -- that so much in the world seems to piss him off means that there is so much stuff he feels he needs to fix that he's constantly drowning in the need to fix something.
Some of us are more complacent -- I'm happy to fix the things that irritate me, but my body of work may be less prolific because I'm generally happy with the products that I use.
We called this process 'Hate Driven Development', and yes, in hindsight (and even in the moment) we all knew what she was doing, but she was clever enough to put it out there in ways where it worked even still.
In a nutshell, I quit trying to explicitly plan and organize my life (not that I was any good at that) and instead I have a giant bag of things I need to do. There's usually a bunch of projects, and each has a todo list. All I do is when I have the time to work on one AND the motivation, then I go bang out as much as I can until I can't. By having lots of different little projects I'm pretty sure I'll always have something to work on that motivates me at that time.
The only caveat on this is I then do one thing at a time. I see too many people who can't get their todo list down are usually trying to do 5 things at once. A good sign you're this kind of person is if you love patch queues. Just do one thing, and make sure before you do it that you can do it. Don't juggle 10 things at once.
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.
- 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.
It's not as if we are discussing monads (which are also easy to understand, given a good teacher).
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)
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.)
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)
Pulling in that language-community momentum can definitely make a difference to the social/technical dynamics inside a smaller group.
... if you have multiple developers who cannot or will not find some way to write maintainable code, you have a problem independent of language.
I've maintained some hideous code written by people who had no business being professional programmers. In every case, adhering to a handful of very simple rules would have improved their code dramatically. Only one case needed a language change, and that one was away from a proprietary 4GL.
Metaclasses can do some pretty powerful stuff though. One of those features that you might never need, but if you do, you really do.
[ (student.name, 'A') for student in students if student.grade > 90]
I'd assert that first class functions are idiomatic python as well and are also critical for python programming. They play an integral part of django, for example.(Functional programming, IMHO, isn't about maps and folds and filters anyhow; what those are are the tools it uses to gain composability. Python uses other tools for that goal; when in Python, you should use those tools. Ultimately, Python is an imperative language and will have all the associated flaws, functional probably does a better job of composability overall. But if you're in Python, you're not going to build a cute monadic combinator library that you can use in Python no matter how hard you try to box it about the ears with map and reduce, so you might as well use what Python actually has, which is classes and generators and list/generator comprehensions and lots of very overloadable syntax and so on and so forth. maps and folds and filters are the surface of functional programming, not the essense.)
(And yes, you can build a combinator library, you just can't make it slick.)
Reduce is the only one that is not clean in Python ("fold"), and the official word is to use loops. Again, it's usually not that great a loss, but the loss vs Haskell is greatest here. On the other hand, compared against some actually-functional languages you're still not typing much more; Erlang's folds are hardly any better than a Python loop, character-per-character.
accum = 0
for i in l:
accum += i
vs lists:foldl(fun (I, Accum) -> I + Accum end, 0, L)
First class-functions are absolutely idiomatic; what's not idiomatic is smashing things together with crazy "and" or "or" chains (or a variety of other hacky approachs) so you can have the magic-goodness-conferring word "lambda" show up in your source, instead of (horrors!) having to give your function a name.Speak the native idioms of the language you are in. A lot of people are missing a lot of the good things about Python because they are too busy complaining that it isn't something that isn't Python. It isn't functional at its core, but it can be a very powerful, concise language, if you work with it instead of fighting it.
I'm no Python expert, I couldn't say what's idiomatic or not. That being said, I never had the feeling of struggling with the language when using map and filter, quite the contrary.
What's the idiomatic way of doing this?
suffix_str_lst = map(lambda x: x + "_suffix", str_lst) suffix_str_lst = [x + "_suffix" for x in str_lst]
If you are okay with a generator instead of a list, then you can flip the square brackets to parentheses and then you do not need to hold the whole thing in memory at once.EDIT: You can add a filter in a similar way:
suffix_str_list = [x for x in str_list if x.startswith("meep")] suffix_str_lst = ['{0}_suffix'.format(x) for x in str_list if x[:4] == 'meep']OTOH, I can see how they could still be a hard concept for a beginner who hasn't done any functional programming before, particularly because they don't read front-to-back like most imperative statements.
EDIT: You can always split complex ones up as well, for most common usages:
meeps = [ s for s in str_list if s[:4] == 'meep' ]
suffix_str_lst = ['{0}_suffix'.format(m) for m in meeps ]
This one was probably a bit simple to really need that, but it's a bit easier to read. :).I'm only half kidding. The best way to get used to using functional concepts is to actually use them in their native setting, and then apply (giggle) them elsewhere. When you _have_ to solve problems this way, at some point, it clicks.
I can say that it has indeed improved my Python scripting as well.
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.
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 :)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.
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.
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.
[0] People will be a lot more helpful if they know you are trying to learn, rather than posting a "send me teh codes plz" request. Also they will hopefully give you just enough of a hint and not spoil the whole thing for you.
This.
I often find that I run into a problem, try to solve it on my own, then bring someone unfamiliar in to get a fresh set of eyes on it. It usually goes like this
Me: "Hey, I honestly can't figure out why this is doing this particular thing, can you take a look? <start explaining problem here in detail> ...FUCK! Nevermind, I know exactly whats going on. Thanks for your help"
Person I asked: "Huh?Uh sure? I can solve problems with my presence alone"
It seemed ridiculous, but it worked wonders. Most of the time said professor didn't have to open his mouth. It was just a matter of organizing your thoughts in a coherent way.
Then I get to stamp something 'solved' on my task list, and everybody's happy.
There's a wiki article about it here:
I've been programming professionally for almost 20 years. What you described right there is the fundamental skill/activity I have performed. Whether waiting for a spec, or decision if this feature is going in, or most commonly like your self looking for answer to some problem I don't get.
Good programmers either know everything (ha) or know how to learn/find the answer quickly. It's a great skill to start honing now.
Maybe some kind of forum in addition to the bok would be a good idea.
Of course, there's always irc.
On the other hand I might have used thatcher help too early...
Every programmer in the world is pissed that "I'm not sure - I'd Google It" is not an acceptable answer to a question about "how do I do X in programming language Y". Happens every day.
That being said - a book forum or Q/A section on the site would likely be very helpful. I'm learning Objective-C right now and the book I'm using has a corresponding forum associated which usually has the answers I'm looking for.
One thing about those though is that if you can't complete them, then just move on and maybe mark it for later. You should try to figure them out for a bit, but sometimes you just can't and have to come back to it later.
Finally, make sure you have this latest version of the book. I added a small section in the beginning which talks about this, so you might have an older version.
EDIT: Oh I'm assuming you mean the Extra Credits. The lessons you should try really hard to do and figure out before moving on. But skipping Extra Credit is quite alright.
Freenode’s web client http://webchat.freenode.net/ isn’t perfect, but it should be figure-outable when accompanied by some simple directions.
Example: http://stackoverflow.com/questions/3391998/pydoc-is-not-work...
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.
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
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)?
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=0BzdipdlNhpRrNWNmYjFlNmMtZTl...I won't do any of that yet though because I need to edit it and don't want people getting bad web pages from caches or places.
Ah well. His prerogative I suppose. Just makes me feel like "teaching people to program" isn't his primary goal.
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.
http://learnpythonthehardway.org/tktview/08a86ff3098eae91d8c...
Update it for me if I didn't understand what you think should be done.
python script.py only two_args
Just the traceback. It might be confusing to a newbie.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.
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.
-- It was a joke.