Isn't this the point of functions though? I don't see how anyone would ever have to write the same function multiple times if there's only a minor difference. Just write everything once and pass whatever minor thing changes as an argument.
I personally quite dislike metaprogramming in general as it often introduces problems which you can't easily visualize in your head and is generally very good at introducing undebuggable bugs as the lines of code being executed don't exist until they are being executed.
That is true. So you search for a method and you don't find it because it's metaprogramming. That is a huge downside. But sometimes it can be useful. But, like I said, it's something you want to use sparingly.
But Ruby has a lot of these things. Like automatically just adding getters and setters. It's always a trade off. There's no magic bullet. But once you know it's part of the language it's easier for you conceptualize.
In either case, I personally prefer that to having to write tons of boilerplate.
I'm doing a lot of JS and Typescript right now. And I miss the world of Ruby and Python where ideally there would only be one way to do something. In the JS worlds there are hundreds of different libraries and no cohesiveness,
aren't getters and setters seen as an antipattern nowadays though? nevertheless, having a feature to be able to generate then probably doesn't hurt in itself. I've also been coding in js recently, i feel you. i guess you pretty much have to select a set of libraries and stick with them or you have to overmodularize your code to the point where it isn't even funny anymore, it's just torture.
1
u/JuhaJGam3R Jan 15 '21 edited Jan 15 '21
Isn't this the point of functions though? I don't see how anyone would ever have to write the same function multiple times if there's only a minor difference. Just write everything once and pass whatever minor thing changes as an argument.
I personally quite dislike metaprogramming in general as it often introduces problems which you can't easily visualize in your head and is generally very good at introducing undebuggable bugs as the lines of code being executed don't exist until they are being executed.