News for hackers. Stuff that matters.
Re:Python Standard Library changes in recent years by gfaure on Friday May 20, 2022 @11:15PM (#31454965)
int.bit_count, but str.removesuffix -- consistency has never been a strength of the Python standard library.
Re:Python Standard Library changes in recent years by rcfox on Saturday May 21, 2022 @01:23AM (#31455454)
Python's style guide prefers words separated by underscores, but makes an exception to match the prevailing style of the module. `removesuffix` is consistent with the naming style of the rest of the `str` methods. `str` is such a fundamental class that it likely predates the current style guide. (All of the `int` named methods seem to be new to Python 3.)
Re:Python Standard Library changes in recent years by pansa2 on Saturday May 21, 2022 @04:56AM (#31456358)
`bit_count` is a terrible name for a function that returns the number of one-bits. Zero-bits are bits too!
Re:Python Standard Library changes in recent years by danwills on Saturday May 21, 2022 @08:48AM (#31457389)
Yeah, good point! I hadn't thought about that until you mentioned it but totally agree. I'd suggest something like `num_enabled_bits` or `enabled_bits_count` might have made things a bit clearer?
Re:Python Standard Library changes in recent years by carapace on Saturday May 21, 2022 @10:44AM (#31458336)
The operation's name is "popcount", there's an asm (i86?) instruction "POPCNT".

https://duckduckgo.com/?t=ffcm&q=popcount&ia=web

Re:Python Standard Library changes in recent years by ehsankia on Saturday May 21, 2022 @12:55AM (#31455334)
What do you mean? That one's a verb and the other isn't? I think it's fine here. The latter returns a modified version of the string, whereas the former is more like a property of the int, like it's "length", although Python also doesn't have .length so I guess that's a bad example. Think of it like datetime.year vs datetime.replace
Re:Python Standard Library changes in recent years by zodiac on Saturday May 21, 2022 @01:08AM (#31455406)
I think the problem is that the first separates words by underscore and the second doesn’t
Re:Python Standard Library changes in recent years by sp332 on Saturday May 21, 2022 @01:07AM (#31455401)
Well count could be a verb here. And one has an underscore while the other smashes two words together.
Re:Python Standard Library changes in recent years by kzrdude on Friday May 20, 2022 @11:22PM (#31454985)
similarly, I was just looking at functools.cached_property.. In the usual style of Python, it's a smart special case but not the same as the composition of @functools.cache and @property. Maybe it should have had a different name, for that reason, and the issue would be less prominent.