Hacker News new | past | comments | ask | show | jobs | submit login

int.bit_count, but str.removesuffix -- consistency has never been a strength of the Python standard library.



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.)


`bit_count` is a terrible name for a function that returns the number of one-bits. Zero-bits are bits too!


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?


The operation's name is "popcount", there's an asm (i86?) instruction "POPCNT".

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


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


I think the problem is that the first separates words by underscore and the second doesn’t


Well count could be a verb here. And one has an underscore while the other smashes two words together.


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.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: