Click here to Skip to main content
15,898,588 members

Survey Results

Should array indexing start at 0 or 1?   [Edit]

Survey period: 7 Mar 2011 to 14 Mar 2011

Old school VB devs and old school C devs know the answer. What's your feeling in this modern, enlightened era?

OptionVotes% 
01,11587.93
115312.07



 
GeneralI understand zero is better for computers... Pin
JChrisCompton14-Mar-11 11:35
JChrisCompton14-Mar-11 11:35 
GeneralRe: I understand zero is better for computers... Pin
Klaus-Werner Konrad6-Jun-11 14:02
Klaus-Werner Konrad6-Jun-11 14:02 
GeneralRe: I understand zero is better for computers... Pin
JChrisCompton7-Jun-11 11:54
JChrisCompton7-Jun-11 11:54 
GeneralTrivial Point with Option Base Pin
CaWxMan14-Mar-11 9:50
CaWxMan14-Mar-11 9:50 
GeneralRe: Trivial Point with Option Base Pin
Klaus-Werner Konrad14-Mar-11 10:46
Klaus-Werner Konrad14-Mar-11 10:46 
GeneralRe: Trivial Point with Option Base Pin
Colin Mullikin6-Jun-11 10:56
professionalColin Mullikin6-Jun-11 10:56 
GeneralRe: Trivial Point with Option Base Pin
Klaus-Werner Konrad6-Jun-11 13:52
Klaus-Werner Konrad6-Jun-11 13:52 
GeneralRe: Trivial Point with Option Base Pin
Colin Mullikin7-Jun-11 4:03
professionalColin Mullikin7-Jun-11 4:03 
GeneralRe: Trivial Point with Option Base Pin
yakshasa15-Mar-11 5:19
yakshasa15-Mar-11 5:19 
GeneralWell... Pin
Lutosław12-Mar-11 1:15
Lutosław12-Mar-11 1:15 
JokeIt should start from sqrt(-1) in a high-level programming language. PinPopular
S. Fischer11-Mar-11 2:03
S. Fischer11-Mar-11 2:03 
GeneralRe: It should start from sqrt(-1) in a high-level programming language. Pin
Emilio Garavaglia13-Mar-11 21:26
Emilio Garavaglia13-Mar-11 21:26 
GeneralThe real answer is 42 PinPopular
Yusuf10-Mar-11 17:29
Yusuf10-Mar-11 17:29 
GeneralRe: The real answer is 42 Pin
Toniyo Jackson10-Mar-11 23:57
Toniyo Jackson10-Mar-11 23:57 
GeneralRe: The real answer is 42 Pin
Ed Nutting11-Mar-11 8:31
Ed Nutting11-Mar-11 8:31 
GeneralRe: The real answer is 42 Pin
567890123411-Mar-11 2:48
567890123411-Mar-11 2:48 
GeneralNot just in computing PinPopular
Kamran Behzad10-Mar-11 17:01
Kamran Behzad10-Mar-11 17:01 
GeneralRe: Not just in computing Pin
xawari11-Mar-11 9:57
xawari11-Mar-11 9:57 
GeneralRe: Not just in computing Pin
Emilio Garavaglia13-Mar-11 21:23
Emilio Garavaglia13-Mar-11 21:23 
AnswerRe: Not just in computing Pin
JChrisCompton14-Mar-11 11:50
JChrisCompton14-Mar-11 11:50 
GeneralBe practical - do what comes naturally Pin
Kamran Behzad10-Mar-11 12:12
Kamran Behzad10-Mar-11 12:12 
As someone suggested it is a religious war. But maybe here is a way to peace.

Here is a scenario:
You load a date value from your DB. Then you want to display an image depending on the month value. So you use something like image[month], month being derived from your date value. Alas you get an error on image[12] and you realise despite voting for zero-based arrays on CodeProject, and implementing such in your code, your evolutionary past has made you make an off-by-one error. Your computer counts the months from 0 to 11 but you do from 1 to 12. And no matter how hard you try, after decades of programming, you cannot not make these mistakes.

So what do you do, Either of two things:
1) Waste image[0] and use image[1] to image[12]
2) Modify your reference in code to read: image[month-1]

Are 90% of voters telling me they prefer not wasting memory (of what could be as little as one byte), instead preferring to have the additional subtraction in their code?

I prefer to sacrifice element 0 for clarity in my code, not to mention saving the extra subtraction operation.

Having said that, as pointed out by many others, many representations require us to also be able to represent absence of something, such as a primary color in a color combination. We simply cannot do without a zero index there.

So, my conclusion: let's put our religious preferences aside. In each case do what is practical and comes more naturally.
GeneralRe: Be practical - do what comes naturally Pin
Jay Gatsby11-Mar-11 22:56
Jay Gatsby11-Mar-11 22:56 
GeneralRe: Be practical - do what comes naturally Pin
PJ Arends12-Mar-11 6:14
professionalPJ Arends12-Mar-11 6:14 
GeneralRe: Be practical - do what comes naturally Pin
Jay Gatsby14-Mar-11 15:13
Jay Gatsby14-Mar-11 15:13 
GeneralRe: Be practical - do what comes naturally Pin
Mr Nukealizer13-Mar-11 12:54
Mr Nukealizer13-Mar-11 12:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.