News for hackers. Stuff that matters.
Re:Thank you, Rails by tptacek on Friday November 06, 2009 @01:29AM (#925574)
But who would ever monkeypatch Array#pack?

I think you're generally pretty safe as long as you stay away from the core library methods. It's the attempts to transparently extend well-known methods that I think tend to blow up on people.

Re:Thank you, Rails by patio11 on Friday November 06, 2009 @01:35AM (#925585)
a) I don't trust the least-skilled programmer in my company to tie his own shoelaces without supervision, as he might accidentally hang someone.

b) You will eventually generate a namespace collision based on the birthday paradox alone, no matter whether programmers avoid the core methods or not, if they are working in the same classes. The Ruby community encourages people to have fun with String, Number, etc because it results in easy to write DSLs.

c) array = []

array.methods.size => 127

require 'activesupport' => true

array.methods.size => 185

Those added methods include, among others: sum, to, split, blank?, rand, load, to_xml, to_json... and numerous other things some intrepid developer might decide their own arrays could benefit from.

Edit: The code sample didn't demonstrate what I wanted it to demonstrate, so I changed it to one that did, although it demonstrated something related anyhow.

Re:Thank you, Rails by FooBarWidget on Friday November 06, 2009 @10:13AM (#926074)
Actively encourage? There are only a handful of libraries that actively monkey patch the core classes. ActiveSupport, RubyGems, extlib, and uhm.... I don't know anything else. If anything most of the Ruby blog posts on monkey patching always warn programmers that it should be done with care.

If you're so afraid of incompetent developers money patching things so that they break, why aren't you afraid that they write Java* code that spawns 2 million threads, crashing the system? Or code that deletes the hard drive? There are plenty of easy ways to break a program besides monkey patching.

* With "Java" I mean whatever your favorite language is that you think will prevent incompetent developers from doing stupid things.

Re:Thank you, Rails by tptacek on Friday November 06, 2009 @02:15AM (#925625)
Yeah ok, you win.