On Fri, 10 Jul 2020 at 12:08, Greg Ewing <greg.ewing@canterbury.ac.nz> 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.
That's a good point - and sufficiently compelling that (if "align else with match" ends up being the syntax) I'd always use "case _" rather than else. Equally, of course, it means that aligning else with match gives users a choice of which indentation they prefer: * Align with cases - use "case _" * Align with match - use "else" I've pretty much convinced myself that whatever happens, I'll ignore else and just use "case _" everywhere (and mandate it in projects I work on, where I have control over style). One thought - what will tools like black do in the "case _ vs else" debate? I can foresee some amusing flamewars if linters and formatters end up preferring one form over the other... Paul