Live data from Hacker News

Python built-ins worth learning

treyhunner.com

11–20 of 69 posts

Re: Python built-ins worth learning

#11
post #5

> Many Python users rarely create classes. Creating classes isn’t an essential part of Python, though many types of programming require it. Huh. Okay.

It's really true. You can do a lot with data objects (dicts, lists) and stateless functions.

Rich Hickey has some nice talks about why separating the data from the methods is really beneficial.

Re: Python built-ins worth learning

#15

I disagree with only one thing in this article. Frozenset is super useful. You should prefer frozenset over set by default imo. Immutable objects are safer to work with, often easier to work with (frozenset is hashable, you can key a dict with it), and sets come up all the time in a lot of work. You can get by with a sorted list, but sets are nicer and faster.

Ha! That was the thing I was most excited to learn about. I’ve never come across it in any codebases I’ve worked on, but will definitely begin training myself to use it by default over a normal set.

Re: Python built-ins worth learning

#16
post #4

If you are reading this, the orange bar at the bottom 5% of my screen is hugely distracting. Please allow us to close it.

Thanks for noting this. I rarely look at my site on mobile and hadn't noticed how big that widget was. I just spent a few minutes making it less visually obtrusive. I may figure out more ways to improve it later.

Re: Python built-ins worth learning

#17

I disagree with only one thing in this article. Frozenset is super useful. You should prefer frozenset over set by default imo. Immutable objects are safer to work with, often easier to work with (frozenset is hashable, you can key a dict with it), and sets come up all the time in a lot of work. You can get by with a sorted list, but sets are nicer and faster.

Great point. I do agree that those who use sets heavily should probably know about frozenset. :)

I've never very rarely seen these used in production code though. I'm also not as strongly biased toward them because set objects in my own code are often pretty short-lived so their mutability rarely matters.

Re: Python built-ins worth learning

#18
post #5

> Many Python users rarely create classes. Creating classes isn’t an essential part of Python, though many types of programming require it. Huh. Okay.

I spent many years with Visual Basic before learning Python. Some of the earlier versions of VB were object based, meaning that you could use pre-written objects (standard and third party), but you had to buy a special kit to create your own objects.

This was quite useful for those of us who were bewildered by OOP.

When I learned Python, I was comfortable enough with using objects, that I had no problem creating classes.

So I think it's fair to say that creating classes is something that beginning Python programmers can put off.

Since I introduced Python to my workplace, I get to watch some fairly neophyte programmers develop their skills. These are typically engineers doing scientific programming, not commercial software developers. There's a point where I get to say: "You could put that stuff in a class." And later on, "You're creating too many classes." ;-)

Re: Python built-ins worth learning

#19
This article covers a lot of good material and I like the breakdown of categories from essential > maybe you'll look this up some day.

My one minor suggestion would be to cover getattr and related methods sooner. I stumbled across that one pretty early on as I was learning programming and it was a serious "Ah ha!" moment. Dynamic lookups with a sensible default value are useful in countless contexts.

Re: Python built-ins worth learning

#20
post #5

> Many Python users rarely create classes. Creating classes isn’t an essential part of Python, though many types of programming require it. Huh. Okay.

It totally depends on the kind of work you're doing. My first few years with Python I never defined a class. I (and imagine most people) were working on code get from a to b. There's a lot of that kind of work to be had. Only later when I started writing modules and libraries did I need to.
Post reply on HN