|
Have you read the original 1964 spec of BASIC?
|
|
|
|
|
Was there a formal spec back then or has it been written afterwards as for most languages of that time?
|
|
|
|
|
|
There we go. The index values range from 0 to (n-1), as they should. Now at which point did they start with 1? Every early home computer had a BASIC interpreter in a ROM, which in most cases was a customized Microsoft BASIC. Atari developed the BASIC from scratch, and was zero based. Look here.[^] It has been some time since I used that manual, but I should still have it somewhere.
|
|
|
|
|
You may have misread the spec; page 38 says it's 0 to n inclusive. I expect that's why so many developers chose to use 1 to n inclusive and ignore element zero.
Show me a BASIC implementation that has 1-based indices (by default). I have never encountered one.
I do see that Turbo BASIC has an OPTION BASE statement that allows a developer to choose to differ from the default of zero. Turbo BASIC also extends the DIM statement to allow the developer to specify a range, similar to Pascal -- DIM b(50:60) . But the default behaviour is for 0 to n inclusive.
|
|
|
|
|
PIEBALDconsult wrote: 0 to n inclusive
Ok, but what's the reasoning behind that? You dimension an array to n elements and get an array with n + 1 elements.
This really is interesting. Back in the day I did not use BASIC very much. The interpreters were too slow, especially for graphics. When finally a C compiler fell into my hands (on the Atari ST), I never looked back. The whole thing sounds like a misunderstanding that came when everyone and their dogs started to write BASIC programs on their TRS-80s or later on their C64s.
|
|
|
|
|
CodeWraith wrote: You dimension an array to n elements
No, you dimension it for n+1, as per the spec.
|
|
|
|
|
DIM X(5)
n=5, so our array now should have six elements, indexed 0 - 5. Strange way of sying that you want six eggs, but ok. At least we use the same value to dimension the array and the highest valid index. In the end it is a just a question of specifications and conventions. However, the original problem was at the beginning of the array. Of course we could access the array with 1 - 6, but that would be even more confusing.
So, where do you think the habit to dimension the arrays one element too large, accessing them with 1 to n and wasting element 0 came into play?
I need a perfect, to the point answer as I am not aware of this.
Please don't reply explaining what method overloading is
|
|
|
|
|
Designers were ahead of their time maybe. And early practitioners weren't smart enough to grok the concept.
It reminds me of strings in Pascal -- you get a maximum of 255 characters preceded by how many characters are currently in the string.
'Tis possible that BASIC's designers had expected developers to use the zeroth element to hold the count of how many elements are in use.
|
|
|
|
|
I would tell you what the zeroth. finger is, but, I don't think you are ready, yet.
«Differences between Big-Endians, who broke eggs at the larger end, and Little-Endians gave rise to six rebellions: one Emperor lost his life, another his crown. The Lilliputian religion says an egg should be broken on the convenient end, which is now interpreted by the Lilliputians as the smaller end. Big-Endians gained favor in Blefuscu.» J. Swift, 'Gulliver's Travels,' 1726CE
|
|
|
|
|
|
To me, as a mathmatically inclined person, it really hurts taking the elevator in our new office building down to the basement: It goes: 4, 3, 2, 1, -1 ...!!! HEY! You dropped something! There is supposed to be something in between there!
I am equally upset about Christian churches - I don't know if it applies to all, but at least the Protestants in Europe and the Catholics officcialy number years "..., -2 (i.e 2BC), -1, +1, +2...). There are years before Christ and years after Christ, but no year "of Christ", i.e. the year of of his birth. This hurts my mathematical feelings.
|
|
|
|
|
Year Zero is a also a Leap Year.
|
|
|
|
|
Member 7989122 wrote: It goes: 4, 3, 2, 1, -1
It says "-1"? That would confuse a lot of people.
|
|
|
|
|
It does. This is not a new independent building, but a new wing. The elevators in the old wings go 4, 3, 2, 1, U - the U is for "underetasje", or "sub-floor". (For buildings having two basement levels, it is common to label them U1 and U2.)
I guess that the reason why they changed it is that we have a large fraction of foreign employees who don't speak Norwegian, so the management (or elevator constructor?) wanted something language independent. You could say that "U" indicateds "underground", but even an English based abbreviation is sort of language dependent . Sure, almost everybody around has at least some understanding of English, but sometimes very little and limited to professional job terms; in the elevator their mind is never tuned in to English. A U is about as good as a Chinese ideograph - just some blurb that makes little sense except symbolizing the basement level.
|
|
|
|
|
Lopatir wrote: who counts anything from zero?
Err...computer scientists do. Because it isn't a count, but a pointer.
|
|
|
|
|
Lopatir wrote: who counts anything from zero?
Everybody, but many don't realize it. Zero is a perfectly good value for counting. For instance, there are zero elephants in this room.
Whenever you count something you always start with zero, then you count the first item as one. It's just so intuitive, you don't really think about it.
|
|
|
|
|
CodeWraith wrote:
Variants, anybody?
they're called "var", in C#
|
|
|
|
|
They are not the same thing, but I still don't like them at all. I prefer code that's readable without the help of costly tools like Visual Studio or Intellisense.
|
|
|
|
|
|
Quote: costly tools like Visual Studio or Intellisense. I use the community edition of VS 2015 at home for free and it has intellisense built it for free.
Did I mention it was free? Not costly at all.
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
Don't call Rome just yet. The Microsofties may all be absolutely selfless may have performed enough miracles, but they have to be dead to be made saints by the Pope.
Personally, I have already moved on and would not want to invest any time or money in Microsoft anymore. There are far more interesting things to do than keeping up with their escapades.
|
|
|
|
|
No, they're called dynamic in C#.
Using var , your variable is still strongly-typed; you're just letting the compiler work out what that type is.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Oh, you mean boxing? Because that is exactly what VARIANT does in COM and VB....
|
|
|
|
|