s-expressions

Amit Rathore blogs about software development

Archive for March, 2007

Perfect vs. Shipped

Posted by Amit Rathore on March 31, 2007

I overheard an amusing comment in my team-room the other day, I think it might have been Kris Kemper who said it – “Anyone who knows Ruby On Rails has a half-done personal project that’s going nowhere”. How true. I have at-least three.

The thing is, in my mind I’m always envisioning these grand cathedrals, and even when I do start work on any one of them, I never seem to quite finish them. Or I don’t complete everything properly (or quite enough to be production-ready), and the application is never quite done.

I think it has to do with a lack of focus. I find myself thrashing between the hundreds of things that interest me, and I end up with a ton of unfinished work. I’m very much into lean software methods, and I know that all I’m doing by operating this way is creating a lot of inventory. I seem to be able to use lean and other workflow management techniques at work, but in the world of my personal projects, I seem to be at a loss.

Sometimes, it has to do with trying to get everything perfect. After all, since it is a personal project, I feel like I don’t have a delivery dead-line, so I can take the time to get it right. Which leads me down the rabbit-hole of perfection and cathedral building, with no real end. Cause there probably ain’t anything called perfection.

When consulting for our various clients, I’ve a clear idea in my mind about the compromises and trade-offs needed between design, architecture, refactoring, and delivery. And I aggressively do whatever might be needed to prod the folks along (be they developers, or product-owners) to get the thing done and into production. After all, there’s always another iteration coming up, and there’s always a next release.

So why the heck can’t I seem to do the same thing when I’m working on a nights-and-weekends project?

Posted in Uncategorized | Tagged: , , , , | 3 Comments »

Ruby, managing global variables, and dynamic scope

Posted by Amit Rathore on March 25, 2007

Everyone knows that global variables are bad. However, they are quite unavoidable. Java’s System.out is an example.

Globals, sometimes offer a certain kind of flexibility. They offer a way to tweak the behavior of the entire (or a subset of) the system. For instance, one can redirect System.out to a different stream (into a file, say) and capture all the messages a program spits out.

This kind of stuff works nicely. Except when someone else goes and changes the same variable to something else in another part of the code, and you’ve no idea where.

What is needed, is something like optional dynamic scope, so that the globals can be used when needed, but can be managed better. After all, from the above example, what seems to be needed is a way for a piece of code to say – for my purposes, and for all code that runs when I’m called, I want the value of this global(s) to be _something_, and when I return, these globals should be reset.

This can be done manually, by saving the existing value of a global before setting it to something else, and then resetting it back when the code block completes running. Perl and Common Lisp have had a mechanism to do this type of stuff for a long time, built into the language.

Here’s a hacky (and probably naive) way to implement this in Ruby, to illustrate how this might work -


module Let
def let(bindings, &block)
old_bindings = capture_existing_bindings_for(bindings)
block.call
rehydrate_old_bindings_with(old_bindings)
end
def capture_existing_bindings_for(bindings)
old_bindings = { }
bindings.each do |k, v|
old_bindings[k] = eval "@"+k.to_s
create_binding k, v
end
return old_bindings
end
def create_binding(var_name, value)
instance_eval "@#{var_name}=value"
end
def rehydrate_old_bindings_with(old_bindings)
old_bindings.each do |k, v|
create_binding k, v
end
end
end

And the way you would use this, would look something like this -


require 'let_module'
include Let
@num_var = 1
@char_var = 'a'
class Car
attr_reader :name
def initialize(name)
@name = name
end
end
@obj_var = Car.new("hyundai")
def do_something
puts "num_var is " + @num_var.to_s + ", char_var is '" + @char_var.to_s + "', obj_var is " + @obj_var.name
puts "returning"
end
do_something
puts "changing num_var to 2, char_var to b, obj_var to 'kia'"
let :num_var => 2, :char_var => 'b', :o bj_var => Car.new("kia") do
do_something
puts "changing num_var to 3, char_var to c, obj_var to 'toyota'"
let :num_var => 3, :char_var => 'c', :o bj_var => Car.new("toyota") do
do_something
end
do_something
end
do_something

And when run, would produce this -

num_var is 1, char_var is 'a', obj_var is hyundai
returning
changing num_var to 2, char_var to b, obj_var to 'kia'
num_var is 2, char_var is 'b', obj_var is kia
returning
changing num_var to 3, char_var to c, obj_var to 'toyota'
num_var is 3, char_var is 'c', obj_var is toyota
returning
num_var is 2, char_var is 'b', obj_var is kia
returning
num_var is 1, char_var is 'a', obj_var is hyundai
returning

This could be one way to control unruly global variables in Ruby.

Posted in Uncategorized | Tagged: , , | 1 Comment »

Java Micro Edition development – annoying emulator error

Posted by Amit Rathore on March 21, 2007

After a long time, I recently started playing with the Java Micro Edition again. Many years ago, I had downloaded and installed the Wireless Toolkit from Sun’s website (then in beta), and had hacked together common mobile games – snake, hangman, and the like.

So, when I downloaded the toolkit this time (v2.5 now), it was annoying to find that I couldn’t even seem to run a basic midlet without the emulator barfing at start up time, with an inexplicable ‘Uncaught exception java/lang/ArrayIndexOutOfBoundsException’ – no line numbers, nothing. The emulator screen wouldn’t list the midlet name either, so clicking on the soft button would simply print the same exception message again.

Google was of limited help. More annoying.

Finally, I just played around with different configurations during launching the midlet, and when running it in “class” mode (you have to specify the midlet class), it seems to work.

So there’s a work-around for you.

Posted in Uncategorized | Tagged: , , , | 1 Comment »

CruiseControl.rb – Continuous integration for ruby projects

Posted by Amit Rathore on March 18, 2007

cruisecontrol.rb

I downloaded and installed CruiseControl.rb today – from the ThoughtWorks website. Well, I suppose ‘install’ is not quite the right word as it comprised entirely of running a couple of commands, and took all of 30 seconds.

It works beautifully, right out of the box! The example on the website didn’t have any reference to the situation where you connect to your subversion server over ssh, so when I went ahead and tried it, it succeeded and then gave me the following message -

IMPORTANT!!! – It looks like you are connecting to your repository with an svn+ssh connection. For cruise to build this project, you need to have set up authentication caching for ssh, see this article

http://subversion.tigris.org/faq.html#ssh-auth-cache

What a pleasant surprise! I like software that was designed with users in mind. The information above for setting up ssh authentication works like a charm, btw.

Posted in Uncategorized | Tagged: , , , , | Leave a Comment »

Turing complete languages and productivity

Posted by Amit Rathore on March 2, 2007

I was having a conversation with a colleague about varying levels of programmer productivity – specifically around language choice. As usual, one of the things that came up was the idea of Turing completeness. The important point to note is that the idea of Turing equivalence is completely separate from expressibility, efficiency, convenience, or well – productivity.

My take on it is this – for simple systems and programs – this idea of languages being equivalent approaches triviality. For non-trivial systems, however, the story changes quite a bit. If the system is sufficiently complex (and needs to be indistinguishable from magic), the best way to do it in a lower-level but “equivalent” language like C or Java is to build abstractions like crazy. Including building an interpreter for a higher level language.

I think that is the only way one can truly claim that languages are equal. Java is “equal” to Ruby because you can use JRuby to write all the code of consequence. C is infinitely superior to C++ when you embed Lua in it. Or Blub is better than Smalltalk because you implemented a Lisp in the former.

After all, what does it mean to write a system in a particular language when you can throw in a completely different layer of abstraction through a library like this? When these lines are blurring so much, and programming models and paradigms are becoming incestuous, is it not time to stop having silly debates about languages and start building systems with what works best?

P.S. – Of course, to be able to do the right thing, you need to have a toolbox with the right tools. Start collecting them, now!

Posted in Uncategorized | Tagged: , , | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.