4 ms·
It disgusts me on levels I cannot describe that this is standard operating procedure for ruby modules (gems, etc) and is the main reason I could never use it. A
by tdavis 18y ago
It disgusts me on levels I cannot describe that this is standard operating procedure for ruby modules (gems, etc) and is the main reason I could never use it. Adding and replacing methods on builtin classes? Are these people out of their minds?! I don't understand it. I've used monkey patches once or twice and it always feels really dirty.
- raganwald 18y agoThe difference between us is this: You see something that sickens you and publicly blame and shame others for the mess. I see something sickening and I am trying to clean it up.
- tdavis 18y agoI commend you for that, though I have no desire to clean up the messes of others. What would you have me do? Learn Ruby and start rewriting modules? Teach proper metaprogramming to the ignorant masses? The first step to fixing a problem, in this case, is conving people they have one. I'm throwing my hat into that ring.
- raganwald 18y agoActually, I was just trying to pretend that I'm a kindly old wise man that everybody likes for his civic-minded attention to duty. In reality, I'm just as disgusted as you are and the post title says it all. It's true that Ruby should provide better tools. But it's also true that a lot of what goes on is avoidable and there's nothing wrong with you pointing that out.
- shiranaihito 18y agoa lot of what goes on is avoidable and there's nothing wrong with you pointing that out Alright, so why the "(you) publicly blame and shame others for the mess" then?
- plinkplonk 18y ago"The difference between us is this: You see something that sickens you and publicly blame and shame others for the mess. I see something sickening and I am trying to clean it up." I am not sure if I am reading this right, but there seems to be abit of a moralizing tone there. "The difference between us is you [ do something slightly slimy] , I [ do something very noble]". At least that's the way it reads to me. I am not sure in a discussion of a technical issue there is much of a difference in practice. Why is "this is sucky" not acceptable unless one has spent significant time trying to clean it up? Edit : Retracted after reading "Actually, I was just trying to pretend that I'm a kindly old wise man that everybody likes for his civic-minded attention to duty. In reality, I'm just as disgusted as you are and the post title says it all.". I thought I'll leave it up here as a warning not others not to read too much into something.
- stewiecat 18y agoIt's the shiny new toy every new ruby dev wants to play with. Once they get bit in the butt by some really obscure bug that requires the correct combination of 10 gems to reproduce they'll realize that maybe monkeypatching isn't such a hot idea, until then we'll have a bazillion versions of String.
- raganwald 18y agoI encourage Ruby programmers to monkey-patch in their "leaf projects." If you want to write Array#sum for your web app, I say go ahead, it's your butt and you are old enough to deal with the consequences. However, when writing gems, plugins, frameworks, any code that others will use is a different story: Now your "clients" suffer the consequences of your choices. A story about how a web app was broken by installing the Classifier gem due to an Array#sum conflict wouldn't be a story. You change your web app and move along smartly. But who in tarnation is up for patching gems to deal with the conflicts caused by gems patching Array on each other. Ugh.
- dasil003 18y agoThis very consideration led me to redefine nil? on an inner class in my SafeNestedHash gem. It's definitely ugly and weird, but I needed a method that existed on object so I can guarantee it's everywhere. Any other thoughts on how to solve this problem? http://github.com/dasil003/safe-nested-hash/tree/master http://github.com/dasil003/safe-nested-hash/tree/master
- blasdel 18y agoRuby, despite having 4? sigils as scoping operators, pervasively screws up or simply doesn't have support for scoping. It really should have support for having class modifications scoped to your module (and accessible manually from outside), but I couldn't find it. If the language is such that everything "should" be a method on the broadest-possible class, people are going to monkeypatch, because it feels "wrong" otherwise. People just want to write idiomatic code. In Objective-C this ends up not being an issue, because there's very little usage of non-Apple libraries -- plus the default way of adding methods doesn't allow replacement, and Apple libraries are well-versioned (if you build your app for >10.4, API changes in 10.5 are invisible).
- akkartik 18y ago_why's done some work on this: http://github.com/why/potion/tree/master http://github.com/why/potion/tree/master Scoped mixins. Basically, you can modify object behavior within a scope. So changes to core classes can be localized. ++ INCOMPLETE ++
- hboon 18y agoDo you mean to say the default way of adding methods to existing Objective C classes can't replace existing methods? That's not true. I just hit it recently. Subtle bug.
- petercooper 18y agoIt disgusts me on levels I cannot describe that this is standard operating procedure for ruby modules (gems, etc) and is the main reason I could never use it. Adding and replacing methods on builtin classes? Are these people out of their minds?! I don't understand it. I've used monkey patches once or twice and it always feels really dirty. Which is why good Rubyists use these tools sparingly and sensibly. It is not "standard operating procedure." Programmers of any language can misuse the tools made available. Tarring the language with the brush of its poorest users is disingenuous.
- alaithea 18y agoThis is the main reason I've switched to Python in all my side-projects. I drank the Rails kool-aid for a long time, until I finally realized I couldn't get much done with it, as the libraries I wanted to use were unstable, and I couldn't understand the source, due to all the black magic going on. (Not to mention that you're forced to go to the source more often than not, because for some reason most Ruby projects' documentation sucks.) Sometimes I miss Ruby's expressiveness, but I'll take Python's abundant, stable and well-documented libraries any day.