Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 1
    $\begingroup$ BCPL, where zero-based indexing probably originated, didn't initialize variables. So that's hardly the right justification. Also, integers don't start at 0. Integers don't have a start. As for a default in your favorite language (if it even has one), that's entirely arbitrary - zero is convenient in pre-zeroed memory, but before modern memory management, there were no definite default values. A pretty common practice is to always initialize variables with a meaningful value, rather than some "whateverdefault" - e.g. if you want a control variable that counts down, initialize it with count. $\endgroup$ Commented Sep 13, 2018 at 10:45
  • $\begingroup$ @Luaan Yeah, this is what I meant by saying that it's arbitrary. I don't agree with BCPL as the origin. In asm when you think of a memory area as an array, you index it with addr+(0*stride), addr+(1*stride), etc $\endgroup$ Commented Sep 18, 2018 at 8:12
  • $\begingroup$ In assembly, you didn't have any abstraction (at first). Indexing an array is already an abstraction - it's a map between "I want the 3rd element of the array" and what's actually needed to get that particular element. The fact that you don't need to know the element size in BCPL (or anything else about the array) is a big difference. Indeed, in assembly, you'd often see very complicated addressing patterns that were tailored to the capabilities of the hardware, rather than the logical structure of the program; in C, if you wanted the next element, you did element++. $\endgroup$ Commented Sep 18, 2018 at 11:10
  • $\begingroup$ Now, it's true that in C, that actually was a low-level pointer operation. But that's not the purpose of it, that's just a constraint to make the compiler simpler. The meaning is still "the next element" or "the 3rd element", not "pointer + 0x12". C is a rather bare language, but it's still way above the abstraction of then-assembly. Meanings started to creep into things that used to be pure procedural code. Of course, it couldn't compare to anything like LISP - the ties to hardware were far too strong for that. But there were things like 0 as pointer value, or what i++ means. $\endgroup$ Commented Sep 18, 2018 at 11:13
  • $\begingroup$ @Luaan This is why I wrote "when you think of a memory as an array". It doesn't matter if the abstraction is a part of a language or your train of thought. BCPL built up on established standards of thinking about a program. I don't really get where are we going, because I feel like you're restating my concepts but phrase them like counter-arguments. If you believe that my answer can be improved, then it appears you need to be more specific. $\endgroup$ Commented Sep 18, 2018 at 12:12