Hacker Newsnew | past | comments | ask | show | jobs | submit | bouchard's commentslogin

> Yes 1-based indexing is a mistake. It leads to significantly less elegant code - especially for generic code - and is no harder to understand than 1-based indexing for people capable of programming.

Some would argue that 0-based indexing is significantly less elegant for numerical/scientific code, but that depends on whether they come from a MATLAB/Fortran or Python/C(++) background.

A decision was made to target the MATLAB/Fortran (and unhappy? Python/C++) crowd first, thus the choice of 1-based indexing and column-major order, but at the end of the day it's a matter of personal preference.

0-based indexing would have made it easier to reach a larger audience, however.

> and is no harder to understand than 1-based indexing for people capable of programming.

The same could be said the other way around ;-)


The 0 or 1 based indexing is actually a very superficial debate for people not very familiar with Julia. Note that 1-based indexing is a standard library feature not inherent to the Julia language itself.

The real indexing issue is whether arbitrary-base abstraction is too easily available.

    # Correct, Vector is 1-based
    function mysum(v::Vector{T}) where {T <: Integer}
        s = zero(T)
        for i in 1:length(v)
            s += v[i]
        end
        return s
    end

    #Incorrect, AbstractVector is not necessarily one based
    function mysum(v::AbstractVector{T}) where {T <: Integer)
        s = zero(T)
        for i in 1:length(v)
            s += v[i]
        end
        return s
    end

    #Correct
    function mysum(v::AbstractVector{T}) where {T <: Integer)
        s = zero(T)
        for e in v
            s += e
        end
        return s
    end
Basically, the concrete `Vector` type is 1-based. However, `AbstractVector` is could have an arbitrary first index. OffsetArrays.jl is a non-standard package that provides the ability to create arrays with indexes that can start at an arbitrary point including 0.


Aside from the fact that 1-based indexing is better for scientific code (see Fortran), I don’t think that it matters very often. I don’t think that any Julia program I’ve ever written would need to change if Julia adopted 0-based tomorrow. You don’t typically write C-style loops in Julia; you use array functions and operators, and if you need to iterate you write `for i in array ...`. If you really need the first or last element you write `a[begin]` or `a[end]`.


> the fact that 1-based indexing is better for scientific code (see Fortran)

It really isn't. "Scientific code" isn't some separate thing.

The only way it can help is if you're trying to write code that matches equations in a paper that uses 1-based indexing. But that very minor advantage doesn't outweigh the disadvantages by a wide margin. Lean doesn't make this silly mistake.

> If you really need the first or last element

What if you need the Nth block of M elements? The number of times I've written arr[(n-1)m+1:nm] in MATLAB... I do not know how anyone can prefer that nonsense to e.g. nm..<(n+1)m


What if I want the nth element up to the math element? arr[n:m]. And if I want to split the array into two parts, one until the nth element and the other from the m+1st element arr[1:m] and arr[(m+1):end]. Julia matches how people speak about arrays, including C programmers in their comments. Arrays are (conceptually) not pointer arithmetic. Also for your usecase typically you would just use a 2d array and write a[n,:].


> arr[n:m]

arr[n..=m]

> arr[1:m] and arr[(m+1):end]

arr[0..m], arr[m..]

Much nicer.

> Arrays are (conceptually) not pointer arithmetic.

Look at a ruler. Does it start at 1?


> arr[n..=m]

so you just need to overload the syntax of intervals even more to make it work

> arr[0..m], arr[m..]

now `m` refers to different things depending on which side of the interval it's on. less characters doesn't mean nicer

I get it though, I was skeptical about 1-based indexing when I started Julia. By the nature of indices vs length there will always be an off-by-one problem: either you have elements [n, m - 1] with length (m - n) or [n, m] with length (m - n + 1). Unless you're doing a bunch of pointer arithmetic type stuff, I find the symmetry of a inclusive-inclusive interval to be a better default.

As a final rebuttal I offer: range(n - 1, -1, -1)


Your second point is the main argument for me personally. Numbers in brackets always mean the same thing: the ordinal number of the references object in an ordered collection. In 0 based indexing you can think of the number as refering to the space between the referenced objects. But that is simply an additional mental image on top of the original one.

As a neat bonus, in Julia 1:5 is just the iterator for the numbers 1 to 5. So slicing is typically not some special syntax either. It all works rather nicely.


So if I have a row of 5 apples, I can say "take the second and third apple" or I can say "take the apples between one apple length and three apple lengths from the start".

Which is more natural? The ruler is exactly the right mental image if an array to you is a partitioned region of memory starting at a specific pointer location. If an array to you is an ordered collection of objects, you would never invent 0-based indexing or inclusive-exclusive slicing.

Either way, it's not a big deal. I have lived in both worlds, I have come to think Julia is a bit more natural and easier to teach. But it ls really the silliest bike shedding complaint, given that the language has considerable real trade offs.


This is such a classic example of online discourse in general. There are two options, and folks tribally cling to one or the other without realizing that both are legitimate and well-suited for different situations.

Yes, of course distances are measured starting from 0. But we count discrete things starting at 1. You can do mental gymnastics to enumerate from zero and many programmers are (unfortunately IMO) taught to do so. It's a hard thing to learn that way, so for the folks that have done so, it often becomes a point of pride and a shibboleth.

As a classic example, a four story building has four floors. But you only need to go up three flights to get to the top. You can legitimately call the top floor either 3 or 4, and folks are similarly tribal about their own cultural norms around this one, too.


> There are two options, and folks tribally cling to one or the other without realizing that both are legitimate and well-suited for different situations.

No I disagree entirely. One is simply better.

> It's a hard thing to learn that way, so for the folks that have done so, it often becomes a point of pride and a shibboleth.

It is not hard. It's not better because it's hard-won knowledge. It's better because it leads to simpler, more elegant code. Simple as.


Thanks for proving my point perfectly.


Fully agreed. I first struggled when switching from python to Julia, then ended up finding it slightly better for my use cases (which includes teaching scientists who are not programmers). But it's simply not a big deal either way. I am also reminded of the significant whitespace objections to python in the old days, before python took over everything...


>It really isn't.

They way people reveal themselves is a pattern worthy of taking note.


> Aside from the fact that 1-based indexing is better for scientific code

I find it to be substantially worse. It's fine as long as you don't manipulate the indicies. But as soon as you start doing math on them 1 based becomes a headache (at least IME).

Meanwhile all you get in exchange (at least as far as I can tell) is ease of speaking about them in natural language. But I'm not usually conversing about indicies.

Concise range notations are a mixed bag. There's pros and cons to either scheme there as far as the syntax goes.


Heh. I grew up writing C code and had real trouble adapting to Matlab's 1-based indexing. Much later I tried Python and was constantly confused by 0-based indexing.

I don't think one is better than the other but my mind is currently wired to see indexing with base 1.

Then there's Option Base 1 in VBA if you don't like the default behavior. Perfect for creating subtle off-by-one bugs.


The approach could be helpful for searching though large 3D model libraries like GrabCAD for some visual placeholder part by just describing it.

The generality of the part descriptions made me chuckle.

> A bevel gear with a circular base and a series of angular, tapered teeth extending radially outward. The teeth are uniformly distributed around the circumference, allowing for meshing at an angle with another gear. The gear's face includes a set of holes, varying in size and symmetrically arranged around the central bore, likely for weight reduction or mounting purposes. The central opening likely acts as an axle or shaft attachment point. The design facilitates the transmission of rotational motion between intersecting shafts, typically at a 90-degree angle.


This is a about Groq, not Grok (Musk's chatbot).


mea culpa!


Comments on the claims made by Penn State's PR department in "Student refines 100-year-old math problem, expanding wind energy possibilities"

> https://news.ycombinator.com/item?id=43162544


Depends if you make overly conservative assumptions in your modeling...


If you have simulations with varying levels of optimism, but all of them were too conservative, then you screwed up.


Meh, depends what's the goal. Exceeding predicted performance is not a screw up, it's just providing a minimum guaranteed performance aka playing it safe (under promise, over deliver).

Also, we don't know by how much the most optimistic predicions were exceeded.

Makes for nice marketing ;)


Using greek symbols as public-facing function arguments, etc. is definitely not recommended, and not that common (at least in my experience).

It's best used for internal calculations where the symbols better match the actual math, and makes it easier to compare with the original reference.


Never thought I'd see the name LimeWire again, wow


Haha interesting pivot!


Looking at interview footage of Stockton Rush, it seems he really wanted to be a disruptor and accomplish something which everyone else (i.e., experts) deemed impossible. He thought he could do what SpaceX did for space, but for underwater exploration.


> He thought he could do what SpaceX did for space

Even SpaceX, with unlimited resources, tried carbon fibre, couldn't get it to work, and switched to stainless steel. Different application but still. It's not a budget material.


Problem is anyone can make a boat and kill themselves in it. Hard to hide a Falcon 9 rocket and get astronauts to go on it. It's highly regulated. You can put anyone on a dingy in the ocean and die.


Rush could be placed in Wikipedia under hubris.

His hubris killed people. He ignored experts. He ignored warnings. This outcome was predictable.


The problem is that SpaceX was told the same and it succeeded despite the ods. History is harsh to people who fail.


SpaceX did not send manned missions for a while.

If the hull failed without people it would be no big deal. However, Rush was running out of money so he felt rushed and got reckless.


That's every startup founder to an extent.

What differentiates a good founder from a bad one is being right.


This is a weird way to think of it, making it seem as thought its just a matter of chance whether the founder is right or not. The difference, if there is one, is that some founders can pivot when they see their approach won't work or, at least, throw in the towel before people die or too much many is wasted.

Maybe that makes them bad startup founders? I don't know. In my opinion "Startup Founder" is a role which should play second to "ethical human being."


Nah, it is about finding ways to fail an experiment without failing the whole business, bonus points for not killing anyone in the process.


The Netflix documentary has some extra interviews with employees, clients, etc. which are interesting. (1hr 51min runtime though)



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: