Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> they are all conventions, after all

If we discovered aliens and learned their programming languages, which is more likely: That they use 0-based arrays, or 1-based arrays?



It is ludicrously unlikely that aliens would be comprehensible at all. Several of Lem's SF novels try to get this idea across, Solaris is most famous, though I'm more of a Fiasco person myself. An octopus is very closely related to you, far more so than any conceivable space aliens - and yet we have no idea what the fuck is going on in there. When you look at an octopus in an aquarium is the octopus wondering whether you are self aware?

We have assumed that aliens would do arithmetic, because we do arithmetic, and it seems very fundamental to us, but that might just be a matter of perspective. So the aliens might have no use for programming languages, or their languages might have no more built-in concept of "0-based arrays" than our languages have of "Happiness versus sadness".


> An octopus is very closely related to you, far more so than any conceivable space aliens - and yet we have no idea what the fuck is going on in there.

If octopuses really are so closely related, why can't I see any sort of large structures or societies or vehicles or weapons created by them? They're a plateau'd species leeching off the planet barely surviving in the balance of nature, like pretty much every species except humans.


> They're a plateau'd species leeching off the planet barely surviving in the balance of nature, like pretty much every species except humans.

That is a ghost pepper spicy take.

In what way does any species plateau? An extant species is either a) Going extinct, b) Well adapted to its environment, or c) Adapting to evolutionary pressures through natural selection.

Instead of "leeching" I would describe them as living in symbiosis with their ecosystem.

Instead of "barely surviving in the balance of nature" I would describe them as... well, surviving. And that against the onslaught of the Anthropocene.

I like humanity as much as the next guy but your comment has a stunning degree of anthropocentrism.


I interpreted their comment a different way. They're raising a question I've always wondered...

Why are humans the only species to have reached such an incredible level of intelligence relative to all the other species on the planet?

Every other creature has plateaued in intelligence. Some are more intelligent than others, but have any of them even learned to create tools beyond bashing things with rocks and sticks? Have any learned to build things beyond a basic nest? None of them have even learned language beyond a few basic noises or bits of body language to express aggression, submission, and maybe happiness.

The usual answer is "Humans are the only species where learning these gave an advantage", but I think that's hogwash. Imagine how much more successful a prey species could be if they had better ways to communicate that they spotted a predator nearby, or even what a predator looks like.


> Every other creature has plateaued in intelligence

This is just not how evolution works. If you're curious about phenomena such as you're describing, I encourage you to dig into evolutionary biology.

It's more correct to say "we don't know of any creatures living or extinct that have a similar development of linguistic / symbol manipulation as modern humans".

This acknowledges that we don't know the intelligence of every species to have existed on earth. The earth is billions of years old. Quite literally, in that time span, species could have developed advanced civilizations, gone extinct, and left no evidence of themselves that we're currently capable of perceiving as such.

It also acknowledges that, unlikely as it seems, we don't know of any living species with similar intelligence to us. Since that quickly descends into sci-fi territory, I'll leave it there.

Finally, it acknowledges that at any point in the future, other creatures could evolve intelligence similar to us.

It strikes me that my whole disagreement with you hinges on the word "plateaued". In common parlance this means "has developed to a point of permanent stagnation". In evolution nothing is Permanently stagnant, thus my previous comment.

> "Humans are the only species where learning these gave an advantage"

This is another point that a deeper dive into evolutionary studies will illuminate.

Humans are the only extant species that we know of where selection pressure met a series of mutations for increased intelligence, and the cost/benefit equation worked out for the species and environment.


> Why are humans the only species to have reached such an incredible level of intelligence relative to all the other species on the planet?

Maybe they went extinct shortly after attaining similar technological levels as us, and we humans just presumed them (eg dinosaurs) to be stupid reptiles?

In fact, given that homosapiens and our close relatives roamed the earth for hundreds of thousands of years, it’s quite a spooky question to ask why only in the past couple thousand years we’ve been able to build a technologically advanced civilization.


Octopodes have short lifespans and aren't very social, otherwise I'm convinced they would have established civilization by now.


Probably 0-based? I'd assume they'd come to the same reasoning as we did, that indexing into an offset starting at zero works better for addressing memory.


We use 0-based, but we also invented the concept of 0. It's true that multiple civilizations independently invented it, but perhaps an alien civilization never invented it and got along fine without it.


Would they even have linear memory? That's a pretty big assumption. They might also have a completely different paradigm that we would never ever think of.


This would depend massively on the equally long evolutionary, cultural, and political history that they would have… just like that context is necessary to understand our own decisions. Folks assume “aliens” would be some kind of clean room, purely logical beings, but no such thing is possible and the assumption falls apart immediately.


If we discovered them, I don't know. But if they discovered us then they probably use 0-based arrays.


Right. If they used 1-based, they'd have accidentally ended up on Mars.


More likely 0-based, given our prior (n=1) that programming languages typically use 0-based indexing.


That depends. Median usage of languages over the population of devs shows that they prefer 0-based indexing. Median usage of languages across the entire population shows that they prefer 1-based indexing (Excel has more users than all other languages combined, and is a 1-based programming language).

As far as human programming languages as a population, they may tend toward 0-based because they are written by devs, who prefer 0-based. But if we're talking about aliens, are we sure that alien devs would be the ones writing programming languages? What if all aliens could code? What if their languages are expressive enough that any alien could make their own language to suit their personal preference. It's really hard to say anything here without specifying anything about the hypothetical alien species and their culture.


We’d surely discover petabytes of discussions on this and other topics mostly irrelevant to a real alien life.


With no prior knowledge of these aliens, neither. Why is 0 more special than 1 in your head?


To be fair, Zero is a thing called Additive Identity, meaning if we keep Adding it to things, we just get the same thing back. So that's special

One is the Multiplicative Identity, if we keep Multiplying things by One we get the same thing back, however that does feel less relevant to how an array works.


We've seen a lot of "drift" of different languages towards zero-based indexing, probably because it lets the compiler generate slightly simpler code.

For the same reason, we've seen architectures "drift" towards little-endian, even though it's undeniably more inconvenient to read hex dumps from little endian machines.


> probably because it lets the compiler generate slightly simpler code.

A compiler can generate the same code either way by shifting by 1 at compile time. You might have a point if you were to say "it lets the compiler be a little simpler" but in the grand scheme of things, it doesn't really simplify the compiler all that much.


> A compiler can generate the same code either way by shifting by 1 at compile time.

Shifting what by 1? Array address aren't always known at compile time. Neither are array indexes. I don't see how this could be done at compile time, in general, without a magically powerful compiler.

I think you may be imagining that in some specific scenarios, the code generation will be the same. I'm speaking about general cases--in general, in order to generate code for array access starting at 1, you have to do a little extra computation--either to subtract an offset from the pointer to the array or to subtract an offset from the index.


> subtract an offset from the pointer to the array

Yeah, you shift the array, not the index. But the instruction for accessing memory on many architectures assumes a shift, so whether it's 1 or 0, it's still just one instruction. Here's a community of programming language developers talking about exactly this question: https://www.reddit.com/r/ProgrammingLanguages/comments/x95ni...

The consensus there is: it's really not something to worry about, as it all comes out in the wash. Performance is certainly not an argument for choosing one versus the other, as there are other dimensions to the choice, like target user familiarity/comfort.


It sounds like you're definitely misunderstanding what I'm saying.

Linked thread is x86, an architecture with unusually rich addressing modes. People make compilers for all sorts of languages and architectures. The fact that in SOME cases, it's simpler not to have an offset, means that there is some pressure to use 0 as the base for your array. If you pick x86 or amd64 as your benchmark, then you're going to get a very narrow picture.

Just to pick an example, consider Arm. I'm looking at an older version of the architecture right now, but you cannot use both a register offset and an immediate offset at the same time. So if your arrays start at index 1, then you must either adjust the index or adjust the array.

Not all language designers follow the zero-overhead principle like C++ does, but you can see how this would cause some language designers to decide that 0 is a more natural array index because it results in the lowest overhead in the most scenarios (across different architectures, not just x86).

Same thing explains why little endian architectures won over big endian. Big endian is definitely more convenient to debug, it's more convenient to look at hex dumps. However, with little endian, the correspondence between memory and registers is slightly simpler. The difference is not so extreme that big endian architectures do not exist, but it is large enough that we've "drifted" into a world where big endian architectures are all but gone, and you mostly find them these days in network appliances.

And to be clear, I'm not saying that the advantage of 0-based indexes is some massive advantage that makes it a clear winner. I'm just saying that there's slight pressure to use 0-based indexes.


> If you pick x86 or amd64 as your benchmark, then you're going to get a very narrow picture.

99% of the language designers I know target x86 first and foremost. But in the given link only one person mentioned x86, while others were speaking generally and voiced an opinion that it really doesn’t matter.

I take your point that other designers might have other pressures, but the choice of 1 vs 0 in the common case (not a narrow slice as you seem to suggest) comes down to other factors. The pressure to conform to developer expectations for 0-based indexing is much greater than anything else; as demonstrated in this HN thread, some people won’t even consider using a language if it has 1-based indexing. Other communities face persistent confusion with 0-based indexing. That provides far more pressure than the ARM instruction set for language devs that I know. Maybe the ones you know feel differently.

Your point is taken on bigendian vs littlendian, but the same has not happened for indexing. Languages haven’t settle on either, but instead they have bifurcated between dev targeted versus end user targeted languages, with the former being 0 based and the latter being 1 based.




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

Search: