On Sun, Apr 26, 2020 at 4:42 AM Stephen J. Turnbull < turnbull.stephen.fw@u.tsukuba.ac.jp> wrote:
You're missing the topic of the comparison. It is that we could have
removeaffix(source, affix, suffix=True) strip(self, chars, where='both') # where in {both, left, right}
Oh, that's not the point I was making, but it is also good. During the .removeprefix() discussion, several people seriously suggested something like `mystring.lstrip('foo', string=True)` to alter the behavior between removing from a set of characters and removing a specific subsequence. In any case, that was not what won out, which was my point. I agree that a `where=left|right|both` would be the wrong design for similar reasons.
I'm not sure why David compares this to the case of print(), where end and sep are arbitrary strings.
Yeah, OK, that is weaker. I guess I was just thinking of the fact that my sep is almost always either the default space or the empty string. And my end is similarly almost always either newline or space. But of course I *could* use anything else (and occasionally do). Ditto open(), where the mode argument
is not 2-valued, but (text, binary) X (read, write, append, create_no_truncate) X (update, not) X (universal newline, not). Not only that, but there are other 'mode' arguments such as encoding, errors, and closefd.
Oh... I'll stick with the open() example. Even though the mode is this compound string, it's really conceptually separate elements (and the documentation makes this point). Text|Binary is a two-value switch, even though it is encoded as a character of a potentially multi-character string. That slightly cryptic string code is legacy IMO (but it's not going to change). Likewise, `newline` is an actual separate argument that takes a small number of options.
The convention is that rather than a function foo(..., mode) where mode takes values from a "very small" enum, say {bar, baz, default}, it's preferable to have foo, foo_bar, and foo_baz. I'd guess #enum=4 (including default) is about the limit, which is why open has all those enumerated mode arguments: even errors has more than 4 options.
Yeah, I agree. Even if the individual aspects of mode are each few enough that separate functions would make sense, the cross product of their combinations becomes large, and we wouldn't want separate functions even if we were starting today. -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.