7 ms·
Too bad they somehow thought it was a good idea to make the syntax resemble MATLAB of all languages. Perhaps most of the nausea inducing warts could be worked a
by jampekka 9y ago
Too bad they somehow thought it was a good idea to make the syntax resemble MATLAB of all languages. Perhaps most of the nausea inducing warts could be worked around with some kind of transcompilation, although some semantic issues, such as one-based indexing, would remain.
It'll be a sad day if Julia starts to get such popularity that high quality libraries will be Julia-only.
- azag0 9y agoOne-based indexing is not a semantic issue, it's a language-design decision you may disagree with.
- pjmlp 9y agoWhich happens to common across many languages outside C universe. 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.
- PeachPlum 9y agoJulia 0.5 introduced support for any indexing scheme you care to invent. 1-based 0-based 20-based https://docs.julialang.org/en/latest/devdocs/offset-arrays/ https://docs.julialang.org/en/latest/devdocs/offset-arrays/
- attractivechaos 9y agoThat is an ugly hack, mainly because it was not in the original language design.
- pjmlp 9y agoWhy ugly? It looks similar to what I know in the Pascal family, where indexes can be ranges or enumerations.
- attractivechaos 9y agoIt is ugly because 1) 1-based indexing and x-based indexing are treated differently; 2) x-based indexing has to use more complex syntax, which in effect discourages the use of non-1 indexing; 3) this strategy sets potential pitfalls (e.g. implementing length and size for non-1 indexing arrays). A cleaner design, I guess, would be to specify index range on declaration like pascal static arrays and use low(A):high(A) for iteration rather than 1:length(A). This, however, complicates 1-based use cases. 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.
- ChrisRackauckas 9y ago1) No, they are just different dispatches to getindex. 2) No, iteration is through indices(A) or eachindex(A), etc., which are the preferred way of iterating anyways. You shouldn't do 1:length(A) which is a MATLABism that works but I would say isn't good Julia. 3) Defining new dispatches for length and size is a pretty standard use of the language? "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.
- attractivechaos 9y agoOn 2), if you think 1:length(A) is bad, why not forbid it from beginning (e.g. use low(A):high(A) instead)? To find an x-based array length, why not just length(A), instead of length(linearindices(A))? Decisions like such are remedies of immature early design. Also, what if I use length() on an x-based array? Abort or a wrong number silently? On 1), having two different ways to access array, the most fundamental data type, is already worrying enough. On 3), the page says "don't implement size or length". That is very uncommon in most other mainstream languages. 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.
- ChrisRackauckas 9y agoit is in the original language design which is all about type-genericness and separation of implementation from interface with zero-cost abstractions. Creating an array with a different `getindex` dispatch is a great example of what Julia's type system was made to do! The standard library chose to use 1-base indexed contiguous fixed-dimesion dynamic arrays, but that's not the right choice for every problem. As evidence of this, check out JuliaArrays (https://github.com/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.
- wtetzner 9y agoShould array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration. -Stan Kelly-Bootle
- disconnected 9y agoI don't have any particular feelings toward one or the other (it is a convention, get over it), but I think that zero-based indexing is just an artifact of C that stuck around. 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).
- pvg 9y agoZero based indexing is not a C artifact. Here's Dijkstra writing about it in '82: https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E...
- Bromskloss 9y agoNote how, in the PDF version [0], Dijkstra numbers the pages starting on zero (handwriting, upper right corner), but whoever created the PDF disregarded its message and did numbering starting on one (lower right corner). :-) [0] https://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF 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 https://tools.ietf.org/html/rfc3986#appendix-C
- Avshalom 9y agoThere's the very real possibility that zero based indexing is in fact a Yacht Racing artifact. http://exple.tive.org/blarg/2013/10/22/citation-needed/ http://exple.tive.org/blarg/2013/10/22/citation-needed/
- Bromskloss 9y ago> The social reason is that we had to save every cycle we could, because if the job didn’t finish fast it might not finish at all and you never know when you’re getting bumped off the hardware because the President of IBM just called and fuck your thesis, it’s yacht-racing time. I don't buy it. Wouldn't people want their programs to run fast regardless of this?
- goatlover 9y agoLike every other language-design decision?
- improbable22 9y agoWhat syntax would you like instead, for numerical programming? * 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.
- sin7 9y agoR had changed a ton in the last three years. It's pretty clean these days.
- jampekka 9y agoI mostly use Python, although it has some syntax issues too (eg. no real lambdas, I'd prefer no parenthesis for function calls etc). I don't see why that's a numpy problem. If you just do "from numpy import *" you can pollute your namespace with hundreds of symbols, just like eg. MATLAB. 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.
- noobhacker 9y agoCould you clarify what's insane about the variable scoping in R? I'm a bit too close to R so I'm afraid I'm oblivious.
- sin7 9y agoI use a lot of R. The thing that drives me insane is when you create a function such as multxy <- function (x){x * y}, then you call multxy(6) R will not return an error as long as y is in the parent environment. That's pretty insane.
- baldfat 9y agoI have zero understanding about this rant? 0 based is due to programming iteration. I don't use pandas because it is 0 based and it was a mistake. Domain 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.
- Bromskloss 9y ago> 0 based is due to programming iteration. 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?
- baldfat 9y ago> To quote wikipedia on Zero-based "Zero-based numbering or index origin = 0[1][2] is a way of numbering in which the initial element of a sequence is assigned the index 0, rather than the index 1 as is typical in everyday non-mathematical/non-programming circumstances." 1 Based 0 = 1 1 = 2 Zero based 0 = nothing 1 = 1 Seem important for mathematics.
- baldfat 9y agoAlso head and tail in Pandas is 1 based! That drove me crazy. print(users[users.age > 25].head(3)) Returns 3 elements and not 4!
- Bromskloss 9y agoIs it possible that the argument to `head` is the _number_ of elements to return, and that the choice of indexing therefore doesn't enter the picture?
- Bromskloss 9y agoActually, even if the argument (3 in this case) were an index, I would expect it to be the index of the first element _not_ to fetch, like how intervals typically are written with an inclusive lower bound and an exclusive upper bound as in "2 ≤ i < 13" [0]. That would make the result you're getting consistent with zero-indexing, but not with one-indexing. Of course, I don't know what Pandas is like outside this particular example, or what Pandas even is. A database thing? [0] https://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF https://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF
- jernfrost 9y agoI really don't get the indexing religious wars. I "grew" up on 0-indexed languages, C/C++, assembly, Python, Ruby, Java, Objective-C, Swift etc. 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.
- goatlover 9y agoWhat's wrong with the syntax? I think Julia has really nice syntax.