[HN Gopher] Show HN: Learn Python the Right Way - free introduct...
___________________________________________________________________
Show HN: Learn Python the Right Way - free introduction to Python
book
Author : sixhobbits
Score : 168 points
Date : 2021-05-13 13:08 UTC (9 hours ago)
(HTM) web link (learnpythontherightway.com)
(TXT) w3m dump (learnpythontherightway.com)
| bmitc wrote:
| I do think it's a bit ironic to have a title "How to Think Like a
| Computer Scientist" when using a language that explicitly and
| intentionally ignored some of the best ideas in computer science:
| lambdas, concurrency, pattern matching, functional programming,
| etc.
| dang wrote:
| " _Eschew flamebait. Avoid unrelated controversies and generic
| tangents._ "
|
| We're trying to avoid programming language flamewars here,
| among other kinds of flamewar.
|
| https://news.ycombinator.com/newsguidelines.html
| [deleted]
| teach wrote:
| Python _absolutely_ has lambdas and functional programming.
|
| And I would argue that concurrency, at least, has no business
| in a textbook for true beginners.
| jhla wrote:
| Python has restricted lambdas, no tail call elimination and
| hardly and FP in the standard library.
|
| It does not have the strong type guarantees of the ML or
| Haskell families; functional code in Python is fragile and
| complex.
| dragonwriter wrote:
| > Python has restricted lambdas,
|
| Python lambdas, _like those in virtually all functional
| languages_ , are a single expression.
|
| Python _expressions_ are somewhat limited (at least if one
| avoids non-idiomatic, and often somewhat ugly constructs)
| because Python isn't a purely expression-oriented language,
| and the Pythonic way to do certain things involves
| statements. [0]
|
| > no tail call elimination
|
| True, then again, TCO has a clarity cost and lots of lisp
| family languages have either no TCO or self-call-only TCO,
| or kinda-self-call-only-TCO-via-explicit-recursion-
| constructs.
|
| Python is metaprogrammable enough that you can do TCO via
| decorators (a couple of ways; I've seen mutual [1] and
| self-call-only done via stack frame manipulation
| decorators, and self-call only done even more efficiently
| via a bytecode injection decorator.)
|
| > and hardly and FP in the standard library.
|
| Not sure if you mean hardly any _use of_ of _support for_ ;
| if the latter, it is simply wrong, if the former, I haven't
| read much of the stdlib source code but who cares?
|
| > It does not have the strong type guarantees of the ML or
| Haskell families
|
| Which in turn don't have the metaprogramming capacities of
| the Smalltalk-descended line of dynamic OO languages. Its
| not _ignoring_ things to make choices that have tradeoffs.
|
| [0] but note that this is mostly about idiomatic, not
| functional limitations, there is very little if anything
| that idiomatically uses multiple statements in python that
| can't be done in a single expression using only language-
| level expression elements plus built-in and stdlib
| functions
|
| [1] that is, general but all participating functions must
| be decorated.
| kwhitefoot wrote:
| > concurrency .. has no business in a textbook for ..
| beginners.
|
| Why on earth not? Lots of people begin by wanting to program
| a simple real time game and concurrency of some kind is
| absolutely required to do that.
|
| Concurrency not being a first class feature of most
| mainstream programming languages and frameworks and being
| clunky in most of the rest is one of the biggest failures of
| language design in my opinion.
| turndown wrote:
| This is the kind of post where you really wonder if
| programmers even remember what it was like before they
| started programming. Concurrency is a legitimately
| difficult concept to understand and use correctly. In
| addition, I doubt you need concurrency in game design for a
| beginner project, or if you do, it's totally abstracted
| away by the game engine you're using to "learn".
| bmitc wrote:
| Just because most programming languages are terrible at
| concurrency doesn't mean it's a hard concept.
| Surprisingly, most people have little trouble with email
| or snail mail processes. It's just that a lot of
| programming languages, like Python, never respected
| concurrency in the first place.
| kwhitefoot wrote:
| I didn't have a game engine on my Z80 Nascom-2
| (1979-ish). I had to deal with concurrency using
| interrupts and assembler when I wrote a little maze game
| where the player was pursued by monsters. Until then I
| had only written a few programs in Basic.
|
| And lots of people program Arduinos and similar kit as
| their first attempt at coding now, are you going to tell
| them not to use concurrency?
| dragonwriter wrote:
| Python didn't ignore any of those except pattern matching
| (well, until recently).
|
| It progressively deemphasized some popular FP patterns (largely
| in favor of comprehensions, which have also been adopted in
| many newer functional languages.)
| auc wrote:
| Python 3.10 will have pattern matching
| [deleted]
| [deleted]
| sixhobbits wrote:
| Hey HN! We posted this before when it was in very early stages.
| It's still a work in progress, but the website is live and all
| the chapters are available online or as a PDF download.
|
| I've taught a lot of Python and I think this book (adapted from
| How to Think Like a Computer Scientist") is the best mix of
| practice and theory and is usually what I recommend to people as
| a 'fixed syllabus' when they are overwhelmed by all the options.
| rahimnathwani wrote:
| Section 17.1 says "This program pops up a window which stays
| there until we close it" but I don't see any program listing or
| any link to a program listing.
| sixhobbits wrote:
| Thanks for catching that! There were some manual steps to
| convert it from RST to MD and we are still doing a run
| through to fix everything up (and to make things consistently
| use Replit - the later chapters still reference a local
| environment quite a bit).
|
| I've added that code snippet in now. Feel free to let me know
| if you spot anything else :)
|
| The site also links to the original which is more battle-
| tested at this point [0]
|
| [0] http://www.openbookproject.net/thinkcs/python/english3e/
| smoldesu wrote:
| I was super enthusiastic about this until I saw that you're doing
| it all in Repl. Love it or lump it, you're not going to be
| writing or deploying any practical Python scripts on Repl, and
| it's a bad idea to market this as any more "correct" than just
| interpreting the scripts on your own machine: particularly when
| the latter is almost objectively more educational and useful.
| cutler wrote:
| I would be wary of promoting Repl.it if you're going to include
| Vim users. Vim keybindings exist in per-project Settings but
| don't work. Otherwise, great free books.
| tpoacher wrote:
| > Use the online IDE Replit instead of showing students how to
| set up Python
|
| Not sure why, but this feels very backwards to me.
|
| I mean, I get it. E.g. Overleaf is a much gentler introduction to
| LaTeX than Miktex/texlive ... but still. Feels like you're
| crippling the student in advance by limiting their ability for
| exploration/exploitation.
| rednerrus wrote:
| It seems like understanding how to setup the environment is a
| key to really understanding Python.
| analog31 wrote:
| Unfortunately, that's the case. An issue for Python is that
| there's no _the environment_ , meaning that approaches to
| setting it up vary in accordance to its anticipated use,
| local standards, and even personal preference. When all is
| said and done, the "Python" that I use for scientific
| programming is a different beast than the "Python" that my
| office mate uses for deployment on a cloud based server.
|
| Of course this is a blessing of Python but an obstacle for
| teaching a language to beginners, if you're spending a lot of
| time troubleshooting installations and wondering why a
| program runs on one computer and not another. It may explain
| the staying power of Matlab, which all comes from one place
| and installs the same on everybody's machine.
|
| From talking to people who have learned programming recently,
| almost every course starts with walking the student through a
| specific, prescribed installation and making sure it works.
|
| It suggests a possible opportunity for another book along the
| lines of: _How to install Python_ , which explains a variety
| of scenarios, what they are for, how they work, etc.
|
| One benefit of a web based IDE is that it works for K-12
| students who are on Chromebooks and can't install software.
| When my son brought home his school issued Chromebook, my
| first response was: "Great, let's install Python." He gave me
| a sad look.
| __mharrison__ wrote:
| My compromise (I teach hundreds Python in live classes each
| year) is to use IDLE for my Python fundamentals course.
|
| It is not the best environment, but it (generally ) works in
| Mac/Linux/Win, and it allows them to work on their own
| computer. This sidesteps environments, but also doesn't make
| them dependent on having the internet or other services.
|
| On the flipside I teach an analytics class for my alma mater
| and there we use Colab. Again, sidestepping install completely.
| I justify it as these folks are more interested in leveraging
| the tools of Python (matplotlib, sklearn, pandas) and don't
| necessarily want to be software engineers. For the motivated
| few who want to install locally I give them a guide [0].
|
| 0 - https://www.metasnake.com/blog/pydata-dev.html
| RheingoldRiver wrote:
| If student A spends 1 hour installing Python (with questionable
| success rate) & setting up an environment (with even more
| questionable success rate), and student B spends 1 hour
| actually typing things into replit and getting results, which
| student do you think is more likely to continue with a lesson
| plan?
|
| Which student has learned more about Python?
|
| Which student is better equipped to pursue setting up an
| environment (maybe on another computer) at some point in the
| future?
|
| Setting up environments is the most frustrating, seemingly
| pointless task _ever_ to an absolute beginner. Someone who has
| literally never written a line of code in their life and has 0
| experience troubleshooting anything is extremely likely to get
| 1 step wrong, or worse have one precondition wrong on their
| machine that breaks the tutorial 's steps, and then get stuck
| in an endless sea of non-functioning, useless applications now
| stuck on their hard drive & then become completely
| disillusioned & never start coding.
|
| The lack of setup on the student's part is why previously I
| have always recommended FreeCodeCamp as the single best way to
| learn programming on the internet to an absolute beginner, but
| now that this exists with its replit-based approach (and I know
| about it) I'm gonna take a look at it and potentially start
| recommending it instead.
|
| P.S. how many IDE shortcut keys did you have to customize
| before you were at all comfortable with using them? And this is
| Python, so if we're sending them to VSC instead of Pycharm, imo
| we're doing them a huge disservice*, and Pycharm's default
| keybinds are particularly egregiously beginner-unfriendly.
|
| *IDE wars aside, arguably the real disservice is locking them
| into one before they have enough knowledge to form their own
| opinion
| qayxc wrote:
| > If student A spends 1 hour installing Python (with
| questionable success rate) & setting up an environment (with
| even more questionable success rate), [...]
|
| I hear this a lot, and maybe I'm just too far removed from a
| total beginner's perspective to understand, but what exactly
| is complicated about installing Python?
|
| Windows in particular is as simple as it gets - there's a
| Windows Store App that you can install and that's pretty much
| it.
|
| Call me old-school, but I consider being able to install and
| start a program on the system I use on a daily basis an
| essential skill and a pre-requisite to programming. If (and
| that's one hell of an "if" these days) something goes wrong
| and troubleshooting is required, the necessary "skills"
| (read: google the exact error message, maybe followed by some
| process of elimination) overlap with the skills needed during
| programming so it actually helps, too.
|
| It rubs me all the wrong ways to tell students to sign up
| with a commercial online service for something they can
| experience for free, offline, and without surrendering
| personal data to some corporate entity on the internet.
|
| As far as IDEs and shortcuts go, that's another thing I just
| can't wrap my head around: so there are people who are
| apparently incapable of double-clicking an icon in their
| respective OS's package manager/app store, but at the same
| time they are expected to care about particular key bindings
| and shortcut keys?
|
| I just don't understand this at all. Not to sound like your
| typical geezer, but back in the day a blinking cursor and a
| magazine explaining the most important BASIC commands was all
| you needed to get started. Shortcut keys are the last thing
| beginners should worry about.
|
| Heck, it's perfectly fine to stay on the REPL for a while and
| just use a simple text editor for bigger scripts. Even
| syntax-highlighting can be enabled via plugin in most text
| editors that are even just better than Notepad.exe.
|
| But again, maybe I'm just way to detached from your typical
| absolute beginner to even remotely understand any of these
| issues.
| RheingoldRiver wrote:
| > Windows in particular is as simple as it gets - there's a
| Windows Store App that you can install and that's pretty
| much it.
|
| Ok I haven't installed Python myself this way, but, does it
| set up PATH for you properly? How about pip, does it add
| pip to PATH? Often things will tell you to type `pip
| install` rather than `python -m pip install` so there's a
| potential source of confusion pretty early on too.
|
| (Currently, I tell people to install chocolatey then use
| that to install Python because choco does take care of PATH
| for both Python & pip. If Windows app store Python install
| takes care of all of this maybe I'll try suggesting this
| next time and see how it goes.)
|
| Also, let's suppose you get Python from Windows app store.
| Great, you have installed Python 3.9! You are doing the
| tutorial, just lovely, now in a week you want to make a
| Discord bot! Great first project. Uh oh, RED Discord Bot
| requires Python 3.8 (3.9 introduces breaking changes for
| some of its dependencies). How much more trouble you are
| now in because you have to install two versions of Python
| at the same time! If only you had waited to install any
| version until you were ready to start your first local
| project. (Based on actual events)
|
| As far as IDEs go, well, in Pycharm you are asked, do you
| want to set up a project? Huh? What's a project? (Later on:
| well, you can't just open a file from Windows Explorer, you
| need to open your entire project! Well, isn't THAT
| confusing!) Then you have to answer about a venv. What's a
| venv? Oh, shit, I made the folder in the wrong place, let
| me move it, omg, nothing works anymore, oh, I guess that
| "venv" thing was kinda important to know about after all,
| well, shit...Ok, so again, maybe don't jump all the way to
| Pycharm as your first IDE but then I just have to ask why
| are you using an IDE at all when replit would do just fine?
| Then you're going to have loyalty to a tool that's worse
| than Pycharm and not want to switch once you are ready to
| use the right tool.
|
| > But again, maybe I'm just way to detached from your
| typical absolute beginner to even remotely understand any
| of these issues.
|
| I think this is pretty likely; if you haven't helped a
| friend start from literal scratch in the past year, it's
| pretty hard to realize just how confused people can be. And
| a LOT of people have tried things before and given up in
| frustration because they remembered how painful the setup
| was. So that leaves them with messes on their computers and
| also psychological scars of "oh my god not another setup,
| please not another setup, don't make me do another
| setup...."
|
| Plus, if you have always had someone to ask for help then
| it's hard to appreciate just how painful setups can be when
| you're stuck on your own for them. If something breaks, no
| one's going to fix it for you, it's just broken, and you're
| just alone, and you feel REALLY goddamn stupid because as
| your comment points out, setups seem like they ought to be
| trivial. But they really just never are.
| __mharrison__ wrote:
| The Windows store version of Python sets up PATH for you.
|
| If you need to have multiple versions installed then
| presumably you are sophisticated enough to manage the
| PATHs for those versions/projects.
|
| Setup is a pain, I get it. I try to avoid it if it isn't
| necessary for the courses I'm teaching.
| smoldesu wrote:
| This post is a lot of fearmongering, and I don't really
| understand where it's coming from. Yes, installing Python
| is marginally harder than installing, say, Discord or
| Steam. Why is that an issue? Up-and-coming programmers
| are going to have to face much bigger issues than what
| version of Python their running, and letting them
| interact with it firsthand is _always_ a more educational
| experience than abstracting it away and telling them not
| to worry about it.
|
| > it's pretty hard to realize just how confused people
| can be.
|
| It's good, though! Confusion is a sign that someone is
| confronting something they don't understand, which is an
| opportunity to teach them about what they're doing, or at
| least motivate them to understand it a little better.
|
| I sympathize with people who want to promote a browser-
| based, sandboxed coding experience- I really do. Teaching
| people to code on it is a whole different story. Imagine
| what would happen if we raised a generation of Python
| scriptwriters who couldn't figure out how to install to
| PATH, or taught C without showing people the compiler.
| There's no excuse for not knowing how to operate your
| tools, and learning them first is an absolute must. You
| don't let someone start playing with a rotary saw until
| they know how to use it.
| swagtricker wrote:
| One other point of praise for this approach: being able to run in
| a web browser via Repl.it is a huge win given the combination of
| the rise of tablets, as well as the popularity of locked down
| Windows/Chromebook laptops for students. Many students today and
| more going forward may not have access to a PC/Mac that they
| could easily install Python on (or convince an adult to do it for
| them). Repl.it with the turtle graphics works just dandy on the
| Chrome browser for my 4 year old iPad Air (disclaimer - I'm a
| Repl.it subscriber).
| Aperocky wrote:
| I'm on the fence about this one as it seem to abstract a
| dangerous level of stuff away.
| smoldesu wrote:
| I agree. I used to be a huge fan of Repl, but the limitations
| start to present themselves pretty early on. My advice is
| still the same for people who want to code: go on Ebay and
| buy a used Thinkpad, install Linux on it and write code. By
| step two, most people can self-educate themselves on where to
| go next.
| hardwaresofton wrote:
| Perhaps a bit rude but one of the best guides I've seen as an
| introduction to Python:
|
| https://python.swaroopch.com/
|
| Since I lost my link to this I actually stumbled upon this as
| well -- evidently UMN has a library of open text books:
|
| https://open.umn.edu/opentextbooks
| mdoms wrote:
| I have some friends who are interested in programming but not
| motivated to work through a text book. I got them into Automate
| the Boring Stuff and actually solving real problems has been
| much more motivating for them.
|
| https://automatetheboringstuff.com/2e/
| TheHypnotist wrote:
| This seems great but I find that one of the hardest things for a
| beginner is setting up the environment. A chapter on that would
| be nice for a beginner.
|
| Edit: I guess this would constitute as more of a tutorial of
| _insert IDE here_. But even picking one like VS Code would go
| some distance toward learning the full scope.
| __mharrison__ wrote:
| In my beginning Python book, Illustrated Guide to Python 3, I
| try and make it really easy to just get started with Python. I
| encourage using IDLE. For beginners it is fine. There are no
| other installs to worry about and they can focus on learning
| the language.
| Kinrany wrote:
| Repl.it is great for beginners.
|
| In the long run I'm afraid books are not a good format for
| helping with this. Too many individual differences, and too
| many things change over time.
| cutler wrote:
| "Repl.it is great for beginners". Yes, but not for Vim users
| as the keybindings don't work.
| mdoms wrote:
| Very few absolute beginner programmers are Vim users.
| Freeboots wrote:
| No comment on the content yet, but its refreshing to click
| 'Download' and actually be given the book, rather than begged for
| my email.
| sixhobbits wrote:
| A few people have said exactly that! We will keep it that way
| mjfl wrote:
| "it's refreshing for me to capture the entirety of the value
| given generously at this page, without even the slightest
| effort to give something in return".
|
| I have nothing to do with the authors of this book/page but
| this attitude is why I don't do free software.
| macintux wrote:
| As someone said on the earlier thread: "I'd be happy to pay
| for it, I just don't want to give my email".
| Siira wrote:
| Then why didn't they use a simple email masker? Or a
| throwaway email account.
| smoldesu wrote:
| Because that takes more than one minute, and most
| curmudgeons like me will leave if something doesn't
| present some kind of download link immediately.
| smoldesu wrote:
| >but this attitude is why I don't do free software
|
| What attitude? The selflessness of the developer for giving
| away the software, or the gratefulness of the user who got
| exactly what they wanted? In either case, I struggle to see
| what repels you.
| kleiba wrote:
| Was it Zed Shaw who originated the "Learn X the Y way" pattern?
| dave84 wrote:
| I think Zed riffed on the "Learn X the easy way" pattern that I
| imagine has existed almost as long as books have.
| teach wrote:
| Probably. His "Learn Python the Hard Way" was early and
| influential.
| shanecleveland wrote:
| This had a huge influence on me. I still have projects
| running on web.py that stemmed from it.
| jakereps wrote:
| It's also fairly controversial within the Python dev
| community. I read this title as a jab at that one, because
| it's not recommended to follow a lot of the "Hard Way"
| patterns and practices. It's been quite a few years since I
| was working in Python exclusively, so I can't recall
| specifics to point out.
| kej wrote:
| "Learn X the Easy Way" goes back decades, especially in foreign
| language books. "Learn Python the Hard Way" was deliberately
| inverting that pattern.
| swagtricker wrote:
| This is a great idea, but does need some more hand-holding and
| fine points. For example, chapter 3 goes into turtle graphics.
| Great. However, the book doesn't tell students they need to use
| the Repl.it Python-Turtle repl rather than the standard one
| they'd been using. Also, the 2nd example in chapter 3 attempts to
| set the title in the UI:
|
| wn.title("Hello, Tess!")
|
| This fails in Repl.it's turtle repl environment.
| sixhobbits wrote:
| Definitely! This is the first MVP release of our conversion of
| the original to Replit and we have done less than the bare
| minimum so far. We will be updating it chapter by chapter to
| address these and more! Thanks for the feedback!
| [deleted]
___________________________________________________________________
(page generated 2021-05-13 23:01 UTC)