Yet I've never felt problems using 1-based languages whether Lua or Julia.
To me I just switch my mental mode to think I am doing math. I am used to mathematics using 1-indexing. And I am not a physicist or mathematician so it is not like I am steep in this tradition.
Of all things one might object to in a language, I don't grasp this carries so much weight for many people.
1-based 0-based 20-based
-Stan Kelly-Bootle
As evidence of this, check out JuliaArrays (https://github.com/JuliaArrays) which is a whole Github organization devoted to the development of alternative array types, like StaticArrays (which are stack-allocated immutable arrays) or CatViews (arrays which are non-contiguous and constructed from views of multiple different arrays). The nice thing about Julia is that, if packages are written to work with generic types, they can natively (and efficiently) work with these "non-standard" array types, making them easy to integrate into the scientific ecosystem.
Generally, I don't think there is a good way to achieve flexible indexing without causing troubles somewhere, so I don't think Julia has really solved the problem.
"Non-standard" arrays with non-standard indexing already work in lots of packages. It could be better (that's one of the things that I am advocating for), but it's not a language tooling issue whenever it's a problem, it was the developer going `::Array` and thus requiring a contiguous 1-base index array where other AbstractArrays would actually work.
You're not understanding generic types and its relation to (1). There's only one way to access an array: getindex. That's the function that's called with A[i]. However, you can use an immutable to put a thin (zero-cost) wrapper over an array, and define dispatches to getindex to do whatever you need it to do. So it's both implicit syntactically because the user just does A[i], but it's explicit because the user has to choose a different type. getindex is then usually inlined and then compiled according to the type, making it a thin abstraction over the implementation.
There are iterators which don't have a size or length. You can write generic algorithms which require an AbstractArray which HasLength and query at compile time for things like that and throw appropriate errors (those are called traits).
There is still a lot of development to do here, but the basics like this are pretty much solved except when new users treat Julia like MATLAB, but I'm not sure how anyone could control for that.
Julia has potential to become a great general-purpose programming language, but this indexing issue will practically limit it to the numerical computing community. Perhaps achieving that is already good enough.
In C, the array syntax is "mostly" just syntactic sugar for pointer arithmetic.
When you do "a[n]=value;" this is equivalent to "*(a+n) = value;". To get the nth cell of an array, you just add "n" to your base pointer "a".
Array indexing, therefore, is consistent with the pointer arithmetic.
That said, and funnily enough, Fortran, which is much older than C, has 1-based indexing (by default, but you can configure 0 based indexing, if I remember correctly).
https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E...
[0] https://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF
Edit: Fixed link. Hacker News apparently doesn't understand the delimiting of a URL with "<" and ">". >-( https://tools.ietf.org/html/rfc3986#appendix-C
I don't buy it. Wouldn't people want their programs to run fast regardless of this?
Some languages, like the Algol ones, even have user defined indexing.
So it is not neither 0 or 1, rather whatever the min value of the index happens to be.
* Python seems not so different, but once you add numpy then it involves a lot of ugly `np.arcsin(np.sqrt([...]))` type of things.
* R looks horrifyingly ugly but I haven't written anything
Coming from Mathematica 1-based is comforting, and it also matches the way people write mathematics on paper which is nice.
R not just looks ugly, but is quite horrible in the inside too. For example the variable scoping is one of the most insane I have ever seen.
But in general, I think having special purpose languages is mostly a bad idea. Firstly, having domain specific languages isolate different fields of science: If engineers use MATLAB and statisticians use R, the transfer of progress between these fields is hindered. Secondly, almost all special purpose languages for scientific stuff encourage horrible programming practices. Which typically leads to practice in the field lagging years or even decades behind scientific advances, because usable implementations are quite scarce, or tied to a domain-specific language.
But it seems R uses lexical scoping - that is, the y is captured at function definition time. That's extremely common and quite useful, in my opinion.
But if you're coming from something like Common Lisp (which is my point of reference), you soon discover that "Lexical Scoping" as implemented there and "Lexical Scoping" as implemented in R are two different things.
In R (paraphrasing) you generally have a search path of environments, and at run-time, R will find a variable by going from the inner-most to the outer-most environment looking for variables of that name. When it finds one, that's the variable R uses. What R does do is capture the path of environments that were in effect at the time of a function's creation. R has to do many of these variable lookups at runtime, which is also a factor that makes is so slow.
So what you get is a scoping scheme that, if i were being short, i'd call "actually more like dynamic scoping with environment search paths", and if i were being flippant "pretty much dynamic scoping dressed up to look like lexical scoping without any of the benefits/distinctions of either. If someone changes the applicable environments or variable later, R will just keep on humming along, pointing at new variable references that align with whatever variable name the original author of the code used, as long as that variable exists somewhere on the applicable search path"
It could be that R somehow gets some aspect of it wrong but you haven't so far presented evidence of that. (Maybe it's something you know a lot about and so it's obvious to you.)
[0] http://andrewgelman.com/2014/01/29/stupid-r-tricks-random-sc...
The function f contains a free reference to a variable called a. This is satisfied in some sort of global environment.
Later, f is called from a function in which there is a local a bound to 100. Of course, this a which is local to that function is invisible to the free reference in f which continues to refers to the global a that contains 10.
It could be there is some problem in R, but whatever that is, this article isn't exposing it in a convincing way.
Same thing in Common Lisp (using CLISP):
[1]> (defun f (x) (* a x))
F
[2]> (setf a 10)
10
[3]> (f 3)
30
[4]> (defun g (y) (let ((a 100)) (f y)))
G
[5]> (g 3)
30
The surprise is supposed to be that `(g 3)` doesn't produce 100. Why should it?(It could produce 100 if the symbol a were marked for binding as a special variable; but it isn't. Thus it's just a free variable in f resolved in the global environment, and a lexical binding in g).
y = 2
def mult(x):
return x * y
mult(6) # returns 12Domain Specific Languages for Statistics and "Math" have traditionally been 1 based. R is one based and S before that. The fact that Pandas went with 0 based was a huge disappointment for many. I use R.
I think it makes sense for enumeration in general to begin at 0. It's a mapping from the natural numbers after all, and zero is the most natural number!
What makes you think of programming iteration as a motivation for zero-based indexing?
C strongly encourages you to think of arrays as simply address+offset pointers, so it absolutely should start with 0.
I think it would make sense to say it. The reason I don't is that people around me would misunderstand me if I did. (Around some people, it works, though!)
1 Based
0 = 1
1 = 2
Zero based
0 = nothing
1 = 1
Seem important for mathematics.
print(users[users.age > 25].head(3))
Returns 3 elements and not 4!
Of course, I don't know what Pandas is like outside this particular example, or what Pandas even is. A database thing?
It'll be a sad day if Julia starts to get such popularity that high quality libraries will be Julia-only.