this post was submitted on 01 Oct 2023
476 points (96.7% liked)

Programmer Humor

32464 readers
518 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] 117 points 1 year ago (3 children)

The answer is a map or dictionary.

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

Or sometimes even just an array. The first time I thought I wanted to do this was 2003 and I was writing a perl script, and I was trying to loop through some sort of array, and write the outputs of some calculations to $val0 $val1 and so on, and I was neck deep into some horrible dark constructs like ${"val" . $i} before I actually realized that I really just wanted an array, you know, like the one I was already using.

It took me forever to understand map (the metafunction).

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

It depends. If the variable names are arbitrary, then a map is best. If the variable names are just x_1, x_2, x_3, ..., x_n, then a list or dynamic array would be more natural. If n is constant, then a vector or static array is even better.

[–] [email protected] 10 points 1 year ago (2 children)

I've just figured out linked lists and I want to call that the solution ¯_(ツ)_/¯

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

When you get a new hammer...

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

I mean, I wouldn’t recommend it, but seems like a data structure that could work.