this post was submitted on 12 May 2024
610 points (92.1% liked)

Programmer Humor

19589 readers
823 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 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 8 points 6 months ago (1 children)

On the contrary, it made it far more difficult to understand the program since you had to know which method was called in which object due to polymorphism when you looked at the code. You had to jump around like crazy to see what code was actually running.

I agree with this point, but polymorphism is often the better alternative.

Using switch statements for the same thing still have the problem that you need to jump around like crazy just to find where the variable was once set. It also tends to make the code more bloated.

Same with using function references, except this time it can be any function in the entire program.

The solution is to only use polymorphism when it’s absolutely needed. In my experience, those cases are actually quite rare. You don’t need to use it everywhere.

[–] [email protected] 6 points 6 months ago

Yeah I agree. With experience you know where to use it and where it really shines, and when not to use it because it will just make everything harder to reason about.

But a lot of devs are not that experienced when they make these decisions. All of us learn from mistakes, and those mistakes stay in the code base. :)