3 ms·
This argument over indexing conventions is so tired. I have yet to hear a good argument for why the answer to "How do I get the third element of this array?" s
by eigenspace 1mo ago
This argument over indexing conventions is so tired.
I have yet to hear a good argument for why the answer to "How do I get the third element of this array?" should be `arr[2]`
> Both R and Julia have their core functions written in C++. Absolutely nothing new.
What on earth are you talking about? This is at least a novel claim. Some deep parts of julia's compiler are written in C++ but that's about it. Nearly everything in the language is written in julia itself.
The only significant foreign codebases in the language are
* LLVM
* OpenBLAS
* LibUV
all of which are extremely reasonable foreign things for a language to use (though we are gradually moving more and more of these things to the julia side)
- defrost 1mo ago> "How do I get the third element of this array" should be `arr[2]` Ask a carpenter. To get to the third pigeonhole in a racked series of one foot per pigeonhole unit you literally offset two feet from the origin. In C (of course), arr[2] works as well as does 2[arr] as both are literally just syntactic sugar for arr+2 ie. The third pigeon hole begins after passing two whole pigeonholes.
- eigenspace 1mo agoOkay, but why are you trying to think about *elements* of a list in terms of offsets from the origin? I mean, that's an important low-level detail to know when you're working with assembly or doing pointer math, but it is not something that necessarily needs to be polluting the semantics of a high level language. I find it much easier to think in terms of v[i] is the i-th element of my vector. These sorts of things just feel like mental gymnastics people perform to post-hoc justify language quirks.
- defrost 1mo agoYou asked for a good argument - I provided one. > but why are you trying to think about a list of elements in terms of offsets from the origin I don't try to think about them in this way - I do and have always thought about them in this way - in software terms for 50 years, in real world cut, saw, and hammer ways for over 60. > I find it much easier to think in terms of ... Which is the crux of the issue really, that's how you think. > v[i] is the i-th element of my vector. I think of V as the start of a row of elements. V+0 is equivalent to V and naturally the start of the first element. V+1 is the start of the row, plus one - the literal start of the second element. I've always thought of V[i] as offsets, "jump overs" if you will. It comes naturally for many that have worked with their hands on physical objects and worked with tape measures. > but it is not something that necessarily needs to be polluting the semantics of a high level language. Either way of thinking works - I spent decades going back and forth from Fortran to C, and people are free to make their high level languages however they wish - it's trivial to move from one to the other. There are even some funky (or eyeball gouging) tricks done to preamble a data run with meta data, leading to V[-1] indexing being commonplace (in some domains)
- eigenspace 1mo ago> You asked for a good argument - I provided one. I don't see a good argument though, I just see adaption to a quirky convention. > Either way of thinking works - I spent decades going back and forth from Fortran to C, and people are free to make their high level languages however they wish - it's trivial to move from one to the other. Here I agree. I have no real problem using a 0-based indexed language, I adapt to it quickly (or as you mention a -1 indexed language. Julia itself actually stores type-level metadata at the -1 index of a pointer to a mutable struct) I just dislike when people try and turn every conversation about julia into "oh it's 1-based indexed so that disqualifies it", and act like 0-based indexing is some god-given most natural way to do all indexing.
- defrost 1mo ago> , I just see adaption to a quirky convention. Of course you do - you very likely didn't start programming in assembler. You literally asked "How do I get to .." implying you wanting street instructions, distances, etc. In assembler the third element begins literally and straightforwardly at the address base plus two (element widths). That's not "a quirky adaption" is it? It's a dull pragmatic address of the start of the third element - the answer to the question you posed.
- eigenspace 1mo agoI did not say "How do I get *to* ..". > Of course you do - you very likely didn't start programming in assembler. I did not, and I do not think that conventions from assembler should influence basic ergnonomic design decisions of modern high-level langauges.
- jondea 1mo agoThe third hole is _offset_ by 2, but if you ask a carpenter to add number labels to your pigeonholes, they are going to start at 1. Indexes start at 1, offsets start at 0.
- defrost 1mo agoWell, of course. And offsets are the measurements that get you to an element - the question was explicitly phrased as "how do I get to" ...
- jondea 1mo agoThe problem is that we call the things in square brackets indexes, when we should probably call them offsets
- CoreformGreg 1mo agoTechnically they explicitly said “how do I get the”