06 January 2007

Fighting the invisible require_dependency!

(Warning: Skip this sentimental / philosophical introduction if you want practical information!)

Back in 1998, at my first job, I was working on client/server applications built with a framework made in France called NatStar. It's probably dead by now as I could not find any link in English! It was quite a blurg with crystal clear method names such as THINGS_GET_DB_ (sic) and I really feel sorry for the poor folks who have to maintain the existing programs. The only documentation available was the User Manual: 7 or 10 huge books!!! I remember spending ages skimming through these horribles books ...

We are in 2007 - less than a decade later! - and I feel lost if I don't have an Internet connection while I am programming, so do you, I guess ;-)
Every time, you run into a new problem, the new reflex is to google it and 80% of the time, you get an answer or at least a clue which help you to solve the problem!
I am not going to comment about the time you spend half procrastinating half reading forum archives instead of actually using your brain! No, I want to blog with you about what to do when google replies "Your search - "very complex problem" - did not match any documents."

Remembering you are a smart person, you'll probably find the solution in number_of_penguins+y*myloadfactor-mymanager_using_waterfall day(s). This could be the end of the story and it probably is in the majority of the cases - we are humans after all - but a minority thinks in a different way. BIG WOW: I am impressed by this minority.

Indeed, they make the choice to "loose" their personal / professional time just to share their solution with the World! Even if they might have narcissistic motivations (hello world, look how smart ass I am!), this kind of altruistic behavior is giving me a bit of faith in Humanity. After all, if all these people are doing it for FREE, there might be a chance to do something about the serious social and environments issues WE have (+ our grand-grand-n-grandchildren).

My point is, try to remember that money is just paper & ink (notes), metal (coins) and especially electrons (databases). Economy can't compete with the act of Giving. Sometimes, when I read newspapers talking about GNP growth (war || destructions => growth), I try to remember our collective madness and I feel quite sad. There is an expression in Spanish I hate: "Es lo que hay" (This is what we have and we have to live with it). NO.

"More than enough rope to hang yourself"

...was the talk Josh Susser was going to give at the RailsConf 2006 . His point was "the pitfalls of excessive cleverness in Ruby coding. Think of it as an antidote to all the talks you've seen about how to go nuts with metaprogramming". I agree with him, a good programmer is a programmer that writes code readable by everyone not only for the smart ass...

Yesterday, I spent hours trying to understand the following error message:

undefined method `use_transactional_fixtures=' for Test::Unit::TestCase:Class (NoMethodError)
This error message is completely useless!

A few people have come across the problem , a bug has been opened into the rails trac system but no solution ...

What did I do? Just a plain and simple refactoring, I had renamed the user model class used by the Login generator .
It happens that I had forgotten to rename the first line of lib/ with contained a require_dependency "myusermodelclass"
The import was failing but no exception thrown, the consequence was that the test_helper was not loaded properly, hence the error message because the use_transactional_fixtures is the first line loaded in test_helper ...

So if you have the same problem, my advice is to check all your require and require_dependency.

The good new is that I am using Rails 1.16 and it seems that the problem will be solved in Rails 1.2 by a patch .

I think that the method require_dependency could have better defined:

Object.send(:define_method, :require_dependency) { |file_name| Dependencies.depend_on(file_name) } unless Object.respond_to?(:require_dependency)
Maybe I am not an expert in ruby but I think that dynamic code is dangerous in general because it's harder to debug, hence loosing quite a lot of productivity. Nothing worths more than a nice exception stack!

This makes me think about the lack of refactoring tools for ruby, I can't imagine the same thing with java and Eclipse. Hopefully, we'll have our IDEs for ruby in 2007!

No comments: