Debugging (was Re: Why not allow empty code blocks?)

BartC bc at freeuk.com
Thu Aug 4 05:13:58 EDT 2016


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?

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.

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.

Then these miss a trick by not having an optional length parameter, so 
that you can operate on the first N characters.

Then you can dispense with str.capitalise by writing str.upper(1). (Or 
str.lower().upper(1) if the current case is unknown.)

(And what about str.reverse()? (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))


Compare all that (and I'm sure there's tons more) with, for example, 
just leaving out the 'i in' in 'for range(N):')

-- 
Bartc



More information about the Python-list mailing list