News for hackers. Stuff that matters.
Re:Swift for TensorFlow Shuts Down by SatvikBeri on Friday February 12, 2021 @05:28PM (#26119266)
I love Julia in general, but yeah, I hate `end`.

Re: 0-indexing vs 1-indexing. If you use 0-indexing, you turn off a lot of non-engineering scientific programmers. My personal experience is that 0-indexing is better for more engineering applications, while 1-indexing is better for math. I'm a weirdo in that I don't seem to mind either one though.

Re:Swift for TensorFlow Shuts Down by cambalache on Friday February 12, 2021 @06:53PM (#26120023)
> you turn off a lot of non-engineering scientific programmers.

I think you mean "non-CS engineers". CS is a minuscule branch of engineering. Plenty of chemical, mechanical, civil (and so on) engineers had their whole education doing maths and programming with 1-indexing.

> I'm a weirdo in that I don't seem to mind either one though.

You are not, as an outsider this is one of the less appealing parts of practical CS, endless bickering about non-substantive issues which most of the time boil down to a matter of personal preference (see also tabs vs spaces, vim vs emacs, react vs vue, golang vs rust and on and on and on...)

Re:Swift for TensorFlow Shuts Down by mjcohen on Friday February 12, 2021 @07:00PM (#26120099)
I don't understand why Julia didn't do like Fortran and Ada and allow any starting index. E.g., a(-5:5, 0:3).
Re:Swift for TensorFlow Shuts Down by kirill5pol on Friday February 12, 2021 @08:32PM (#26120642)
In case you didn’t know, Julia does in fact have arbitrary indexing!

https://docs.julialang.org/en/v1/devdocs/offset-arrays/

Re:Swift for TensorFlow Shuts Down by SatvikBeri on Friday February 12, 2021 @07:16PM (#26120198)
I mean, Julia is flexible enough that it's pretty easy to implement arrays with different indexing schemes that have the same performance as built-in arrays: https://github.com/JuliaArrays/OffsetArrays.jl
Re:Swift for TensorFlow Shuts Down by skohan on Friday February 12, 2021 @05:40PM (#26119385)
Is there an example of where 1 is better for math, or is it just a familiarity thing?
Re:Swift for TensorFlow Shuts Down by FridgeSeal on Friday February 12, 2021 @07:28PM (#26120294)
Zero based indexing came from early requirements to address things in arrays using offsets.

Subsequent languages don’t have this issue, and when you think about it, it causes a weird disconnect: 1-based indexing corresponds exactly with how you think about and see elements in a collection. 0 based indexing-despite how comfortable one gets with it requires additional arithmetic.

It’s a relic from the past, and unless you’re doing the very specific thing of indexing via offset instead of position, there’s no reason to hang onto this anachronism.

Re:Swift for TensorFlow Shuts Down by socialdemocrat on Friday February 12, 2021 @06:44PM (#26119951)
Most math books are written in a way where 1 is the first element. So if you take math examples and translate to code, it works more naturally.

Also this is how you talk normally. You don't talk about the zeroth-column or zeroth-row in daily speech. You talk about first column and first row.

Only reason 0 based indexing make sense to me is because I began programming as a teenagers and was forced to get accustomed to it. But I remember struggling with it. Yes when working with memory, pointers etc it is more elegant. But if you are not, then I think 1-based indexing looks better.

Re:Swift for TensorFlow Shuts Down by SatvikBeri on Friday February 12, 2021 @06:15PM (#26119693)
As a trivial example, if you want to get the sum of the first n numbers, that's `sum(range(n+1))` in Python. Or if you want to get all the prime numbers <= n, find the triangular numbers, etc. In general you end up with a lot of `n+1`s and it's easy to lose track or miss some, and end up with a silent, non-crashing error that produces the wrong result because you're accidentally leaving out the last element of your input.
Re:Swift for TensorFlow Shuts Down by cbkeller on Friday February 12, 2021 @09:13PM (#26120832)
Linear algebra is the most practically consequential one - and suffice it to say, it’s not a coincidence that BLAS, LINPACK, and LAPACK were all written in one-based languages. Matrix indexing is one-based, and beyond the issue of translating notation from equations, IIRC there is even a slight performance difference in some cases.

I believe what it really comes down to is that, just as zero-based really is more natural for offsets (zero offset means the first position, great for pointers), one based really is more natural for counting [and _sets_] (when your index is n that means you have counted n elements up until now).