Why Julia is not indentation-based like Python?
Asked Answered
P

2

16

I really like the indentation-based syntax of Python; it makes code much more terse.

Is there a reason why Julia was not chosen to be indentation-based as well?

Please note that my intention is solely to learn about the motives that Julia developers had behind this decision; whether we agree or not with those motives is another discussion. I do not intend to start a never-ending discussion.

Photochromy answered 12/2, 2016 at 12:1 Comment(3)
Slightly troll-ish question. Escaping indentation based syntax is perhaps one of Julia's raison d'être.Understructure
@user3580870 I do not mean to start a dicussion. My question is about what were the motives behind this design decision. Whether we agree or not with those motives is another discussion.Photochromy
@user3580870 I think this is a good question.Simply
D
33

See this post on julia-users: https://groups.google.com/d/topic/julia-users/lOmwPvOKc-o/discussion

From Stefan Karpinski

It's a matter of taste – and the fact that we wanted Julia to feel familiar in particular to Matlab users (and to a lesser extent Ruby users). I personally don't like significant indentation. It gets really awkward and fiddly when you're trying to cut and paste into a terminal or into an editor. I've seen a significant number of live Python demos flounder as the presenter struggled with indentation issues. It feels to me like Python programs trail off into space with never-ending scopes. Jeff and Viral both happen to feel similarly, so Julia ended up looking more like Matlab than like Python.

Doer answered 12/2, 2016 at 13:34 Comment(1)
Although that link is helpful, I think you need to provide a summary for this to be a complete answer. Adding a bullet-list outlining some of the key motivations would be good. (I personally like the points about auto-indenting and macros/meta-programming.)Forethoughtful
D
0

It was the taste of the developers (more matlab orientated). That is unfortunate for python users, who will miss more nice feature of python. See also https://groups.google.com/g/julia-users/c/itZDMNEoIW0/m/V-2YYpJdBmwJ

Deflect answered 13/1, 2021 at 0:17 Comment(2)
note that the choice to use end makes editing in the repl much easier. Julia knows that if you don't have an end you aren't writing your function. In python by contrast, the repl can't know if you are done writing your function.Vickivickie
In the end I have come to appreciate the fact that Julia is not indentation-based, more and more.Photochromy

© 2022 - 2024 — McMap. All rights reserved.