News for hackers. Stuff that matters.
Re:Some Insights from a Julia Developer by jampekka on Saturday October 14, 2017 @09:55AM (#15472178)
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.

Re:Some Insights from a Julia Developer by jernfrost on Saturday October 14, 2017 @08:03PM (#15475037)
I 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.

Re:Some Insights from a Julia Developer by azag0 on Saturday October 14, 2017 @10:07AM (#15472222)
One-based indexing is not a semantic issue, it's a language-design decision you may disagree with.
Re:Some Insights from a Julia Developer by PeachPlum on Saturday October 14, 2017 @10:18AM (#15472259)
Julia 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/

Re:Some Insights from a Julia Developer by wtetzner on Saturday October 14, 2017 @12:30PM (#15472897)
Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration.

-Stan Kelly-Bootle

Re:Some Insights from a Julia Developer by attractivechaos on Saturday October 14, 2017 @10:25AM (#15472291)
That is an ugly hack, mainly because it was not in the original language design.
Re:Some Insights from a Julia Developer by ChrisRackauckas on Saturday October 14, 2017 @10:35AM (#15472335)
it 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) 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.

Re:Some Insights from a Julia Developer by pjmlp on Saturday October 14, 2017 @10:29AM (#15472308)
Why ugly? It looks similar to what I know in the Pascal family, where indexes can be ranges or enumerations.
Re:Some Insights from a Julia Developer by attractivechaos on Saturday October 14, 2017 @10:57AM (#15472426)
It 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.

Re:Some Insights from a Julia Developer by ChrisRackauckas on Saturday October 14, 2017 @11:09AM (#15472488)
1) 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.

Re:Some Insights from a Julia Developer by ChrisRackauckas on Saturday October 14, 2017 @11:51AM (#15472671)
@attractivechaos I don't know how to reply to your last reply, so I'll do it here. 1:length(A) is bad because it's using a standard construction for intervals of numbers, but using it for indices. We don't want to get rid of it because 1:5 or 0:0.2:1 is something that is very common and necessary, but I don't see how to tell one that they should instead use eachindex(A) except through proper docs. 1:length(A) is so common in MATLAB though that I am sure people will carry it over, and I'll PR to their library to fix it. I'm not sure how to fix a knowledge issue like that.

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.

Re:Some Insights from a Julia Developer by conistonwater on Saturday October 14, 2017 @02:56PM (#15473609)
You can click on the timestamp, and there will be a reply link there. I think reply links are hidden for a little bit of time after posting, but I'm not sure why.
Re:Some Insights from a Julia Developer by pygy_ on Saturday October 14, 2017 @04:57PM (#15474258)
This is an anti-flame war feature, designed to let people cool off before replying (fast paced discussions were often contentious before that was introduced).
Re:Some Insights from a Julia Developer by attractivechaos on Saturday October 14, 2017 @05:31PM (#15474425)
I guess so. This is a well thought feature. I like it.
Re:Some Insights from a Julia Developer by attractivechaos on Saturday October 14, 2017 @11:29AM (#15472581)
On 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.

Re:Some Insights from a Julia Developer by mkborregaard on Saturday October 14, 2017 @11:43AM (#15472641)
The `length(linearindices)` and no `size` etc are for a short transitory period while packages are ported to the indexing-based-non-reliant framework.
Re:Some Insights from a Julia Developer by mkborregaard on Saturday October 14, 2017 @11:41AM (#15472631)
One of the most mindboggling thing about the recurrent 0- vs 1-based indexing discussion is how incredibly rarely that difference is ever used programmatically in Julia. Most of the large julia packages are programmed in a way that doesn't care whether the array is 0 or 1 based. It is important in some other languages, and then I just think people are happy that this is something that everybody can agree to disagree on. I don't think the discussion is very productive though.
Re:Some Insights from a Julia Developer by attractivechaos on Saturday October 14, 2017 @06:25PM (#15474669)
Hmm... I wanted to learn more about 0-indexed arrays, but after looking around, I still have not figured out how to declare 0-indexed arrays without extending the AbstractArray interface or using another package.
Re:Some Insights from a Julia Developer by disconnected on Saturday October 14, 2017 @11:03AM (#15472454)
I 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).

Re:Some Insights from a Julia Developer by pvg on Saturday October 14, 2017 @11:29AM (#15472576)
Zero based indexing is not a C artifact. Here's Dijkstra writing about it in '82:

https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E...

Re:Some Insights from a Julia Developer by Bromskloss on Saturday October 14, 2017 @12:20PM (#15472832)
Note 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

Edit: Fixed link. Hacker News apparently doesn't understand the delimiting of a URL with "<" and ">". >-( https://tools.ietf.org/html/rfc3986#appendix-C

Re:Some Insights from a Julia Developer by Avshalom on Saturday October 14, 2017 @03:21PM (#15473733)
There'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/

Re:Some Insights from a Julia Developer by Bromskloss on Sunday October 15, 2017 @01:35AM (#15476053)
> 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?

Re:Some Insights from a Julia Developer by CyberDildonics on Sunday October 15, 2017 @07:26AM (#15476703)
In C arrays are given an offset to the pointer, not an index, that is why they start at 0.
Re:Some Insights from a Julia Developer by pjmlp on Saturday October 14, 2017 @10:11AM (#15472235)
Which 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.

Re:Some Insights from a Julia Developer by goatlover on Saturday October 14, 2017 @09:36PM (#15475392)
Like every other language-design decision?
Re:Some Insights from a Julia Developer by improbable22 on Saturday October 14, 2017 @10:48AM (#15472389)
What 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.

Re:Some Insights from a Julia Developer by jampekka on Saturday October 14, 2017 @11:27AM (#15472571)
I 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.

Re:Some Insights from a Julia Developer by noobhacker on Saturday October 14, 2017 @11:53AM (#15472679)
Could 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.
Re:Some Insights from a Julia Developer by sin7 on Saturday October 14, 2017 @12:18PM (#15472818)
I 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.
Re:Some Insights from a Julia Developer by icebraining on Saturday October 14, 2017 @12:40PM (#15472947)
I don't use R, so I thought you were referring to dynamic scoping, which I do think it's horrifying.

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.

Re:Some Insights from a Julia Developer by ACow_Adonis on Saturday October 14, 2017 @06:52PM (#15474756)
R documentation and users SAY that R has lexical scoping, which can be really confusing for people reading about the topic.

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"

Re:Some Insights from a Julia Developer by kazinator on Sunday October 15, 2017 @08:43PM (#15480153)
A search through linked environment objects corresponding to nested lexical scopes is a valid, correct implementation of lexical scoping.

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.)

Re:Some Insights from a Julia Developer by jampekka on Saturday October 14, 2017 @12:50PM (#15472988)
R uses a "sort of" lexical scoping which causes some "interesting" things. Eg a symbol may be simultaneously in global and local scope within the same function, which can be (ab)used to create a variable that's randomly scoped[0]. I'd say this is sort of a "dynamically lexical scope".

[0] http://andrewgelman.com/2014/01/29/stupid-r-tricks-random-sc...

Re:Some Insights from a Julia Developer by kazinator on Sunday October 15, 2017 @08:52PM (#15480179)
The article is not convicing me that the language is obeying any poorly designed requirements.

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).

Re:Some Insights from a Julia Developer by icebraining on Saturday October 14, 2017 @01:13PM (#15473097)
Ah, fair enough, that's definitively weird.
Re:Some Insights from a Julia Developer by noobhacker on Thursday October 19, 2017 @01:54AM (#15505739)
Sorry for being obtuse, but doesn't Python do the same thing? I just tried in ipython

  y = 2
  def mult(x):
      return x * y

  mult(6) # returns 12
Re:Some Insights from a Julia Developer by sin7 on Saturday October 14, 2017 @11:00AM (#15472440)
R had changed a ton in the last three years. It's pretty clean these days.
Re:Some Insights from a Julia Developer by baldfat on Saturday October 14, 2017 @11:10AM (#15472490)
I 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.

Re:Some Insights from a Julia Developer by Bromskloss on Saturday October 14, 2017 @11:40AM (#15472630)
> 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?

Re:Some Insights from a Julia Developer by dnautics on Saturday October 14, 2017 @11:18PM (#15475707)
Enumeration should generally begin at 1. In common language, you don't say "this person won the 0th place trophy", you say "this person won the 1st place trophy". It's address offsetting that should begin at 0.

C strongly encourages you to think of arrays as simply address+offset pointers, so it absolutely should start with 0.

Re:Some Insights from a Julia Developer by Bromskloss on Saturday October 14, 2017 @11:38PM (#15475755)
> you don't say "this person won the 0th place trophy"

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!)

Re:Some Insights from a Julia Developer by goatlover on Sunday October 15, 2017 @12:41AM (#15475918)
If some told me they got the "0th place trophy", I would take that to be a colorful way of saying they didn't win anything, as 0 means nothing, or the absence of trophies, in this case.
Re:Some Insights from a Julia Developer by Bromskloss on Sunday October 15, 2017 @01:19AM (#15476023)
That's just an artefact of being used to a certain way, isn't it? For me, it's about finding fundamental reasons for one convention or another, not about the practicalities.
Re:Some Insights from a Julia Developer by goatlover on Sunday October 15, 2017 @01:52AM (#15476085)
The reason for not starting at zero for enumeration is that zero means a lack of things to count or list. Therefore, we should start with the one, since that's the first number where we would have reason to enumerate.
Re:Some Insights from a Julia Developer by dnautics on Monday October 16, 2017 @04:00AM (#15481577)
Why not say someone won the -1th place trophy? Where does it start?
Re:Some Insights from a Julia Developer by goatlover on Saturday October 14, 2017 @09:40PM (#15475405)
I start counting at 1 for everything when not programming, so I don't understand this. I always understood zero-based indexing to be primarily a hardware driven concern, with C being fairly close to assembly, and so many languages ended up copying C's syntax.
Re:Some Insights from a Julia Developer by baldfat on Saturday October 14, 2017 @12:40PM (#15472946)
> 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.

Re:Some Insights from a Julia Developer by baldfat on Saturday October 14, 2017 @06:54PM (#15474769)
Also 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!

Re:Some Insights from a Julia Developer by Bromskloss on Saturday October 14, 2017 @07:36PM (#15474929)
Is 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?
Re:Some Insights from a Julia Developer by Bromskloss on Sunday October 15, 2017 @12:06AM (#15475839)
Actually, 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

Re:Some Insights from a Julia Developer by goatlover on Saturday October 14, 2017 @09:36PM (#15475390)
What's wrong with the syntax? I think Julia has really nice syntax.