(评论)
(comments)

原始链接: https://news.ycombinator.com/item?id=39392881

我不会说“只雇用聪明的西方人”,因为这根本不是事实。 然而,在主要位于城市地区的一些行业或公司中,受过教育的个人可能有更多的机会,他们拥有通常通过北美和欧洲大学主要以英语提供的高等教育课程获得的特定技能。 话虽这么说,世界各地肯定有来自不同背景的才华横溢的专业人士,他们在技术内外各自的领域表现出色。 最终取决于地点、行业、公司文化等因素。

相关文章

原文
Hacker News new | past | comments | ask | show | jobs | submit login
Think Python, 3rd Edition (allendowney.github.io)
478 points by beefman 1 day ago | hide | past | favorite | 110 comments










So excited to see this coming! When we used Jupyter Notebooks to publish Practical Deep Learning for Coders, we discussed with Allen the idea of doing the same for some of his books.

Now it's actually happening. :D Even better, he's taken it further by adding cool tools such as a Jupyter-based turtle that shows inline graphics in the notebooks. I strongly suspect this will turn out to be the best way to learn Python programming when it's released.

Oh and I just remembered, we even showed a proof-of-concept of converting some of the 2nd edition of this book into nbdev notebooks: https://github.com/fastai/nbdev_cards/blob/master/01_deck.ip... . That notebook is rendered as this HTML: https://fastai.github.io/nbdev_cards/deck.html



I am proud of you!

I loved Think Bayes and Think Stats, but it felt a bit off when everyone else were using notebooks.

When I learn a new language with e.g. AdventOfCode, my first task is building a jupyter image for it.



Having code you can hide like this looks great foe documentation, I've been looking for something like this for a while.


Think Python 2e changed the trajectory of my life. I took a single Java class and hated it so much I gave up on programming. A few years later as a network engineer I had a problem that seemed like it could be scripted and ended up picking up Think Python and fell in love with the language and programming in general.


Just as an counterexample, I started with bash/Perl, moved to Python and really liked it and then started getting issues due to dynamic typing. Around that time, Java was chosen to be the main language for our team and once I saw the benefits of static typing, there was no looking back. Since then Python has come a long way with optional typing support and IDEs to help enforce it but by now I am forever biased in favor of statically typed languages. I still enjoy Python for writing utility scripts because it is so much more polished compared to just using bash (which has its own place obviously) - but if I have the option of choosing a language for a full fledged application, I would prefer Java/Scala etc (Rust is great but the learning curve is way too steep for most mortals).

I do admit that I haven't had the first-hand experience of optional typing in Python supported by something like PyCharm so it is possible that the tooling has brought the experience to be comparable to working with a statically typed language. If someone has used IntelliJ community edition with Python typing-enforcement turned-on, please share your experience.



This is just the sort of thing I needed to read.

I am considering changing the trajectory of my own life, towards a more community/maker/teacher role, and I have a freelance/small business idea about teaching but I need sort of "soft syllabus" materials.

I am learning Python myself, having just never had a need for it in all of my professional web development life (I've written apps in just about every other web-focussed programming language, including Perl and Ruby).

It looks like the right language to teach general concepts in, and having a book I can draw from will help.



Think Python is also just a really great book, even for people who don't want to stick with Python long term.


Python is challenging as a production language, given its tooling inconsistencies, but it’s a great pseudocode language.


Similar for me - I had learned some Java, Matlab, C, Perl here and there but it wasn’t until Think Python 2e that I was gripped and from there read many other books and changed my career to software.


What other books did you read that you would recommend?


I enjoyed “Data Structures and Algorithms in Python”!


Couldn't this result be more attributable to Python itself than the book?


Maybe, but I think the book really was different from any book I had read before. Most books teach the language, but Think Python showed me some of the why, what each data structure might be used for, it would quickly dip into some interesting implementation details to give me a more solid foundation and then zoom out and give me perspective on why something is useful and related software writing skills and tips. It was thorough, but also concise, and the exercises were engaging, so I found myself for the first time really getting sucked into the zone with the problems and time was flying by. This hadn’t happened to me with Java or Perl.


In the abstract, yes. But I also know that Think Python is a great book.

(I came across Think Python when I was trying to help other people learn how to program. So I did not learn programming from Think Python, and Python is also not my favourite language. (It's also not my least favourite language, either. Far from it.))



Think Python and the other books in the Think X series are more about how to think like a programmer in X.

It's not just a book about a language, but an introduction into the basics of solving problems as a programmer.



Exactly!


Same here. I moved cities and was looking for a job... I printed a copy of this book and started going through the chapters... This book made me into a software engineer :)


Think Python helped me finally understand OOP for the first time, after a C++ class, a Java class, etc.


That must have been Calendar.class


Love Think Python, I have recommended it to so many learners: it balances the various concerns of a new programmer book really well. Allen Downey has a bunch of other books with somewhat similar approaches too https://greenteapress.com/wp/ -- some I do think he might have gone too far in the low-rigor side, but all the ones I've reviewed have been pretty good.

(I was sharing a table at a conference with Allen some time ago and told him how many times I'd recommended or bought people his books, and I think he thought I was bullshitting him.)



Apologies for changing the subject, but aside from real world experience (which I have and am getting at work), is there a resource of similar quality for more intermediate/advanced Python programmers? I always feel like there's a big chunk of the language or stdlib I do not know.


I learned Python starting with 1.5.2 from the official documentation and think it's a good resource.

https://docs.python.org/3/tutorial/index.html

https://docs.python.org/3/library/index.html

Whenever a new version is released, I read its What's New documentation.

Beyond that, I like to read source code, both for the stdlib and popular third-party packages. This advice generally applies when I'm learning any new language or re-familiarizing myself with one, not just Python.



I really enjoyed Fluent Python a while back as an intermediate book.

Python official docs are not completely horrible, but compared to most other popular languages (Kotlin, Scala, Rust, Go at least), the Python official docs are kind of meh.

I suppose Python docs beat C and C++ which do not have official docs besides the spec. (not counting K&R and Bjarne's books).

Also I guess Javascript does not have official docs (ie MDN is not official)



I enjoyed Effective Python. It's a "tips" style book with a good handful of recommendations with use cases and applications.


Fluent Python is good book at that level, and works as a good reference book while working too.


I have bought this book for every friend learning python for work purposes, really fleshes a lot out that's not taught implicitly. The data model stuff is really useful.


I like https://effectivepython.com/

Also just reading Norvig’s annual Advent of Code implementations usually provides some insight on how to write elegant and concise Python code.



Looks like there's a new edition coming in March. https://www.amazon.com/Effective-Python-Specific-Software-De...


It’s a bit older, but I learned a lot from “Writing idiomatic Python”. Honorable mention to “the little book of Python antipatterns” as well.




+1 for Fluent Python. See also:

* Serious Python (https://nostarch.com/seriouspython) — deployment, scalability, testing, and more

* Practices of the Python Pro (https://www.manning.com/books/practices-of-the-python-pro) — learn to design professional-level, clean, easily maintainable software at scale, includes examples for software development best practices

* Intuitive Python (https://pragprog.com/titles/dmpython/intuitive-python/) — productive development for projects that last

* Advanced Python Mastery (https://github.com/dabeaz-course/python-mastery) — exercise-driven course on Advanced Python Programming that was battle-tested several hundred times on the corporate-training circuit for more than a decade



Fluent Python and Effective Python are good books. The former is huge and is really multiple books in one.


Python Modules of the Week (PYMOTW). Great resource to learn the stdlib.

https://pymotw.com/3/



Reading the docs proactively (not just when you need something).


Humble Bundle had some nice collections on Python for many uses. For in general, I remember that Serious Python and Automate the Boring Stuff with Python were both good.


The author also blogs his latest Python projects (mostly Bayesian data analysis) on https://www.allendowney.com/blog/ , which I have really enjoyed.


What are some books for mid to advanced programming in Python? I already know Puthon and programming in general but want to improve my Python skills.

I know only Fluent Python which I'm currently reading, and CPython Internals.



You might want to consider books that show application of techniques in real world practical code.

For example, Effective Pandas 2 illustrates common patterns for dealing with tabular data. Along the way, it uses comprehensions, lambdas, unpacking, etc. Shows how to use pytest to refactor. Leverage visualization to understand data.

(Disclaimer: I'm the author)



`Fluent Python` is more than enough; the rest of the language features you will understand them by reading the official reference manual.


You could also look into more general algorithm and data structure books, or into design books.

https://www.redblobgames.com/ has lots of really nifty articles, too.



You might want to check out Exercises in Programming Style (2nd Edition) by Cristina Videira Lopes.

It's a little known book that explores different ways of solving the same problem under different constraints.



I mean, the docs? And the source code?

At a certain point of expertise, everything after basic journeyman familiarity, there's nothing left but to read code and write code.



Related:

Think Python 2e - https://news.ycombinator.com/item?id=35421096 - April 2023 (30 comments)

Think Python: How to Think Like a Computer Scientist - https://news.ycombinator.com/item?id=1586000 - Aug 2010 (9 comments)



What luck! I just started mentoring someone in Python, and I am a huge fan of Downey. Truly an outstanding educator and renaissance man.

Will definitely keep my eye on this.



I love these books … in my case Think Perl6 (now Think Raku) was a real eye opener. A quick scan of the new Python 3rd edition looks like it is quite dumbed down - which is probably appropriate for Python.

I highly recommend the intro to Functional Programming in Raku (chapter 14). https://greenteapress.com/wp/think-perl-6/



Cool, I didn't know about this book! I enjoyed Think Python, but this book surprises me. I'd think there are very few people learning Perl / Raku as their first language nowadays, so a book targeting more experienced programmers seems like it would make a lot more sense.


At one point I started writing a book about Raku for Perl programmers.

For various reasons, I did not finish that: but what did got written, wound up as a 24-part blog series on dev.to: https://dev.to/lizmat/series/24075



What do you mean that TPe3 is "dumbed down"? I didn't notice anything appreciably reduced in the content yet but then again I haven't gone through and compared both editions, so I was interested in your comment.


How does one do proper concurrency in Python? As in separate "processes" running with encapsulation, fault tolerance, etc. For example, how does one bundle up a TCP client in a "process" such that the process handles failed connections, broken connections, retrieving data at periodic intervals (relatively fast), receiving "messages" from other "processes", etc.?

There's Ray, Pyro, Pykka, Celery, multiprocessing, asyncio, threads, Qt, and more, but all of them have issues. And a lot of it boils down to the GIL, although "processes" that are doing I/O such as TCP and other network communication should ideally reduce the GIL effect, to my understanding (is that right?).

From what I can tell, it's basically one of the worst language choices for systems of this nature, but I am trying to figure out how to do it because I need to.



If you are I/O bound then asyncio or good old fashioned gevent will do great. If you are CPU bound, then use multiprocessing. If you need to accept "jobs" from elsewhere, use RabbitMQ (with or without Celery). If you have mixed CPU/IO workload that fits the worker pattern, then you would do all 3. At the top level you have a RabbitMQ consumer, fetching jobs from a remote queue and then putting these into a multiprocessing queue processed by N=~cpucount processes. And each of these use asyncio/gevent to do their work.


So do you recommend a single Python process running asyncio or multiprocessing or both? Or do people normally split these things amongst several Python processes?

My understanding is that multiprocessing creates multiple interpreters but that it still comes across some GIL issues if all under the same Python process.

I am in general quite comfortable with the actor model, and I would ideally use Erlang/Elixir here, but I can't for various reasons.



Why some people are extremely averse to RabbitMQ?

I saw that at one company having RabbitMQ / Celery setup - every time a new software engineer comes in, they complain about RabbitMQ and ask why would company use it. The infrastructure was running like this without hiccups for years. At one point company has let go of many experienced engineers and this time one developer found some issue with the code and blamed it on rabbit as it was locking the queue. There were no more senior developers to contest it, so he convinced manager to swap it out for Redis. He took about two months to rewrite it. Surprise, the same issue existed on Redis. The Redis solution works fine, but has its own limitations...



Use asyncio. Bind to a socket, set blocking False, then asyncio.run(on_new_connection(sock)).

Inside that coroutine get the loop and await loop.sock_accept(sock)

And then asyncio.create_task(on_connection_data(connection)).

The only gotcha is you need to keep a reference to that task so it doesn't get garbage collected.



Get garbage collected by what? Doesn’t Python use reference counting?


The reference implementation (CPython) does use reference counting, but that is not its only approach to garbage collection.

"The default build implementation is a generational collector. The free-threaded build is non-generational; each collection scans the entire heap."

https://devguide.python.org/internals/garbage-collector/

https://docs.python.org/3/library/gc.html

(And as someone else pointed out, asyncio's event loop keeps only weak references to tasks, so the GC implementation doesn't really matter here.)



asyncio doesn't store strong references to tasks. It is your responsibility to keep the ref: https://docs.python.org/3/library/asyncio-task.html#asyncio....

Consider organizing the code using TaskGroup.



Python has a GC.


This talk on concurrency in Python by Ray Hettinger is quite good: https://www.youtube.com/watch?v=9zinZmE3Ogk


Something something libuv?


Can you give an example of what you consider a good solution in a different language? That will help us see exactly what you're looking for and how/whether it might be achieved in Python.


Erlang and Elixir. :)


Well RabbitMQ is built in Erlang so there you go :)


But RabbitMQ is just a messaging bus, isn't it? That doesn't handle the processes (operating system processes or virtual processes) actually processing the messages and those processes handling fault-tolerance for the things they're connected to.


That is correct. Honestly I’m not sure this is a good use case for Python but it’s definitely possible. I’ve used the RabbitMQ + gevent + multiprocessing pattern in the past and it works but I find the code extremely hard to reason about. If I were doing it again from scratch I’d probably choose another language with better concurrency primitives.


> Honestly I’m not sure this is a good use case for Python but it’s definitely possible

It definitely isn't, but this is a new role with a rushed timeline in a place dominated by Python.

> and it works but I find the code extremely hard to reason about

This is also a major concern of mine.



Rather than handling the multiprocessing and message passing yourself it would be much easier to use celery + gevent and let celery do the work of spinning up processes for executing the tasks.

It may feel limiting but my advice would be to keep all the celery job queue stuff isolated from your server, especially if you are using an async web framework. Have your web server just put all the jobs in the celery queue and let it handle executing them, regardless of whether they’re cpu or io-bound. If you try to optimize too much by doing something like leaning on celery for cpu-bound tasks but letting your web server handle the io-bound ones you’re going to be in for a world of hurt when it comes to both debugging and enforcing the order of execution. Celery has its warts but you’ll at least know where in the system your problem is and have reasonably good control over the pipeline.



Can Celery help handle state internal to the workers?

What about using Pkykka alongside Pyro such that each Pyro remote object is actually a Pykka actor? Such that Pyro allows splitting workers across separate Python OS processes and the "messaging" while Pykka handles the internal state.



Could you give an example of state internal to the worker?


Similar to how one can pass around state inside an OTP GenServer in Erlang.

In Python, it could be a class managing a session type of object, like a TCP socket connection, or managing some piece of hardware that is doing something independently of the other parts of the system, or a database writer, etc.



Oh sure, if I'm understanding you correctly. It's been a few years since I've wrenched on such code, but IIRC, you can pass any seralizable object you want to the function being executed. We used to pass around an in-memory class object, no problem. The tricky part was control flow, but that wasn't celery's problem.


This book ALSO changed my life when I was first learning programming!! Not so much in terms of a pivot but of the way the book was written itself and how some concepts all of a sudden just made sense as a total freshman. Now, ~10-15 years later, seeing this third edition is such a nostalgia and I can't recommend this book enough!!!


I particularly enjoyed this passage from an older edition of Think Java: https://files.catbox.moe/v1vgdc.jpg

Also neat:

> What happened next is the cool part. Jeff Elkner, a high school teacher in Virginia, adopted my book [Think Java] and translated it into Python. He sent me a copy of his translation, and I had the unusual experience of learning Python by reading my own book.



This book gets overlooked in favor of other ones such as Python Crash Course but I really enjoyed reading through Think Python 2e and will read through this version as well. Check out the rest of his books on Green Tea Press.


I also like PCC. What do you think the pros and cons are of PCC v. TP3e? They are really two different types of books in terms of pedagogy.


Python Crash Course teaches Python while Think Python teachers computer science using Python. You are right that they are two different books but people recommend Python Crash Course for beginners when Think Python is a much better recommendation for them in opinion. If you just need to learn Python then PCC is a great book.


Tangential, is there a book to learn typing? I feel I need a hefty book to learn typing. Don't mind if you recommend a Typescript book or other language with similar concepts.


You mean types, right? Typing is what you do on a keyboard.

If you want to understand type systems, Types and Programming Languages (https://www.cis.upenn.edu/~bcpierce/tapl/) is the book most people start with. If that is too advanced for you, PLAI (https://www.plai.org/) is a gentle introduction to programming language theory which includes type systems.





Those books are great; though I'm not sure whether they are good for a beginner? Getting your feet wet by programming in a few reasonably typed languages might be better, before you tackle TAPL?

(By 'reasonably typed' I mean something like Haskell, OCaml, even TypeScript or Facebook's hack. But not Go, C++ or Java.)



If you want something JavaScript-ish with strong type inference, take a look at ReScript (https://rescript-lang.org/)


I can recommend Total Typescript by Matt Pocock, a course and a collection of tutorials. He is writing a book in public at [0] as well.

A bit more advanced, and geared towards library authors, is Type-level Typescript.[1]

[0]: https://github.com/total-typescript/total-typescript-book

[1]: https://type-level-typescript.com/



Not a book, but this might help:

"Python Type Challenges" (https://github.com/laike9m/Python-Type-Challenges) — Master Python typing (type hints) with interactive online exercises



This is an odd question to read. The first programming language I learned* was C and types were so fundamental that you HAD to learn them if you were going to do anything at all.

So now I wonder, do people really spend so much time in weakly typed languages that types seems to be a special concept? Or is there something about types that has gotten so complex that its worthy of extra study?

*I did do some BASIC as a middle schooler but it didn't stick. C did.



https://www.cis.upenn.edu/~bcpierce/tapl/

This is a comprehensive resource that I use as a reference. Happy reading!





That is a big topic. Learning typing in Go will be easier than Typescript which is orders more sophisticated. In Typescript you can solve Sudoku in the type system! Then there is the theory of type systems. But if it is the day to day just use it, it will make sense. You are just describing what the type of something will be in code rather than let it be figured out at runtime.


Programming with types by Vlad Riscutia fits your bill exactly.

Examples in typescript (so syntax should be familiar compared to e.g OCaml) and teaches you how to model a domain in types and how to think in terms of a type system, instead of diving into the details of how to implement one.



Haskell might be a fun if indirect way to learn more about a type system. It’s a neat middle between academic typing systems and a language you can do real stuff with.

Typescript might be nice because of how it’s a gradual typing system, just try and do a bit more and more with it as you go.



I learned it through Domain Modeling Made Functional (it uses F# though which looks the same as Ocaml).


This is the book that got me started with programming, so I'm grateful to Allen for it.


I love the Jupyter-/Colab-approach and would like to join the journey... and support the project by buying the book (although I don´t need it to follow the Colab?). But without subscribing to the OReilly-learning platform it seems that buying it on amazon is the only option, right ?


It's a pre-order even on Amazon. The publication date for the book isn't until later in the year (at least for the edition available in the UK, which will probably be the same):

https://www.whsmith.co.uk/products/think-python-how-to-think...

https://blackwells.co.uk/bookshop/product/Think-Python-by-Al...

(Blackwells think September, incidentally, whereas WHS think the end of July)

Amazon just list books way, way earlier in pre-order than a lot of places.



Green Tea Press (by Prof. Downey) has a donate button. That's probably a more efficient means of supporting the project than buying the book, considering all the middlemen.


Oh my ..., was skipping too fast through the page and didn´t see this, and also didn´t realize what he exactly is doing with his Textbook Manifesto etc. Ok, the Paypal-Link is a no-brainer for me now. Thanks for pointing out the obvious.


I use the 2nd edition when I teach intro to programming. The students uniformly love this book and prefer it over any university provided material.


I had read the second edition when I was still relatively new to Python. I even spent a few weeks trying to translate the book to Ruby. Found it a great experience, especially the friendly prose and excellent exercises.


What is a good book for learning Python when you already now some/many other languages?


Just follow the tutorial (yes, really) https://docs.python.org/3/tutorial/index.html


It's what I started with, but honestly it's not great. It also heavily overemphasizes the interactive interpreter


REPL is kind of the point: did you try to type and run any of the examples in the tutorial? Just skimming it would be less useful (for the very basics).

If you already know everything in the tutorial, then try a project in Python that you did previously (familiar project, new language—Python).



Probably Python Crash Course.


Does anyone know how to report issues with the first chapter? I don't see a way to leave feedback.




Thanks!


“If you have comments, corrections or suggestions, please send me email at feedback{at}thinkpython{dot}com.“


This has been a great resource - I love this book! For the last 5 years, I've taught an intro to programming class at the college level and I always recommend that my students augment their resources with this book.

Glad to see it evolving!





Is it really so difficult to learn loops and objects? It’s always been syntax and not knowing how to use library that tripped me up.


Hey genuine question,

Why would anyone bother with learning anymore? When is learning enough to get started?

How will someone get started with work? What qualifies someone to start a new position?

Pretty sure only smart people will be hired for the roles.

No matter what I do, I am forever unqualified, even from junior roles.

1. Have post grad degree

2. Have internships

3. Have only part time or short tenure roles.

But can't get into any industrial role. Why?

Means, I die? What qualifies for a job?

Well one option is to go back to shithole country I came from and just stay there earning pennies. With the money I make there affording a new mac will take 2 years salary. So that is the kind of shithole I am talking about.

Seriously, why?



>Pretty sure only smart western people will be hired for the roles.

Everywhere I've ever worked in tech, in my 20 year career, has had people from all backgrounds.







Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact



Search:
联系我们 contact @ memedata.com