On 10/07/2020 12:33, Greg Ewing wrote:
A thought about the indentation level of a speculated "else" clause...
Some people have argued that "else" should be at the outer level, because that's the way it is in all the existing compound statements.
However, in those statements, all the actual code belonging to the statement is indented to the same level:
if a: .... elif b: .... else: ....
^ | Code all indented to this level
But if we were to indent "else" to the same level as "match", the code under it would be at a different level from the rest.
match a: case 1: .... case 2: .... else: .... ^ ^ | | Code indented to two different levels
This doesn't seem right to me, because all of the cases, including the else, are on the same footing semantically, just as they are in an "if" statement.
I feel all those who aren't directly arguing against it are working off the assumption that it is needed for match and case to have different levels of indentation, but is this really true? Is there anything (bar tradition or other subjective arguments) that speaks in favour of this, especially in light of the fact that having the same indentation level would also solve other problems? A few emails ago I proposed something like this (and I'm probably only the last one to do so amongst many), but if anyone made an argument against it I must have missed it: match: a case 1: ... case 2: ... else: ... (The a on a separate line being arguable.) I think it would look neater, be reminiscent of the if/elif/else syntax we're all familiar with, and solve the issue of where to indent the else.