Mr eel
Programming
Getting the Rug Pulled From Under Your Feet
So, recently we’ve learned that Merb will be merged with Rails.
This is complete bullshit. I’m strongly opposed to the idea and I think it’s a huge mistake. I won’t enumerate all the reasons why — I think that’s all going to be thrashed to death in the coming days — but I do have a number of specific objections that I want to highlight.
Firstly, this means removing choice and competition between Merb and Rails, which despite the occasional friction, I considered to be a good thing. It doesn’t benefit the Ruby community to shift back to one monolithic framework.
I choose to use Merb for practical and philosophical reasons — basically it’s smaller, faster and easier to grasp as a whole. The development process has also always seemed more transparent and open to contributions from outside the core developers. It was a real viable choice to Rails.
But, what’s most irritating about this decision is the secrecy. There is a community of Merb users and developers who weren’t given a chance to comment on or participate in the choice. Instead we get one secretive clique schmoozing up with another secretive clique. It’s damned rude.
The end result is that the term Merb Community has no meaning to them. They don’t give a shit. If you ever used Merb, pimped it to clients or other developers, bought a Merb book, made a plugin, paid for training or went to Merb Camp — you’re being treated like a sucker. They’ve just given you a kick in the balls and you’re being told you’re gonna love it.
I’m damned bitter. I hate the idea and am disgusted at the lack of transparency and condecention implied in the decision.
I now have no interest in Merb at all. They can go to hell.
EDIT: For a good explanation of the merge, read this post by Matt Aimonetti. I’ve since tempered my views a little — although I’m still against the merge in principle and hate the secrecy surrounding the choice — Matt has helped put things into perspective.
Dynamically Creating Classes
Here’s some interesting metaprogramming trix for generating classes at run-time. This is something I had to do recently, so I thought it would worthwhile writing them down — and yes I really did have a good reason for doing this, I swears.
So the first thing to note, is the the Class object actually has a #new method. This just creates a new class which you can then assign to a variable.
new_class = Class.new
A class isn’t so useful without methods, so you can pass a block to the new method which will act as the body for the class definition.
new_class = Class.new do
def cry!
"waaaagh!"
end
end
new_class.new.cry! #=> "waaaagh!"
It’s a regular class so you can do everything you usually would — subclass, instantiate, mix-in modules etc. Still, it’s not very nice having a class reference inside a regular variable, what you really want is to stick it in a constant. Seems easy enough, but remember we’re talking about doing this at run-time, so the code you’re calling will be inside a method. You cannot assign values to a constant inside a method. Oops. Luckily there is a way around it.
An evil little method called Object#const_set. So, if we define a class like this:
class NeedsToBeMoreDynamic
def self.make_a_class!
const_set("NeedsToBeMoreDynamic::KaPow", Class.new)
end
end
NeedsToBeMoreDynamic.make_a_class! #=> NeedsToBeMoreDynamic::KaPow
Right, that seems dead easy, but there is one caveat and it’s a big one, so be careful for $DEITY’s sake — #const_set will actually hijack an existing constant. That means if you’re not careful you’ll make things screwy. You can actually overwrite references to class definitions. That’s bad… obviously.
Don’t let that put you off though, this is definitely a handy technique to know.
Let Us Play a Game
What is this?
>>= \cs ->
A. Person in a boat?
B. A Fish!?
C. Some Haskell code
Silly, it’s some Haskell code of course.
(defun math-boners () (+ 0 0))
So, what have I been doing? I know you probably haven’t had that thought at all, but please allow me to use the conceit. Well I recently added this to my .bash_profile:
alias lisp_for_great_victory=sbcl
Yes, I’ve installed the Steel Bank Common Lisp. Yes, I’m learning Lisp. God I just hope I don’t turn into a smug Lisp-wonk. Those guys are annoying.
Nor have I turned my back on Ruby, I just want to broaden my mind a wee bit. It’s Lisp or acid.
This means I’ll be posting on here a bit more often with my various thoughts about Lisp. I’m sure that’ll be riveting stuff *rolls eyes*.
(print "BOBOBOBOSELECTA!")