Scala considering significant indentation like Python

oliver oliver.schoenborn at gmail.com
Mon May 22 11:21:55 EDT 2017


Any nesting beyond third level should be strong candidate for refactoring.
Soon after you do that, big surprise, refactored block gets better
documented, gets used elsewhere, becomes testable on its own, etc. I.e. if
structure is not obvious from indentation alone, refactoring is the proper
solution, not braces.

Also deeply nested structures tend to involve variables in the deepest
levels that are also used in the outer levels, making the scope of
variables harder to manage (leading to similar bugs as result from use of
global variables).

So languages that do not require braces for code blocks encourage
refactoring, and hence clearer code structure, separation of concerns,
isolation of namespaces, etc.

On Mon, May 22, 2017, 09:31 Cholo Lennon <chololennon at hotmail.com> wrote:

> On 22/05/17 00:53, Steve D'Aprano wrote:
> > The creator of Scala, Martin Odersky, has proposed introducing
> Python-like
> > significant indentation to Scala and getting rid of braces:
> >
> >      I was playing for a while now with ways to make Scala's syntax
> >      indentation-based. I always admired the neatness of Python syntax
> >      and also found that F# has benefited greatly from its optional
> >      indentation-based syntax, so much so that nobody seems to use
> >      the original syntax anymore.
> >
> > https://github.com/lampepfl/dotty/issues/2491
> >
> >
> >
>
>  From the link:
>
> "Impediments
>
> What are the reasons for preferring braces over indentations?
>
> Provide visual clues where constructs end. With pure indentation based
> syntax it is sometimes hard to tell how many levels of indentation are
> terminated at some point... "
>
> I am a huge python fan (but also a C++ and Java fan) and I agree with
> Scala creator, sometimes the readability is complicated. So, more often
> than I would like to, I end up missing the braces :-O
>
>
> --
> Cholo Lennon
> Bs.As.
> ARG
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
Oliver
My StackOverflow contributions
My CodeProject articles
My Github projects
My SourceForget.net projects



More information about the Python-list mailing list