Hello,
On Sat, 11 Jul 2020 22:49:09 +1200
Greg Ewing <[email protected]> wrote:
[]
> For the most part, Python indentation follows what people
> would naturally do even if they didn't have to. So I think it's
> worth looking at what people typically do in other languages
> that don't have mandatory indentation.
>
> Taking C, for example, switch statements are almost always
> written like this:
>
> switch (x) {
> case 1:
> ...
> case 2:
> ...
> default:
> ...
> }
>
> I've rarely if ever seen one written like this:
>
> switch (x) {
> case 1:
> ...
> case 2:
> ...
> default:
> ...
> }
Indeed, that's unheard of (outside of random pupil dirtcode).
Actually, the whole argument in PEP 622 regarding "else:", that its
placement is ambiguous sounds like a rather artificial write-off.
Individual "case"'s are aligned together, but suddenly, it's unclear
how to align the default case, introduced by "else"? Who in good faith
would align it with "match"?
> or like this:
>
> switch (x) {
> case 1:
> ...
> case 2:
> ...
> default:
> ...
> }
Oh really, you never saw that? Well, they say that any programmer
should eyeball the source code of the most popular open-source OS at
least once:
https://elixir.bootlin.com/linux/latest/source/kernel/sys.c#L2144
And a lot of projects follow the Linux codestyle, because it's
familiar to many people and offers ready/easy to use infrastructure for
code style control.
> This suggests to me that most people think of the cases as being
> subordinate to the switch, and the default being on the same level
> as the other cases.
And to me it suggests that well established projects, which have
thought out it all, aren't keen to use more indentation than really
needed.
> --
> Greg
[]
--
Best regards,
Paul mailto:[email protected]
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/YGZMM53MPLRETNBYERVI3APR7FM26EC2/
Code of Conduct: http://python.org/psf/codeofconduct/