osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Scala considering significant indentation like Python


Cholo Lennon writes:

> 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

I am the inventor of multiple ends on the same line. This way, in a
language where all of several nested constructs end with an end - not
going to name the language but it's Julia - instead of

                end
            end
        end
    end
end,

one combines the uninformative lines into one by writing

end end end end end,

and with four-space indentation the ends align neatly with the starts.
Technically, the ends on the remaining line of ends are backwards.