News for hackers. Stuff that matters.
Re:Julia 1.9.0 lives up to its promise by bobbylarrybobby on Saturday May 13, 2023 @04:53PM (#35932599)
Not just that, but ranges are inclusive on both ends.
Re:Julia 1.9.0 lives up to its promise by sundarurfriend on Saturday May 13, 2023 @04:59PM (#35932653)
Ha, I was thinking of replying to your parent comment, "Half-open ranges are such an unpleasant thing as to be unforgivable to me. Different subjective preferences."

I've always found 0-indexing mildly unpleasant too, even though C was the language I learnt programming with, and felt like I found home when I came across 1-indexed languages.

Re:Julia 1.9.0 lives up to its promise by bobbylarrybobby on Saturday May 13, 2023 @05:23PM (#35932887)
With half open ranges, the length of the range is the end minus the beginning, which is nice. It's also much more simpler to write an empty half inclusive range. For instance if left=right then left..right would be the empty range. Whereas in Julia I'd need... left:(right-1)? But is 1:0 the empty range or the right-to-left inclusive range [1,0]? Very confusing and hard to work with all around.
Re:Julia 1.9.0 lives up to its promise by sundarurfriend on Saturday May 13, 2023 @05:44PM (#35933073)
> With half open ranges, the length of the range is the end minus the beginning, which is nice.

But I already know from real life that if there's maintanence in blocks 5 to 15, that's eleven blocks under maintanence. With half-open ranges, it once again introduces confusion and makes things unintuitive.

We can each find countless examples where each style comes out better, for eg `1:N` most often expresses the intent better than `range(N+1)`. I find people who prefer half-open ranges to be weird and incomprehensible, you probably find my preferences the same, I just don't like the categorical statement often made in this regard that one is inherently and universally superior to the other.

Re:Julia 1.9.0 lives up to its promise by bobbylarrybobby on Saturday May 13, 2023 @06:13PM (#35933288)
Yes, range(n+1) is bad. I hate python as well. You want something like Rust’s m..n and m..=n to have the choice. Anyway, if you have half open ranges, it's trivial to get a closed range (add one to the right endpoint), but going the other direction is not so simple.
Re:Julia 1.9.0 lives up to its promise by Iwan-Zotow on Saturday May 13, 2023 @06:15PM (#35933307)
Julia ranges are not composable, period

In Python, C/C++ and its descendant

[0...N)=[0...N/2)+[N/2...N)

Re:Julia 1.9.0 lives up to its promise by webshit2 on Saturday May 13, 2023 @05:23PM (#35932886)
Little do Julia fans know they're missing out on gems like range(n - 1, -1, -1).
Re:Julia 1.9.0 lives up to its promise by ted_dunning on Sunday May 14, 2023 @01:48AM (#35935636)
??

Isn't that just n-1:-1:0 in Julia?

Was this sarcasm?

Re:Julia 1.9.0 lives up to its promise by leephillips on Sunday May 14, 2023 @10:53AM (#35938456)
Naaaah.
Re:Julia 1.9.0 lives up to its promise by adgjlsfhk1 on Sunday May 14, 2023 @03:00PM (#35940418)
I think the point was that in Julia is n:-1:1 since although rangers don't compose, they do reverse (unlike python)