News for hackers. Stuff that matters.
Re:Julia 1.0 by typon on Thursday August 09, 2018 @09:30AM (#17723984)
Reading through the docs, looks like they have 1-indexed arrays..?
Re:Julia 1.0 by peatmoss on Thursday August 09, 2018 @09:39AM (#17724048)
For a numerics-oriented language this is a good choice. It’s more consistent with mathematical conventions for matrices.

0-based indexes are commonplace in programming circles because of the C language, however 1-based indexes are the earlier standard set by Fortran.

EDIT: If Julia becomes popular outside data and numerics circles, it will have pulled off nothing short of a miracle in getting people to adopt 1-based indexes. This feud is older than vi vs. emacs. :-)

Re:Julia 1.0 by Accipitriform on Thursday August 09, 2018 @01:57PM (#17726661)
Julia supports 0 based indexes if desired, similar to Ada and other languages.
Re:Julia 1.0 by computerphage on Thursday August 09, 2018 @09:37AM (#17724035)
So does Matlab/Octave and R, so Julia's choice is unsurprising to many people in the target demographic.
Re:Julia 1.0 by jordigh on Thursday August 09, 2018 @09:45AM (#17724089)
And Matlab and Octave in turn inherited it from Fortran, which inherited it from classical numerical analysis.

One-based indexing has a good, long history.

Re:Julia 1.0 by creativeembassy on Thursday August 09, 2018 @10:00AM (#17724225)
To use a silly example... can I finally realize my dream of two-based indexing?
Re:Julia 1.0 by ChrisRackauckas on Thursday August 09, 2018 @10:08AM (#17724295)
Yes. And 1.5-based indexing, though I would recommend using rational numbers instead of floating point numbers for this one.
Re:Julia 1.0 by JulianMorrison on Thursday August 09, 2018 @10:50AM (#17724660)
And imaginary is right out.
Re:Julia 1.0 by stabbles on Thursday August 09, 2018 @11:10AM (#17724820)
Maybe you could use complex numbers to index matrices
Re:Julia 1.0 by 3JPLW on Thursday August 09, 2018 @11:28AM (#17724998)
Sure can:

    # Magic
    julia> Base.to_indices(A, inds, I::Tuple{Complex, Vararg{Any}}) = (real(I[1]), imag(I[1]), to_indices(A, Base._maybetail(Base._maybetail(inds)), Base.tail(I))...)

    julia> A
    4×5 reshape(::UnitRange{Int64}, 4, 5) with eltype Int64:
     1  5   9  13  17
     2  6  10  14  18
     3  7  11  15  19
     4  8  12  16  20

    julia> A[3 + 2im]
    7
```
Re:Julia 1.0 by jordigh on Thursday August 09, 2018 @03:42PM (#17727758)
Story time!

When Octave was getting a lot of traffic from the first Coursera machine learning class, when it was just Andrew Ng doing a course and before the Coursera org existed, we were getting a lot of novice users who would do something like

    some_matrix(i,j) = 5
and get cryptic errors about how matrices cannot be indexed by complex numbers. This is because by default, in Matlab and Octave `i` and `j` are functions that evaluate to the imaginary unit. You have to overwrite the function names with `i=2, j=3` or whatever beforehand, which novices often forget. This was happening often enough that I pushed some patches to warn, "did you forget to assign i or j?" if someone tried to index matrices with complex numbers.

Point is, people in Matlab and Octave often unintentionally try to index by complex numbers.

Re:Julia 1.0 by ChrisRackauckas on Thursday August 09, 2018 @11:28AM (#17725003)
And quaternions for image stacks in ML? Troll, but not too troll...
Re:Julia 1.0 by elcritch on Thursday August 09, 2018 @07:56PM (#17729588)
That’s a right kind of wrong... and could work with FEA tensor too... ;)
Re:Julia 1.0 by timholy on Friday August 10, 2018 @02:24AM (#17731127)
For all those worried about whether Julia's indexing is good enough, let's broaden the conversation a bit. How good is your favorite language at, say, iterating along dimension m of an n-dimensional array, where m and n are not known by the programmer, and where you can't count on the array being strided? Trivial and extremely efficient in Julia: https://julialang.org/blog/2016/02/iteration.
Re:Julia 1.0 by currymj on Thursday August 09, 2018 @09:39AM (#17724042)
Apart from being close to MATLAB, a goal of Julia is to make it easy to just type mathematical formulas straight off the page and into your code. 1-based indexing makes this so much easier, even if it seems somewhat depraved to a computer scientist.
Re:Julia 1.0 by kmm on Thursday August 09, 2018 @11:37AM (#17725104)
In my experience, 0-based indexing is way more common in mathematics. Maybe it depends on the field you're working in. Off the top of my head, dimensions are numbered from zero in relativity and particle physics, Fourier series only make sense with 0-based indexing, coefficients of polynomials are numbered from zero, Taylor series, indexing by taking the modulo ...
Re:Julia 1.0 by simonbyrne on Thursday August 09, 2018 @11:59AM (#17725321)
A slight quibble: FFTs are more naturally indexed periodically. Luckily, Julia has that covered: https://github.com/JuliaArrays/FFTViews.jl
Re:Julia 1.0 by stabbles on Thursday August 09, 2018 @09:49AM (#17724122)
If you feel uncomfortable, note that Julia internally has some indirection to allow for custom offsets. See for instance OffsetArrays.jl [1]

[1] https://github.com/JuliaArrays/OffsetArrays.jl

Re:Julia 1.0 by JulianMorrison on Thursday August 09, 2018 @10:51AM (#17724666)
0-based feels like offsetting memory to me. In a high level language, you aren't doing that.
Re:Julia 1.0 by dagw on Thursday August 09, 2018 @09:33AM (#17724013)
That is correct, mainly due to coming from Fortran and Matlab background. However they also have offset arrays (like in Fortran) if you need arrays that start on a different index.
Re:Julia 1.0 by ur-whale on Thursday August 09, 2018 @10:51AM (#17724669)
Does that work properly with multi-dimensional arrays?
Re:Julia 1.0 by KenoFischer on Thursday August 09, 2018 @11:10AM (#17724821)
Of course.
Re:Julia 1.0 by stellalo on Thursday August 09, 2018 @10:32AM (#17724500)
1-based indexing is a non-issue
Re:Julia 1.0 by ur-whale on Thursday August 09, 2018 @10:50AM (#17724662)
It most certainly is for the vast number of folks who code in C, C++, Java, Python, etc ...

It will for sure hurt adoption.

Re:Julia 1.0 by BeetleB on Thursday August 09, 2018 @11:40AM (#17725124)
>It will for sure hurt adoption.

Reminds me of the complaints my friends had about Linux when I first showed them a fantastic window manager.

"This will never get anywhere. It has no Start button."

If I were in a team that refused a language just because it is 1 based indexing, I would really worry about the abilities of the team.

Re:Julia 1.0 by weatherlight on Thursday August 09, 2018 @11:11AM (#17724831)
I'm pretty sure if people are willing to adopt a new language, they will be open minded enough to accept 1 indexed arrays.
Re:Julia 1.0 by ur-whale on Thursday August 09, 2018 @11:59AM (#17725330)
History has shown the exact opposite.
Re:Julia 1.0 by DandyDev on Thursday August 09, 2018 @12:23PM (#17725588)
Examples?
Re:Julia 1.0 by ur-whale on Thursday August 09, 2018 @01:06PM (#17726078)
You just have to look at the most popular programming languages on 2018.

They're all 0-based (with maybe R as an exception, but R is a niche language. If that's what Julia aims to remain -- their loss).

The folks who designed these languages knew how not to alienate their future market.

Re:Julia 1.0 by cultus on Thursday August 09, 2018 @01:39PM (#17726469)
Matlab is 1-based. That's what the vast majority of scientific programmmers still use. Worrying about 0 vs 1 is just useless bikeshedding, really. I've done lots of index heavy operations in Julia and in Python, and it's easy either way.
Re:Julia 1.0 by typon on Thursday August 09, 2018 @02:25PM (#17726976)
I think majority of scientific programmers use Python/C/Numpy stack over Matlab
Re:Julia 1.0 by cultus on Thursday August 09, 2018 @05:24PM (#17728639)
No, not true at all. Engineering and academia are still solidly Matlab. You have to keep in mind that these people are not programmers, they are used to Matlab, and they don't want to learn another language. It's just a small proportion of new faculty and some grad students that use Python. Statistics is all R.
Re:Julia 1.0 by goatlover on Thursday August 09, 2018 @11:21AM (#17724931)
It's not any harder to get used to than using whitespace for blocks in Python, or having to end every damn statement with a semicolon in the C inspired languages.
Re:Julia 1.0 by ur-whale on Thursday August 09, 2018 @12:08PM (#17725434)
>It's not any harder to get used to than using whitespace for blocks in Python, or having to end every damn statement with a semicolon in the C inspired languages.

Strongly disagree.

I can move from C to Python without a second thought and rewrite code from one to the other without even thinking.

Having to rewrite an algorithm working on multidimensional arrays that was written with 0-based conventions to 1-based conventions and have the resulting code remain readable is a freaking headache.

Re:Julia 1.0 by SolarNet on Thursday August 09, 2018 @12:52PM (#17725928)
Ok, then use the built in Julia features to use any offset you want inside your algorithm's code.

Compilers are pretty good about optimizing integer constants.

Re:Julia 1.0 by ur-whale on Thursday August 09, 2018 @01:04PM (#17726047)
Everyone in this thread seems to believe that 1-based indices is a non-problem because Julia "offers a choice".

My reaction:

   - the default is 1-based, which means the bulk of Julia code will adopt the convention and therefore the vast majority of coders in 2018 will have to do mental gymnastics to understand what the code does.

   - when I read Julia code, I will never know which convention the code was written with unless I dig to find where that particular flag is set.

   - passing 0-based arrays to a library routine that expects 1-based stuff, what happens then?

   - for code that will be 0-based and uses library code that expects 1-based (assuming that's possible without paying copying overhead) will force the code to mentally switch between the two modes. Ugh.

In short: offering is a choice is maybe even worse than enforcing 1-based.
Re:Julia 1.0 by SolarNet on Saturday August 11, 2018 @08:54PM (#17742351)
I think you misunderstand that the offset is encoded in the type of the object, so only your 1st concern is valid.

For concern 2, it's as easy as finding the type. And without knowing the types you wouldn't know what the code did anyway.

For concern 3, a type error.

And for 4, because it's a type there is zero runtime overhead. A view of the array with the offset the code expects is constructed, often automatically based on the types involved. This view is often a zero cost abstraction at runtime because of how Julia specialization works. So at worst you pay some (extremely minor) compile-time/load-time costs.

Re:Julia 1.0 by int_19h on Thursday August 09, 2018 @05:56PM (#17728916)
Languages that have offered that choice have been around for decades - Pascal, for example. It was never a problem in practice.
Re:Julia 1.0 by pjmlp on Thursday August 09, 2018 @11:24AM (#17724965)
Some of those folks started when Fortran, Basic, Clipper, Pascal, Modula-2, Ada were relevant.

1 based indexes were just fine.

Re:Julia 1.0 by kazinator on Thursday August 09, 2018 @04:05PM (#17727990)
Vectors are zero based in Common Lisp; the 1960 Lisp 1 manual describes arrays; they are zero based.

Zero based is much more sane. If the array is regarded as being made up of larger groups of elements, say groups of 8, then ⌊index/8⌋ gives us the group and group x 8 gives us the base element of group. Not so if index is one-based.

Zero based multi-dimensional coordinates are easy to convert to a flat address. E.g. 3D case: just ABz + By + x.

Imagine distances were one based (so that either 1 m or 1 km means no displacement), and then trying to convert a given distance between m and km. Yikes!

Music intervals are one-based, to their great detriment. We end up with a "rule of nine" for interval inversion and that comes from the octave of the diatonic scale having seven notes!

One-based indexing is okay when the indices don't have a strong numeric meaning (beyond basic successor/predecessor relationships), or none at all (basically are symbolic and could be replaced by any set that can be enumerated by the natural numbers).

As soon as the index domain is involved in displacement calculations that feature multiplication and division, anything but zero based is disadvantaged.

Re:Julia 1.0 by pjmlp on Thursday August 09, 2018 @05:49PM (#17728845)
I also have read Dijkstra, it doesn't mean I agree with everything he wrote.

In Algol based languages indexes are customizable, I don't remember ever writing array [0..9] of Integer instead of array [1..10] of Integer.

C, C++ and their descendants took over and I just had to adapt.

Re:Julia 1.0 by stellalo on Thursday August 09, 2018 @06:57PM (#17729264)
I haven’t, so far, encountered a single occasion in which I would need to manually flatten-deflatten indices: Julia has multidimensional arrays of any dimension N, and you can access their content in a linear fashion without any effort (simply provide one index instead of N)
Re:Julia 1.0 by kazinator on Thursday August 09, 2018 @10:22PM (#17730229)
Still, the implementation has to internally do ABC(z - 1) + AB(y - 1) + A(x - 1), compensating for the pointless bias at every dimension.

It's just a wanton complication, like insisting on Roman numerals instead of a radix enumeration.

Re:Julia 1.0 by stellalo on Friday August 10, 2018 @05:21AM (#17731810)
Well, I’d say the analogy with Arabic vs Roman numerals is a bit of a stretch. Seriously, it is just a matter of shifting by one, humanity has much bigger problems to focus on!
Re:Julia 1.0 by pjmlp on Friday August 10, 2018 @01:13AM (#17730853)
The implementation already has to do lots of internal stuff to map high level language abstractions to actual real hardware capabilities, index calculations is just another one.
Re:Julia 1.0 by stellalo on Thursday August 09, 2018 @03:53PM (#17727888)
I love C and I was myself suspicious when I first tried Julia. I ended up being perfectly able to reason in terms of 1-based indices and right-inclusive ranges. I’m sure I’m no special kid :-)
Re:Julia 1.0 by dnautics on Thursday August 09, 2018 @12:51PM (#17725914)
I started using elixir/erlang, which basically doesn't have indexing, ever. It's been a joy.
Re:Julia 1.0 by Q6T46nT668w6i3m on Thursday August 09, 2018 @09:34AM (#17724019)
Yes. Julia’s mission was (and still includes) providing an alternative to 1-indexed MATLAB.
Re:Julia 1.0 by pkofod on Friday August 10, 2018 @04:30AM (#17731603)
I know, right? Every time I want to read the top post on hacker news I always spend 10 minutes looking for it... but then I realize that HN labels the top post "1" and not "0". So annoying.
Re:Julia 1.0 by eigenspace on Thursday August 09, 2018 @09:59AM (#17724214)
... and?
Re:Julia 1.0 by dangjc on Thursday August 09, 2018 @10:40PM (#17730303)
Porting existing C, C++ library code hand tailored with 0 based indexing is incredibly painful and error prone. And unfortunately, that’s what most libraries used underneath python or R wrappers use.
Re:Julia 1.0 by ur-whale on Thursday August 09, 2018 @10:52AM (#17724676)
Yeah, same here. Once I hit on that, it was really hard to convince myself to read further.
Re:Julia 1.0 by goatlover on Thursday August 09, 2018 @11:26AM (#17724981)
You do realize that 0-based indexing is mostly because of C's huge influence and not because it's natural to higher level languages, particularly ones that are designed with scientific computing in mind. Fortran existed before C.

It's also not hard to get used to. No more OB1 errors.

Re:Julia 1.0 by buckminster on Thursday August 09, 2018 @01:23PM (#17726290)
I programmed in 1-based languages for a decade before I used C yet I prefer 0-based.

If you are calculating an index the domain and range of the index function are very often 0-based. So you have to subtract and add one to convert from and to 1-based. It's just messy.

Re:Julia 1.0 by ur-whale on Thursday August 09, 2018 @12:02PM (#17725365)
>No more OB1 errors

That makes no sense. Neither 1-based indexing or 0-based indexing will save you from OB1 errors.

As a matter of fact, if you make more OB1 errors in a 0-based indexing language, it's probably because your brain is wired to think 1-based.

The problem: there are legions of programmers whose brain is wired to think 0-based and are guaranteed to suffer through a lot more OB1 errors if they try to adopt Julia.

0 based indexing is not because of C's influence. It's because that's how computers work. ASM is 0-based indexing. The first memory cell on a computer doesn't start at address 1.

Re:Julia 1.0 by goatlover on Thursday August 09, 2018 @01:34PM (#17726415)
Programming languages are an abstraction from the hardware. There's a reason we stopped using assembly for most programming, and C is considered by many to not be a good high-level general purpose language. Anyway, 1-based is not exactly a new thing in the domain Julia is targeting.
Re:Julia 1.0 by ChrisRackauckas on Thursday August 09, 2018 @12:11PM (#17725465)
Because you defined binary counting to start at 0
Re:Julia 1.0 by chappi42 on Thursday August 09, 2018 @11:06AM (#17724792)
Your loss, maybe?
Re:Julia 1.0 by ur-whale on Thursday August 09, 2018 @04:47PM (#17728341)
I didn't say I stopped reading.
Re:Julia 1.0 by psychometry on Thursday August 09, 2018 @11:15AM (#17724863)
If 1-indexing seems strange, you're probably not doing mathematical or statistical computing, so it's probably not the language for you.
Re:Julia 1.0 by ur-whale on Thursday August 09, 2018 @12:04PM (#17725392)
I've done math and stats all my life.

When I do sigmas in math, they go: i=0,i<n and very rarely i=1, i<=n unless the problem really is made simpler by the weird 1-based indices.

Re:Julia 1.0 by dnautics on Thursday August 09, 2018 @12:53PM (#17725936)
that's very bourbakian, but pretty much everyone else does 1..n, except for taylor series.
Re:Julia 1.0 by ur-whale on Thursday August 09, 2018 @12:58PM (#17725984)
>that's very bourbakian

guilty as charged :)

Re:Julia 1.0 by dnautics on Thursday August 09, 2018 @03:56PM (#17727918)
no need to be ashamed of it!