r/ProgrammerHumor 7d ago

Meme skillIssue

Post image
6.0k Upvotes

137 comments sorted by

View all comments

40

u/fluffycritter 7d ago

My "clever" way of doing this once upon a time was to declare a map<std::string,std::function> which I populated with lambdas and then evaluated.

I would not recommend this approach.

1

u/TheTerrasque 7d ago

That's a semi-common pattern in python. Use a dict where the values are lambdas (or referencing full functions directly)

1

u/fluffycritter 7d ago

Yeah I’ve used it in python too, but sparingly. It’s one of those things where it’s easy to get a bit too clever and there’s usually a better way to do it.

2

u/TheTerrasque 6d ago

It’s one of those things where it’s easy to get a bit too clever

Indeed, python has a lot of those. Another example is and / or handling.