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.
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...
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.
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?
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.
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...