this post was submitted on 15 Sep 2023
391 points (93.5% liked)

Programmer Humor

19747 readers
33 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 58 points 1 year ago (11 children)

Are you indexing your fingers or counting them ?

Indexing starts ar 0 but counting starts at 1.

[–] FriendOfElphaba 27 points 1 year ago (10 children)

This.

One of the reasons indexing starts at zero is because back when we used to use pointers and memory addresses, the first byte(s) of an array were at the address where the array was stored. Let’s say it is at 1234. If it was an array of bytes, the first data element was at 1234, or 1234 + 0. The second element would be at 1235, or 1234 + 1. So the first element is at location 0 and the second at location 1, where the index is actually just an offset from the base address. There may be other/better reasons, but that’s what I was taught back in the 90s.

Counting always starts at 1 (if we’re only using integers). You don’t eat a hamburger and say you ate zero hamburgers.

[–] [email protected] 5 points 1 year ago (4 children)
[–] FriendOfElphaba 3 points 1 year ago (1 children)

Perchance programming with pointers has plunged as a percentage of programmers.

But thank you. I was hoping someone would notice that.

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago) (1 children)

Well, you don’t really see many people accessing lists with pointers directly. Also 0-indexing does give us an extra number to index with(say 1-255 vs 0-255)

Edit: 0-255, not 0-256

[–] FriendOfElphaba 1 points 1 year ago (1 children)

It’s 0-255 when you’re indexing like that. 11111111b = 255.

[–] [email protected] 2 points 1 year ago

Oh sorry, you’re right. Amended my comment.

load more comments (2 replies)
load more comments (7 replies)
load more comments (7 replies)