Live data from Hacker News

Understanding Python through its builtins

sadh.life

21–30 of 180 posts

Re: Understanding Python through its builtins

#21

Are there any good books that deal with writing pythonic code? As well as being focused on more intermediate or advanced features like this? If the book is project focused that's a bonus. Performance trade-offs another bonus.

I can personally recommend Fluent Python (its 2nd edition is about to come out in a couple months) for learning these intermediate/advanced concepts, and Python Cookbook for code examples using many of these features. I don't know any books for projects per-se, maybe HN will know!

[deleted]

Re: Understanding Python through its builtins

#22

Are there any good books that deal with writing pythonic code? As well as being focused on more intermediate or advanced features like this? If the book is project focused that's a bonus. Performance trade-offs another bonus.

Searching python on HackerNews readings (a site I built): https://hacker-recommended-books.vercel.app/category/0/all-t... The results include Fluent Python recommended by tusharsadhwani

Re: Understanding Python through its builtins

#23
post #6
post #4

Earlier quoted context omitted.

Huh I never even thought we would need to create copy of an object when adding new item to it (like a new item to list for example). Is there any drawback on doing that in standard pythonic way? I actually learned to program using Python and it was my first language. Since then I only used JS. In both I like using functions a lot and rarely dabble in OOP since it is more conveniet to me.

You often lose performance in traditional imperative languages when aiming for persistence. When you have immutability guarantees (like in many functional programming languages like ML or Haskell) you can avoid making copies by sharing the parts of the data structure that don't change. If this kind of thing interests you, you should check out Chris Okasaki's book "Purely Functional Data Structures".

"avoid making copies" dors not always equal "performance". Depending on your access patterns, having the data colocated can be more important.

But immutability sure is nice when you can have it.

Re: Understanding Python through its builtins

#25

Are there any good books that deal with writing pythonic code? As well as being focused on more intermediate or advanced features like this? If the book is project focused that's a bonus. Performance trade-offs another bonus.

In a way, learning Python is harder for people experienced with another language because so much of the content you find is for first-time programmers.

That said, I think I had good luck with Writing Idiomatic Python.

Re: Understanding Python through its builtins

#26
post #16
post #12

Earlier quoted context omitted.

>Python is really consistent when it comes to its behaviour True, though you end up with things like: ' '.join(thelist) Instead of thelist.join(' ') Because of the somewhat aggressive mantra to be consistent.

But that's good. Because a string just needs to know aboit interable to perform that operation whereas every iterable would need to implement it's own join if you had it the other way around.

[deleted]

Re: Understanding Python through its builtins

#27
post #24

This is such a good write up for someone like myself still trying to get their head around Python. I can appreciate this must have taken considerable effort, It reads really well. Thank you!

I was concerned if my writing style will click with people, this is good to know :)

Re: Understanding Python through its builtins

#28
In addition to this, I highly recommend just reading the codebase. I haven't written C since college and it's remarkably readable.

I once tried to catalogue all the stdlib operations which release the GIL, meaning if you use only those (well, only those "heavy" bits, you can still use other small blocking glue bits), you can do "real" multithreading.

It was a fun exercise!

Re: Understanding Python through its builtins

#29

Are there any good books that deal with writing pythonic code? As well as being focused on more intermediate or advanced features like this? If the book is project focused that's a bonus. Performance trade-offs another bonus.

Searching python on HackerNews readings (a site I built): https://hacker-recommended-books.vercel.app/category/0/all-t... The results include Fluent Python recommended by tusharsadhwani

Fluent Python is definitely a good book, I knew a whole bunch of the stuff in this article because of it. I only got to Chapter 9, but it legitimately made my Python much, much better.

Re: Understanding Python through its builtins

#30
post #28

In addition to this, I highly recommend just reading the codebase. I haven't written C since college and it's remarkably readable. I once tried to catalogue all the stdlib operations which release the GIL, meaning if you use only those (well, only those "heavy" bits, you can still use other small blocking glue bits), you can do "real" multithreading. It was a fun exercise!

And it helps much more in the actual job of writing software than in say, practicing coding puzzles
Post reply on HN