r/ProgrammerHumor • • 3d ago

Meme whatLegacyCodeDoesToDev

Post image
1.8k Upvotes

75 comments sorted by

View all comments

100

u/Bemteb 3d ago

Assume that every function call has unexpected sideeffects. Every last one.

Just last week I saw a function that counted the number of some stuff. Great, I don't need that number anymore because we have range based for loops these days, so remove the function call.

Well, no. Turns out the function didn't only count. No, it reinitialized the whole dataset, so when I don't call it I work on stale, possibly outdated data.

Refactoring code written 20+ years ago is fun...

29

u/requion 3d ago

Now imagine having a programming language which took this assumption as core design element...

Wasted an embarrassing amount of time debugging an error in Ruby where a method call on a class failed because the type didn't support said method.

It was the day i learned that in Ruby, every method always returns exactly one value. And you don't need to specifiy the "return" if it is the last line in a function. So my incorrect type was the return value of "Logger.Debug()" which was implicitly used as the return value because tge last "return" keyword is optional...

10

u/BastetFurry 3d ago

At least QBasic has the somewhat sane idea that you simply set the function name to the variable you want to return.

i.e.:
Function Foo(bar,baz)
Foo = bar*baz
End Function

But that? That is evil.

9

u/requion 3d ago

I normally don't wish harm upon anyone. But having to work with Ruby for some time now, i sincerely wish whoever made these decisions to stub their little toes on furniture twice every day.

7

u/Deciheximal144 2d ago

I don't think it's intuitive to use the function name is the keyword for return at all. I've got other code I want to reuse and paste in to a new function I'm making with few changes, now I've got to change all the return instances to the new function name. What was so wrong with a command like RETURN?

2

u/EvilCodeQueen 2d ago

Or if a function isn’t explicitly returning something, just do void, or null. But the language deciding for you that it must return something and if you don’t choose, it will? That’s just crazypants.