Julia is a great language, but I'm still waiting for someone to create a Julia fork that uses 0-based indexing.
They should compromise and use 0.5-based indexing.
Automatic Differentiation with Julia
61–70 of 83 posts
Re: Automatic Differentiation with Julia
#62Earlier quoted context omitted.
>close-to-magical As magical as the chain rule of differentiation.
It’s interesting though that the way calculus is classically taught does not make this obvious.
Re: Automatic Differentiation with Julia
#63Earlier quoted context omitted.
My argument was that in situations where the difference between 0 and 1 based indexing makes a difference it's ususally 0-based indexing that leads to simpler code.
I guess I find it ironic then, that one of the most common programming errors, is of the "off-by-one" variety[1]. It is in part due to differences in convention and notation in various fields[2]. This isn't common in 1-based indexing languages. Very common in 0-based indexing languages[3]. If the 0-based indexing was objectively superior, wouldn't there be fewer instances of such bugs? [1] https://en.wikipedia.org/wi…
Off-by-one can show up in a bunch of ways that are agnostic to the underlying indexing, so it isn't obvious to me that there would be a substantial difference at all. Also, given what's said below about the ease of writing code which fails to consider custom indices, I'm not sure I believe just switching to 0-based or anything else in Julia is as painless as you suggested earlier - it could introduce its own off-by-one errors!
Re: Automatic Differentiation with Julia
#64Earlier quoted context omitted.
It's not absurd at all. In situations where you need to do modulo arithmetic on array indices 1-based indexing forces you to shift the offset by 1.
Yes and that's something most programmers need to do almost never, so let's not make any important design decisions around that very specific case.
Re: Automatic Differentiation with Julia
#65Earlier quoted context omitted.
I guess I find it ironic then, that one of the most common programming errors, is of the "off-by-one" variety[1]. It is in part due to differences in convention and notation in various fields[2]. This isn't common in 1-based indexing languages. Very common in 0-based indexing languages[3]. If the 0-based indexing was objectively superior, wouldn't there be fewer instances of such bugs? [1] https://en.wikipedia.org/wi…
I was hoping to read some code analysis that supported your claim of off-by-one being more common in 0-based languages, but all I see in your [3] is a few different speculative reasons - am I missing something? Off-by-one can show up in a bunch of ways that are agnostic to the underlying indexing, so it isn't obvious to me that there would be a substantial difference at all. Also, given what's said below about the ea…
Re: Automatic Differentiation with Julia
#66Earlier quoted context omitted.
> This is too often the attitude of Julia people And it's a good attitude for the Julia people to have. Their target audience is not just (or even mainly) full time developers. They're targeting scientists, statisticians etc. As such, it makes sense for Julia to use conventions that are appropriate to their audience. This pervades the whole of Julia, not just indexing although the latter is exceptionally rich for thi…
> And it's a good attitude for the Julia people to have. Their target audience is not just (or even mainly) full time developers. They're targeting scientists, statisticians etc. I don't see how scientists or staticians would be unable to understand a basic knowledge like zero-based indexing. In fact, zero-based indexing already is widely used in basic areas such as series and sequences. Why are freshmen quite capabl…
Re: Automatic Differentiation with Julia
#67Earlier quoted context omitted.
Julia was developed by scientists that used math software like MATLAB. Most mathematics software uses 1-based indexing. (Previous comment about this.[1]) >with 1-based indexing : T[(h-1) * W * C+(w-1) * C+c] Your example showing how cumbersome and ugly it is to subtract 1 -- isn't how the intended audience uses mathematics software. Instead, they would use idiomatic multidimensional access with commas or multi-bracke…
My argument was that in situations where the difference between 0 and 1 based indexing makes a difference it's ususally 0-based indexing that leads to simpler code.
Have you used julia? You're almost never calculating your offset to a pointer. The VM does that for you. (As it does for python, ruby, erlang). Or actually in the case of julia it's more accurate to say the (extremely lazy ahead of time) compiler does it for you.
Re: Automatic Differentiation with Julia
#68Julia is a great language, but I'm still waiting for someone to create a Julia fork that uses 0-based indexing.
Hear hear. Everyone that's making excuses for one based is wrong. You need a zero in your set of integers to form a Ring modulo N. I hereby declare everyone that wants 1 based indexing out of some naive sense of it being easier a scrub.
Re: Automatic Differentiation with Julia
#69Earlier quoted context omitted.
> or any other kind of offset that you so desire This is too often the attitude of Julia people. But zero-based indexing is not just some arbitrary offset. Programmers just like it. You say that many things are more intuitive with one-based indexing, but many things are less intuitive too. I don't think python ever would have become popular without zero-based indexing. The thing is, we really don't know why people pr…
Well for one, most situations I can think of when an index is calculated a 0-based index is more useful. Addressing an element T[h][w][c] in a linearized 3D tensor with 0-based indexing: T[h*W*C+w*C+c] with 1-based indexing: T[(h-1)*W*C+(w-1)*C+c] Or let's say you want to take a string "abc" and repeat it until the length is 10, getting "abcabcabca". With 0-based indexing: a,b = "abc", [" "]*10 for i in range(0,10):…
But why would you ever use linearized addressing when you have proper multidimensional access? Aside from doing the low-level implementation of multidimensional access, you shouldn't ever need to do that.
> Or let's say you want to take a string "abc" and repeat it until the length is 10, getting "abcabcabca". With 0-based indexing
Your example assumes not only the stated indexing model but also a range function that returns the integer members of a half-open range, which is a little crazy of a way to do loops, but the least unintuitive way with 0-based indexing, so programmers are used to it from C (where you do it without an actual function call) and newer zero-based languages.
With 1-based languages, the sane way is the more intuitive closed range (for i in 1:5) which doesbt require an extra mental operation to convert to the set of values that will actually be used. There are good uses for half-open ranges, but the kind of explicit loop control they get used for in 0-based languages is an artifact of 0-based languages, so arguing that it is (even more) awkward in a 1-based language isn't an argument against 1-based languages.
Re: Automatic Differentiation with Julia
#70Earlier quoted context omitted.
> Having said that, I encourage you to try out the 1-based indexing, as I think you might find a lot of things become surprisingly more intuitive. Can you provide an example? It seems that the assertion only reflects a personal point of view, similar to the egg endianness discussion in Gulliver.
Counting is slightly easier: if you have one object, it has slot number 1, and if you have one more object (meaning you have two objects) that second object has slot number 2. PS: I am joking here of course, but seriously, try counting things with your fingers starting with a fist, then one finger, then two.