Sujet : Re: Python (was Re: I did not inhale)
De : bc (at) *nospam* freeuk.com (Bart)
Groupes : comp.unix.shell comp.unix.programmer comp.lang.miscDate : 29. Aug 2024, 11:49:35
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vapjnv$3u1ub$2@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
User-Agent : Mozilla Thunderbird
On 29/08/2024 02:16, Lawrence D'Oliveiro wrote:
On Thu, 29 Aug 2024 00:21:43 +0100, Bart wrote:
On 28/08/2024 23:49, Lawrence D'Oliveiro wrote:
>
On Wed, 28 Aug 2024 20:27:53 +0100, Bart wrote:
>
The main problem isn't in changing the indentation of a block of code;
it is in HAVING to do so because of poor language design.
>
If you think the need for refactoring is something that can be solved
by “language design”, I’d like to hear how.
>
The aim is to not NEED refactoring when you are playing around with
different, short-term bits of code.
“Playing around” is exactly one of those situations where you will need to
do all kinds of things to the code, including refactoring.
Here:
if a == b:
s1
return
s2
s3
that return statement is added temporarily for some reason that is not relevant to the discussion.
Real life code would have much busier statements, and the whole thing would in the middle of lots of other stuff that can include actual return statements.
The problem is that that line doesn't stand out, when later you have to find it to remove it or comment it. It blends into the surrounding code.
Without the constraints imposed by the language, I could just write it as:
if a == b:
s1
RETURN
s2
s3
NOW it stands out! Of course, I could just do:
if a == b:
s1
return # TEMPORARY RETURN
s2
s3
But this is extra effort that shouldn't be necessary, like adding #end comments. I might for example move that line to a different part of the function, but it might use a different indent level.