4 ms·
int.bit_count, but str.removesuffix -- consistency has never been a strength of the Python standard library.
by gfaure 4y ago
int.bit_count, but str.removesuffix -- consistency has never been a strength of the Python standard library.
- kzrdude 4y agosimilarly, 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.
- ehsankia 4y agoWhat 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
- rcfox 4y agoPython'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.)
- pansa2 4y ago`bit_count` is a terrible name for a function that returns the number of one-bits. Zero-bits are bits too!
- danwills 4y agoYeah, 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?
- carapace 4y agoThe operation's name is "popcount", there's an asm (i86?) instruction "POPCNT". https://duckduckgo.com/?t=ffcm&q=popcount&ia=web https://duckduckgo.com/?t=ffcm&q=popcount&ia=web