Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: I prefer my indexes to start at:

by mandarin (Hermit)
on Sep 02, 2022 at 13:14 UTC ( [id://11146634]=note: print w/replies, xml ) Need Help??


in reply to I prefer my indexes to start at:

No sane person starts counting in "real life" at 0, so why should my indexes do so? I stongly suspect that C's idiocy of starting at 0 is the number one cause for off-by-one errors and resulting segfaults, buffer overflows, etc.

Replies are listed 'Best First'.
Re^2: I prefer my indexes to start at:
by Perlbotics (Archbishop) on Sep 02, 2022 at 19:05 UTC

    Pointer arithmetic and calculation of memory addresses, esp. for arrays, becomes easier when starting index is zero.

Re^2: I prefer my indexes to start at:
by NERDVANA (Deacon) on Sep 06, 2022 at 23:31 UTC
    Depends whether you need your first fence post at "zero feet from the wall". ;-)

      Are you attaching your fencing directly to the wall? If not, you need a post there to support it.

Re^2: I prefer my indexes to start at:
by ninto1 (Novice) on Sep 05, 2022 at 13:31 UTC

    Isn't it more efficient in binary?

    Example for 4 bit:

    0000 = 0

    0001 = 1

    0010 = 2

    -...

    And starting at 1 would waste the 0000 state. I think this is why starting at 0 is the more natural way to count in basic electronics in my opinion, which is how I think it made its way into C.

    Nowadays it is almost obsolete, but changing so old standards can often be hard to become used to for expierienced programmers, and those mistakes mostly just happen to novice ones, who are not the ones designing new languages.

    Hope I could make you see another side of this debate.

    Greetings, Ninto

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11146634]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2024-04-23 12:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found