Debugging (was Re: Why not allow empty code blocks?)
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Thu Aug 4 05:38:30 EDT 2016
On Thursday 04 August 2016 19:13, BartC wrote:
> On 04/08/2016 04:23, Steven D'Aprano wrote:
>> On Wed, 3 Aug 2016 08:16 pm, BartC wrote:
>
>>> So the idea that remembering 'repeat N' is a cognitive burden, and the
>>> myriad string operations for example are not, is ridiculous.
>>
>> Who says it isn't a cognitive burden? Of course it is.
>>
>> The difference is that most of the string methods carry their own weight in
>> usefulness versus burden, and "repeat N" doesn't (according to the core
>> developers). You have weighed "repeat N" high on the usefulness side and
>
> OK, let's look at some string features.
>
> First, you have string.ascii_uppercase, which is just
> "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
>
> Is that really so indispensable that it has to be built-in to the
> language? Is it that much of a hardship to assign it once and for all to
> some variable?
/facepalm
It *is* assigned once and for all to some variable. It's a variable in the
"string" module.
It is neither a built-in value (like None, True or False) nor a language
feature.
> And 'string.ascii_uppercase' is not that much more concise than just
> writing out the alphabet! In the case of "0123456789", the constant name
> is longer.
The reason for giving constant values a fixed name is not to save keystrokes,
but to have a consistent, readily understandable, self-descriptive name.
If you say:
from string import digits
that's only 26 keystrokes, including a newline. Compared to:
digits = '1234567890'
which is 22 keystrokes. So it costs you four keystrokes over defining it
yourself. Big deal.
> Now you have string str.lower, str.upper, and str.swapcase. Clearly one
> of those first two is redundant, as you can implement str.upper by
> writing str.lower().swapcase() for example.
I've already suggested that swapcase() is not very useful, and that it still
exists only for backwards compatibility. But are you serious about suggesting
that Python should drop str.upper() in favour of having the user write
str.lower().swapcase()?
At least put a wink or a smiley there, so we know you aren't a total idiot.
> Then these miss a trick by not having an optional length parameter, so
> that you can operate on the first N characters.
That's actually a nice feature. I might request it. It's too late for Python
3.6, but maybe 3.7. It would have to take a start and end position, but that's
actually quite clever.
> Then you can dispense with str.capitalise by writing str.upper(1). (Or
> str.lower().upper(1) if the current case is unknown.)
Backwards compatibility would require it stays even if it became redundant.
> (And what about str.reverse()?
What about it? The canonical way to spell "reverse a string" is with a slice:
mystring[::-1]
> (The comments here about the readability
> of Python code, and who is entitled to express an opinion about it, are
> amusing:
> http://stackoverflow.com/questions/931092/reverse-a-string-in-python))
Ah, well, Stackoverflow. What did you expect?
--
Steve
More information about the Python-list
mailing list