|
Of course, the old VB, before .NET allowed you the ability to declare it either 0 or 1. Certainly, the atrocity of declaring an array with 10 elements and getting 11, 0 thru 10, is not the way to go.
Delphi allows you to declare an array starting with the positive integer of your choice, e.g.:
var Appointments : array[3 .. 9] of Integer; which would give you seven (7) elements.
Or you could do the usual:
var Appointments : array[0 .. 6] of Integer; for seven (7) elements.
Norman E. Fisher
|
|
|
|
|
To me that makes sense. It doesn't matter what you call it as long as it has the number of elements you require?
A rose by any other name...
|
|
|
|
|
Why use anything other than 0? It always works when the iterating a range and can just use the count. I see no benefit to using arbitrary offsets. If I saw them I would assume the code was a hack job, rather than a well designed or elegant piece of code, and that the code is confusing to anyone that doesn't know the reason (which would be everyone but the author, then maybe even the author if he picked it up later).
Even if you say something like from 3..9, you still have the problem of knowing whether you are starting with the 3rd or 4th element, and ending on the 9th or 10th element. It did not solve a thing. If you don't use zero as the index, there is always some a priori knowledge of the special case that you HAVE to know or document so it is easy to see and understand, which just increases the probability of a bug.
There is nothing gained except the ability to hack and it should not be encouraged as a principle of software development. That is like encouraging people us Goto or return in the middle of a function, to me.
I think this is why there is a lack of respect for VB coders. Their language of choice encourages bad technique. I prefer the codes look and the compiler tell me if I appear to be doing something stupid with warnings, rather than just hide it in the muck of verbosity and irregularity.
Just my opinion.
|
|
|
|
|
*pArray essentially means pArray[0] . Using pArray[1] and *pArray for same thing would be inconsistent and error prone.
A loop that starts from 0 would always end up counting the elements, no +1 or -1 would be required.
When building lifts starts with 0, and almost everyone can understand it, what the problem with 0-based indexing?
|
|
|
|
|
Unfortunately there's a continent full of people who don't understand that lifts start at zero. They don't even understand that they are called lifts.
Phil
The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.
|
|
|
|
|
My experience also says something else too. People would ask for the lift to "come-down", or to "go-up". Instead of asking it to take you "where" you want to go.
For example, you are on 4th floor, want to goto ground floor, and lift is on 1st floor - they would press "UP" asking it to come up, take you. Instead of pressing "down", where you want to go!
|
|
|
|
|
Oh yeah.... I see that almost everyday and I think: "Hummm... it's gotta be the first time they are using the elevator".
If the above is true, then man, I think I'm the person who has seen the most people using the lift for the first time.
|
|
|
|
|
They left out being able to choose any positive integer for the starting index.
Still I vote for array indexes starting at zero.
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
I was *that* close to adding a "other" option on the poll.
But I knew that would just confuse the issue
cheers,
Chris Maunder
The Code Project | Co-founder
Microsoft C++ MVP
|
|
|
|
|
Only the true comedians here would have selected it.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Well the universe is homogeneous, why shouldn't be the arrays?
Yes, I'm one of the true...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
|
You can in Ada, if I remember rightly, or with a negative number, but though it seems clever when you do it, the code is unmaintainable. But that goes for Ada most of the time anyway.
------------------<;,><-------------------
|
|
|
|
|
CIDev wrote: Still I vote for array indexes starting at zero.
Surely zero is neither positive or negative.
|
|
|
|
|
Why stop with positive. Pascal let you do something like this:
Example = Array[-5..5] of Integer;
3x12=36
2x12=24
1x12=12
0x12=18
|
|
|
|
|
Ahhhhhh. I still remember my love affair with (Turbo) Pascal. What a beauty.
|
|
|
|
|
There is only one "old school" language and it ain't C or Basic
|
|
|
|
|
Nemanja Trifunovic wrote: There is only one "old school" language
Yeah! COBOL...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
OriginalGriff wrote: COBOL
COBOL is a recent fad. FORTRAN is the first real programming language.
|
|
|
|
|
Nemanja Trifunovic wrote: FORTRAN is the first real programming language.
Closely followed by Lisp.
/ravi
|
|
|
|
|
Ravi Bhavnani wrote: Closely followed by Lisp.
t
Strictly speaking, boolean literals didn't exist in original LISP
|
|
|
|
|
Ravi Bhavnani wrote: Closely followed by Lisp
What about assembler?
That's the 'real' programming language. Other are artificial; everything in them is a convention, so it is starting from 0 or 1, or ever from 2
|
|
|
|
|
Nemanja Trifunovic wrote: There is only one "old school" language and it ain't C or Basic
PL1
|
|
|
|
|
Let me whip out my punch cards here...
|
|
|
|