i find it really cramps my code formatting style to not permit colon-defined ranges across multiple lines. and to get around the prohibition requires adding extra parens or defining otherwise needless temporary variables.
disallowed in https://github.com/JuliaLang/julia/issues/4701 because it caused a pythonista problems. can we please consider reverting?
a range has two or three arguments that naturally avail themselves to a line of their own. much more readable that way in many cases. i often want to write:
variable1 = some_really_long_start_expression :
another_long_expression_for_the_step :
and_lastly_yet_another_expression_for_stop
perfectly readable, right? much more ugly though if i have to:
foo1 = some_really_long_start_expression
foo2 = another_long_expression_for_the_step
foo3 = and_lastly_yet_another_expression_for_stop
variable1 = foo1 : foo2 : foo3
## or, use the lispy variant:
variable1 = some_really_long_start_expression : (
another_long_expression_for_the_step ) : (
and_lastly_yet_another_expression_for_stop )
(:)(some_really_long_start_expression,
another_long_expression_for_the_step,
and_lastly_yet_another_expression_for_stop)
heh.
ah yes, another quirky alternative. had thought of that too and forgot to put it here. i remember the day colon
was deprecated, but can't remember why. can someone point me to the discussion?
my general thoughts with this issue and with https://github.com/JuliaLang/julia/issues/35073 are that we shouldn't be beholden to the past.
as it stands now, for kids growing up learning julia as their very first language, we have to teach them that no, you can't do it this way because there used to be / is this other language that did/does it this way, or for which doing it this way caused problems, and so yea we decided to perpetuate this standard despite how ugly it is.
for kids growing up learning julia as their very first language, we have to teach them that no, you can't do it this way because there used to be / is this other language that did/does it this way, or for which doing it this way caused problems, and so yea we decided to perpetuate this standard despite how ugly it is.
Yes? That's the case for a large number of things so it isn't like it will be something unique. Also "kids growing up learning julia as their first language" are not the only users of Julia so (like in this case) considerations to other groups of users also need to be taken.
Putting the arguments to infix :
on separate lines is also extremely rare and not exactly beautiful.
Yeah, I'd argue if you need to do this, put parens around the entire expression:
julia> (1:
2:
3)
1:2:3
I'm also quite partial to:
start = some_really_long_start_expression
step = another_long_expression_for_the_step
stop = and_lastly_yet_another_expression_for_stop
variable1 = start : step : stop
Although I'd think if you're putting that much effort into computing steps, you should probably just use range(..., length=)
instead since it's often just as easy (but more exact) to compute the length.
Most helpful comment
I'm also quite partial to:
Although I'd think if you're putting that much effort into computing steps, you should probably just use
range(..., length=)
instead since it's often just as easy (but more exact) to compute the length.