Saturday, January 27, 2007

Windows is driving me to the bleeding edge...

of my sanity. Did you know that Ruby's green threads on windows are worthless? Ok, they aren't completely trash, I mean, they do indeed work but the problem is that they don't run in parallel. Kind of a bummer, eh?

It's especially frustrating when I hacked up a dsl and a RESTful service for executing commands on remote clients in a few hours and I have spent an entire day of my life trying to get it to work properly in windows. I guess this is where Ruby's unix prejudice really starts to show (personally, that's fine with me).

So, after finally figuring out why my DRb server was unresponsive after spawning a new thread I figured I would try using JRuby since it uses Java Threads. Let me first say that I'm quite impressed with the work that the JRuby team is doing. However, due to a bug that exists in the 0.9.x branch I was still unable to get DRb to spawn the thread properly either (for totally different reasons). On a sidenote my friend ruby-debug doesn't currently work under JRuby either. I will dig deeper into that problem later, but after spending and 2 hours and getting 'no where' I have moved on.

So I'm switching to edge YARV. That's the bytecode interpreter that's shipping with Ruby 2.0. I read that there are more threading options available in YARV and I'm interested to see if it helps me out at all.

Thursday, January 18, 2007

Mark, we need arrive at a clearer definition of the word free...

Because it's really starting to bother me that you say the word 'free' as if you don't know there are two distinct meanings in the open source ecosystem. I will choose freedom before I choose free beer. Let's call your definition of free 'FREE' and we'll call mine 'free'.

While I think it's important to many people that things are FREE I believe the greater good is freedom. Freedom to tinker, break, improve and understand. I'm worried you think that if everyone just starts using FREE software the world will be a better place. I posit that if the world (for some definition of 'world') understood the freedoms that come with free software and used it to it's full potential the world would indeed be a better place. From what I've seen on the net recently the EU might be starting to understand this.

Let's put our motives aside and not label companies that have made great contributions to freedom as not 'FREE'. The truth is Mark the freedom is in the source.

Friday, January 12, 2007

Overloading a method within a class.

I came to an interesting realization today what I came home from work and started to look through what had been posted to comp.lang.ruby. The language I program in has drastic effects on my design. Actually, I guess I've always thought to that be true. That's probably why I prefer to do certain things in one language over another. Anyway, enough of my being theoretical. Read this.

What I find fascinating is that in over two years of hacking ruby it has never even once occurred to me that I couldn't overload a method within a class. Why? Because Matz and the other Ruby commiters have found it to be a Bad Thing(TM) and Ruby encourages you to do good things. Yeah, yeah, if you read the whole thread another reason for not implementing it is because it would be hard to do. With that aside I've already started to loathe seeing multiple constructor signatures in a class and that's pretty much the same thing. Just make a static constructor and give it a name that actually means something. None of this 'new Foo(x); new Foo(x,y); new Foo(x,y,z)' trash.

Wednesday, January 10, 2007

Kernel#gets vs. IO#gets

I made an interesting discovery tonight while hacking on widi (it's actually quite embarrassing that I never came across this before). Whenever you are trying to read from stdin in ruby you typically just type 'gets' and don't think twice. I found out there are actually two different 'gets' methods, Kernel#gets and IO#gets.

Usually you don't notice the difference simply because if ARGV doesn't exist Kernel#gets simply reads from stdin. However, tonight I started building out some of the scm wrapper functionality of widi and naturally I was adding command line arguments. This caused widi to die a painful death. It's last words were:
kill #: widi.rb:27:in `gets': No such file or directory - kill (Errno::ENOENT)
from widi.rb:27

To fix the problem I googled a bit and realized I needed to explicitly tell ruby to check stdin using the global variable $stdin (IO#gets is private so don't even bother trying to call it!). Not exactly intuitive but I guess I can't complain too much.

Sunday, January 7, 2007

I will learn something new about vim every day of my life until I die.

I never cease to be amazed by the raw power of vim. Over the last year it has become my editor of choice for ruby code. I even find myself closing my IDE and using vim to edit java code from time to time when things get serious (I swear I could write a web app using only vim macros).

So, I suggest you take some time and read Jonathan's McPherson's blog entry on efficiently using vim.

Tuesday, January 2, 2007


Apparently no one uses ruby-breakpoint anymore. For some strange reason it just stopping working for me all together (that's what really disturbs me). I would hit a breakpoint and it was as if the proper binding simply wasn't being set. I didn't have access to the scope in which the breakpoint was executed (that's not very helpful).

Luckily I came across 'ruby-debug'. Everyone on #ruby-lang says it's cooler anyway.

Monday, January 1, 2007


I frequently find myself writing the exact same method over and over with only minor differences between them (I'm sure there are plenty of design patterns to get around this in every language). One way of getting around this in ruby without much fuss is 'define_method'. Here's a snippet from Widi:

['header', 'footer'].each do |m|
define_method('generate_' + m) {
@widi_config = WEBrick::Config::Widi
file = @widi_config[m.capitalize.to_sym]
file =~ /rhtml/ && File.exists?(file)
data = open(file) {|io|}
elsif file.nil?
constant = self.class.to_s + '::DEFAULT_' + m.upcase
constant.split('::').inject(Object) do |x,y|
Once that code is run the encompassing class will have two methods called 'generate_header' and 'generate_footer'. This approach would be more justifiable if I needed more than just two methods so I may end up ripping it out.

One thing that did not behave how I expected was Module#const_get. It doesn't handle the ::'s nicely and I had to use an idiom I found in The Ruby Way.


Santa brought Denver a lot of snow for Christmas this year. I guess this is what happens when you get snowed in and decide to read a book on the linux kernel.

From snowtux


my google reader feed