Slashdot Mirror


2nd Edition of Learn Python the Hard Way Released

theodp writes "Are you or your kid intrigued by Python, but not quite ready to purchase an in-depth O'Reilly book? Zed A. Shaw's 2nd edition of Learn Python The Hard Way may be a friendlier option. Shaw's path to Python programming is simple: 1. Go through each exercise, 2. Type in each sample exactly, 3. Make it run. If $60 for the hardcover is too much to ask, or $15.99 for paperback, you can spend a measly buck for the PDF/ePub download. Still too steep? OK, there's even a free online HTML edition. After completing the 52 exercises, Shaw's concluding Advice From An Old Programmer says, 'Which programming language you learn and use doesn't matter. Do not get sucked into the religion surrounding programming languages as that will only blind you to their true purpose of being your tool for doing interesting things.'"

25 of 167 comments (clear)

  1. Languages are different by gweihir · · Score: 3, Interesting

    They can be in your way, they can make you jump though hoops, they can require you to create so much noise that you need tools to write anything in it (java is a prime example). If you are a truly good programmer, you want a language that does not tell you how to do things and just lets you do what you think is right. Even if that language has less extensive libraries than others.

    Personally, I like Python, Lua and C at this time. Python does OO but does not force a specific, limited model on you as most other OO languages do. The one thing that comes close is Eiffel, but at the price of the compiler needing global scope. Lua is just plain elegant minimalistic and again supports OO, but as you see fit, not some restrictive inheritance model. And C just lets you do what you want, very fast if you know what you are doing, although OO, while feasible, has no language support at all. But often you can do without in C anyways. (Yes, even people that understand and like OO sometimes find that not using it is better.) In addition, all three languages are light-weight.

    As to C++, I think that abomination would have been better aborted before birth. You need to know far too much about its internal execution model to write efficient code. At the same time, it is not light-weight anymore.

    I also have observed that most of the Java crowd never manages to get to the level of being even mediocre programmers. To me these people look more like "library call sequencers" that could not ever do anything useful without these libraries and development tools that automatize a lot. Quite often this leads to slow, complex and insecure solutions, where the code is basically unreadable due to too much code, to many layers, too much abstractions and no insight on the part of the programmer. Sometimes Java code is 95% clutter and noise. This problem is less pronounced with other languages. One piece of advice I therefore give to anybody that wants to learn programming is to avoid Java like the plague. This is definitely only a language for quite advanced programmers, although the typical Java programmer is very far from that indeed.

    --
    Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
    1. Re:Languages are different by greg1104 · · Score: 4, Insightful

      Java as a base language is just fine. The problem is that the sort of problems people like to solve with Java involve things like database interaction, web applications, and user interface construction. And doing all those things turns Java programming into a giant library exploration exercise.

      Many other languages end up falling into the same trap if you try to push them toward the same things Java aims at. Python for example has a pretty weak database interface layer. If you want to build a non-trivial DB app, you're likely to add both a database driver plus an ORM solution to make that work sensibly. As a PostgreSQL developer I run into psycopg2 + SQLAlchemy as an example combination. The resulting code is arguably no less "library call sequencer" than a similar solution built using JDBC + Hibernate. And the Java one also fits together into all these other "enterprise" app widgets--application servers and database connection poolers for example. You can do all that in Python, too, but you'll find yourself wandering into the same scale of library mess in the end.

      Building an application development framework toolkit that doesn't feel like your language has been turned around to suit the needs of the library is a hard problem. I think one of the reasons Rails has become so successful is that it did a better job than most of avoiding that problem (albeit while giving you a whole different set of problem trade-offs to worry about instead).

    2. Re:Languages are different by Raenex · · Score: 5, Insightful

      They can be in your way, they can make you jump though hoops, they can require you to create so much noise that you need tools to write anything in it (java is a prime example).

      While I'll admit that Java has too much boilerplate, tools are good regardless of any language you use. You don't need tools to write in Java -- people managed before fancy IDEs came along. However, because Java is statically typed, it lends itself to more powerful tools. This is really helpful as projects get bigger.

      I also have observed that most of the Java crowd never manages to get to the level of being even mediocre programmers.

      Oh please, cut the bullshit bashing. I could say the same thing about Python programmers, but that's just throwing insults around.

    3. Re:Languages are different by Nursie · · Score: 3, Interesting

      Python's good.

      It's quite refreshing to go to a language where (as someone with a lot of experience in programming but not much with python) with such flexible syntax that "I wonder if I can write it this way?" usually works.

      And as for rapid prototyping it's great. A couple of evenings and 500 or so lines of python and I can have something that would take me weeks in C. Of course in C I would have had more fine grained control over behaviour and I do run up against barriers in python every so often.

      The major downside for me is the GIL. For anything processor intensive you have to work around the language to use the resources of a modern system, rather than work with the language.

    4. Re:Languages are different by Capsaicin · · Score: 2

      I like python too. My *ONLY* bitch about it is beginning and ending tags that are non existent. Indent level? Really?

      I think we all felt that like at the beginning. Now I get really annoyed when I have to use curly braces.

      I can NOT tell you the number of times this has created a bug for me, because the spacing was off. Had one 'flavor' where if you mixed tabs and spaces in the same file (one dev liked tabs the other spaces) or didnt put tabs on empty lines it would cause the python interpreter to go into lala land.

      You need a get text editor. :p

      Seriously though this isn't a major problem if you take a few steps to avoid it. For a start, make sure your text editor will substitute any tabs you might accidentally put into python code with four spaces. Say you use vim or a derivative (I use gvim), put a line in your .vimrc file which will do this automagically, ie au FileType python set shiftwidth=4 expandtab (you also need to make sure .vimrc has :filetype on with pure vi you have to use a hack of setting ts really wide (as there is no et). But whatever text editor you have you ought to be able to set this up.

      Secondly if you are working with someone else's code check for mixed tabs and spaces by running python with the -t or even -tt switch at the cmd line. If there's a problem just do a quick sed s/\t/ /g src.py > src_fixed.py or do this in your editor.

      Once your work environment is properly set up this problem simply vanishes. With time you will come to appreciate the clean code this affords us. Marking blocks by indentation is both easier to type and because it enforces good indentation practice, easier to read and maintain. I had a similar problems with the python idiom (not enforced) not to use accessor methods, but to access attributes directly. Until I realised the properties overcame any tight coupling issues and allowed for changes in object level implementation without breaking any dependencies on that object, all the while resulting in code that is much easier on the eye.

      What is this punch cards? Seriously? Indent level? Did I step back into the 60s or something?

      I've been trying, in vain, to find that Dijsktra quote about how indentation might in the future be used to mark off blocks ... did I just imagine it? Suffice to say that in the 60s, 70s and 80s they could only dream of such syntactic simplicity. This is nothing like column specified Fortran. If that is truly your "*ONLY*" bitch, then with a bit of workflow setup and some more experience using the language, you are about to fall seriously in love!

      --
      Better to be despised for too anxious apprehensions, than ruined by too confident a security. --Edmund Burke
    5. Re:Languages are different by abigor · · Score: 2

      The multiprocessing module is your friend. When it comes to Python, forget threads.

      "multiprocessing is a package that supports spawning processes using an API similar to the threading module. The multiprocessing package offers both local and remote concurrency, effectively side-stepping the Global Interpreter Lock by using subprocesses instead of threads. Due to this, the multiprocessing module allows the programmer to fully leverage multiple processors on a given machine."

    6. Re:Languages are different by m50d · · Score: 2

      You don't need tools to write in Java -- people managed before fancy IDEs came along.

      I'm pretty sure anyone who did that will be taking early retirement for their RSI. Java has its place but writing it unassisted is literally physically painful.

      --
      I am trolling
  2. From lesson 0 by xs650 · · Score: 4, Funny

    "A programmer will eventually tell you to use Mac OSX or Linux. If the programmer likes fonts and typography, they'll tell you to get a Mac OSX computer. If they like control and have a huge beard, they'll tell you to install Linux. Again, use whatever computer you have right now that works."

  3. Other Free High-Quality Tech Books/Writing? by theodp · · Score: 2

    Philip Greenspun has some good titles: Philip and Alex's Guide to Web Publishing (dated, but I paid cash money for it back in the day), Software Engineering for Internet Applications, and SQL for Web Nerds. If you find yourself in the DB2 world, Graeme Birchall's DB2 SQL Cookbook is a must-have.

  4. Exercises not all that good by Warlord88 · · Score: 2, Informative

    I am a novice level programmer in C++/Python and I thought I could benefit from this book. But the exercises seem to be ridiculously simple and it seems a book only suited for someone with zero or negligible programming background.

    1. Re:Exercises not all that good by gweihir · · Score: 3, Interesting

      ... it seems a book only suited for someone with zero or negligible programming background.

      It is. There is a place for such books as well. It does not hide this fact either.

      --
      Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
    2. Re:Exercises not all that good by Warlord88 · · Score: 2

      My bad. I never thought Slashdot could run a story on a programming book that I find it easy!

  5. This sounds like a good start by billstewart · · Score: 2

    A month or so ago I decided to pick up a Python book at the Borders-is-dying sale, and while it's from O'Reilly, the book is too much of a reference - a lot of bottom-up "here's are six different list-like things" and "nobody expected the Spanish Inquisition, which is why you need to use this method to catch the exception it throws, but you can change that by overloading _ _ that _ _ method name's variable __pope__ or using _ComFyChaiR_ instead, but you can't set __pope__ to French, because that object uses __antipope__ instead, though in later versions you can modify it by using Cardinal()."

    A friend of mine pointed me to python.org's tutorials", which were going to be my next step, but this looks pretty simple and accessible too.

    --

    Bill Stewart
    New Fast-Compression-only CPR http://preview.tinyurl.com/dy575ks
    1. Re:This sounds like a good start by Toksyuryel · · Score: 2

      A good, free book I've been learning from is http://diveintopython3.org/ I find it to be much better than this book. This book gives really bad advice. For example, claiming that "vim and emacs are for professional programmers only" completely disregards that the only way to get good at either of them is by USING them for a while, a good long while, which would go so well with the message he claims to be sending with this book. Instead of stopping to learn them later, which could take months, you could be learning them concurrently with Python (which is in fact what I am doing right now). Advising not to learn Python 3 AT ALL is similarly bad advice- it's that sort of mentality that causes the adoption rate to be so slow in the first place. Learning both side-by-side would be much preferable, and then you could use your new skills to help port all the old libraries lying around to Python 3.

  6. Re:Only a limited starter no Python by gweihir · · Score: 3, Interesting

    I have been doing Python 3 for some time. The language is better than Python 2, but you still frequently run into things that are not ported yet. So I would definitely advise either to learn Python 2 and have a look at 3 or the other way round.

    For larger projects, I would advise to still use Python 2 at this time, but with a style that allows an automated upgrade later on. This will mean not using some Python 2 features.

    --
    Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
  7. Forget that, go OCW and GPL book by x1n933k · · Score: 2

    Check out MIT's OCW. Free lectures with a GPL Python programming book that does an excellent job at explaining programming and the Python language. The lectures are bad quality but the projects are good for practice.

  8. Re:Misleading by greg1104 · · Score: 2

    Oh, you think watching Python on VHS is the hard way, do you? Why, in my day, if we wanted to see a good Monty Python skit we had to go kidnap the performers, construct a set, and buy enough booze to get them drunk enough to perform. VHS? Luxury.

  9. Code by people much better than you by billstewart · · Score: 3, Interesting

    One of the things I really liked about C was that once you've learned a few basics like how pointers and structs work, looking at code written by people much better at C than you just makes sense and comments like /* you are not expected to understand this */ are quite rare. That wasn't as true about C++ or Java, where many kinds of things are readable (after getting the basic "object" stuff down") but some of the template stuff is too obscure. It wasn't true at all about APL or PERL :-)

    I was expecting Python to resemble LISP with a different syntax, but it's looking a lot messier than even Common LISP, and of course a lot of the moving parts are hidden in the large number of pre-written modules that come with Python.

    --

    Bill Stewart
    New Fast-Compression-only CPR http://preview.tinyurl.com/dy575ks
    1. Re:Code by people much better than you by ginbot462 · · Score: 2

      >> books for Python but resources for intermediate/advanced programmers are harder

      I somewhat agree, I feel its like that for many languages except domain specific (e.g. graphics, database) ones for C/C++, but would like to point out two other O'Reilly ones:
      Programming Python (Unfortunately, covers a bit too many unrelated, but advanced topics for me)
      Python Cookbook (Recommend this one, though like it implies, all over the place. You pretty much read it online)

      However, when you get into more specific items like: SWIG/boost wrapping you're left with documentation and google.

      --
      Atlas Shrugged : Thematic Story :: Battlefield Earth : Organized Religion
  10. Re:What format is the PDF in? Kindle? by Inner_Child · · Score: 3, Informative

    You can always grab the ePub for that same $1 and use Calibre to convert it to a format the Kindle can use. I just bought it myself, looks great on my Nook.

    --
    Today is red jello day - all workers must eat all of their red jello. Failure to comply will result in five demerits.
  11. Exercises that good by JeremyBanks · · Score: 2
    That is the idea. The first sentence from the site:

    Have you always wanted to learn how to code but never thought you could?

    and then from the next paragraph:

    ...At the end of LPTHW, you'll know the basics of coding...

  12. Non issue by Capsaicin · · Score: 3, Interesting

    No, the fact the language doesn't deal with the real programmer's life issues with (eventually) bad text editor, or simply because there will always people with bad or diverging habits is python downside.

    In the same way that the the it is difficult to drive nails into wood with a nail file is the downside of a nail. Once you apply the correct tool in the correct fashion the problem vanishes.

    Really all you have to do is alias python to path/python -tt and there is no problem only a syntax error. Or Alternatively, I have a "bad habit" I tend on occasion to leave the semi-colon off the end of the line when writing in Perl or C. Thus both Perl and C's "downside" is that they "[don't] with the real programmer's life issues .. simply because there will always people with bad or diverging habits." Makes sense to me.

    The fact that one may or may not use a text editor that you consider "good"

    I wrote "... whatever text editor you have you ought to be able to set this up." If you can't then the editor is not "good," but not as a function of my personal aesthetics, but due to its lack of fitness to do its job. Are there really programmer's text editors out there that cannot substitute a tab for four spaces throughout a file?!!

    You may "like it", and I can see why ... but do not dismiss the issues associated with it.

    After 2 or 3 months annoyance with the tabs/spaces "issue" followed by about 10 years withoIn factut even noticing any, I think I'm entitled to dismiss the "issues associated with it."

    As it happens I wasn't dismissing the issue, I was offering advice about how anyone still suffering from this issue could dismiss it.

    --
    Better to be despised for too anxious apprehensions, than ruined by too confident a security. --Edmund Burke
  13. 'learn new languages in about a day".... Bullshit by cruachan · · Score: 2

    Most of this "advice" is bullshit. The "line I've been programming for a very long time. So long that it's incredibly boring to me. At the time that I wrote this book, I knew about 20 programming languages and could learn new ones in about a day to a week depending on how weird they were. " gives it away.

    Sure if you've got a background covering C you can pick up those languages based on C syntax pretty quickly - in terms of writing raw statements - but that means very little as most of the heavy lifting these days is done using the supporting libraries. Sure myself I picked up C# syntax in about that, but groking .Net to a productive level takes a fair bit longer. Even Javascript, which appears very simple for someone with a C background is deceptively simple to think you've got but you're probably missing out on the subtleties whole protoypical inheritance model. And then there's C++. Can anyone who doesn't code C++ as their day-job for less than two years really claim to have C++ and completely under their fingers?

    And we haven't even considered more unusual things like Haskell or Prolog, or even Lisp where it's not just a question of the syntax. Sure if by 'picking up' you mean getting to the point of being able to code Quicksort then yes, but otherwise - well I call bullshit. And I've got over 20 years experience and an average of one language a year over that (but I'd only claim to really have half a dozen completely understood).

  14. Just snagged a copy by bazmail · · Score: 2

    This is exactly how I like to learn, a dew lines about the code, the code, and expected output. Its concise, no crud in there. Its a format i'd like to see more of. I remember reading a C++ book, one of those monster ones from the late 90s that used up about 50 pages printing out encoded resource files, pages and pages of non-human readable crap. (Being a nub at the time I actually typed a lot of it out)

  15. Re:'learn new languages in about a day".... Bullsh by Medievalist · · Score: 2

    I've got over 20 years experience and an average of one language a year over that (but I'd only claim to really have half a dozen completely understood).

    I've got almost 40 years in, and long ago lost count of languages, operating systems, and hardware environments.

    You'll get past this stage.

    You will never have any living computer language "completely understood" for any significant amount of time if you are working on anything more meaningful than simply tracking that language's implementation arc in a world of constantly changing underlying platforms.

    There's a difference between learning a language and memorizing that language's commands and libraries. There's a difference between knowing a language and knowing which language features are optimally supported on a specific OS or hardware implementation, too.

    Learning how you learn is the key, and I think you've already got that. Trying to learn every single thing there is to know about a computer language is a waste of time that could be better spent creating something wonderful. Instead, just learn language weaknesses and vulnerabilities, and google for syntactic boilerplate as you need it.

    Hopefully you'll reach a point where you know exactly what you want to accomplish, and how that can be optimally computed in the target execution environment (regardless of whether that evironment is an embedded RISC processor or a browser DOM) and you'll plot the best path to get to that goal in whatever languages are available to you.

    Eventually you'll probably start avoiding the use of any libraries at all, and start liking languages with very terse syntax. When you find yourself preferring to write fifty lines of C rather than five lines of perl that calls in 50,000 lines of code from CPAN, look out! If you don't keep that tendency well under control, you might turn into Paul Graham.

    To avoid that fate, train yourself to always write code that is maintainable by people who are far less skilled than you are. That way you can delegate maintenance and enhancement to less skilled hands, and go do more interesting things yourself.