Thursday, February 14, 2008

A simple DRY

It's interesting a lot of people come to like how ROR organized directories eg app, lib, public, db, etc. The point of attack seems to be homogeneous but nevertheless very handy when bundling particular category.

I come to like it too a lot specially expecting the controllers, model can concentrate on its functionalities rather than cluttering the classes/modules with bits and pieces of delegate methods.

Below is a simple DRY (don't repeat yourself) implementation of a template pattern inside ApplicationController (class require's are not explicitly shown). The main intent is to have one entry call for getting a util class. The redundant other implementation would require if-else statements to extract the Util class per controller.

class ApplicationController
...
def user_template
util = get_util #template_method
util._method1
...
end

...
def get_util #template_method
end
...
end

class AController < ApplicationController
def get_util
UtilA
end
end

class BController < ApplicationController
def get_util
UtilB
end
end

# lib/ folder classes

class Util
def self._method1
end
end

class AUtil < Util
def self._method1
#customized implementation here
end
end

class BUtil < Util
def self._method1
#customized implementation here
end
end

Why Bill Gates is Reckoned to be the Greatest Gift to Secular Humanity

Tuesday, February 5, 2008

Windows JS debugger

My old desktop has .NET installation on it just for the sole purpose of stepping-through the javascript error when opening my web apps with IE. It was kind of a sitting elephant doing the work of a fly but what choice do I have when IE script debugger was pretty much lame in doing strep-thru debug?

Now with Visual Web Developer freely available, this can be a huge sigh of relief when tracking down javascript errors may it be browser compatibility issues or just plain syntax error.

Why Bill Gates is Reckoned to be the Greatest Gift to Secular Humanity