this post was submitted on 01 Oct 2023
304 points (96.1% liked)

Programmer Humor

32000 readers
1744 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 

The audacity to do such a thing…

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 49 points 11 months ago (13 children)

I distinctly remember asking this question during a 100 level programming class but I just can not remember why I'd ever want to do this?

What problem could I have possibly have been trying to solve where this would seem like the answer.

[–] [email protected] 27 points 11 months ago (9 children)

A common problem (before learning it is impossible/fraught with danger) is categorisation, like sorting of strings.

Say you have a text, and need to count words of different lengths.

One intuitive approach is to pass through it once and add each word to a list for the corresponding length, as well as making lists as needed. No 7 letter words, no 7-letter-word-list, even though there are longer words.

As humans we're good at sorting things into an unknown number of categories, and we have to unlearn that for programming

[–] [email protected] 2 points 11 months ago (1 children)

This makes a ton of sense and I think you probably solved this mystery for me.

"Oh I need to iterate over something, and keep track of new information as I do it, therefore I should be able to create 'dynamic variables' as I progress."

[–] [email protected] -1 points 11 months ago

Yep, what you failed to realise at the time is you've just invented a dynamic data structure like a list or a dictionary.

load more comments (7 replies)
load more comments (10 replies)