RailsConf Europe 2006: Day two, prophylactic programming
The second and final day of RailsConf Europe 2006 starts.
Jim Weirich, author of Rake, starts an interesting talk on the inherent dangers of the dynamic nature of Ruby. 3rd party libraries you may use that, instead of sub-classing, open and change standard Ruby libraries e.g. Logger.
And now we are moving on to the famous Leroy World of Warcraft video. It illustrates collborative systems and how they can go wrong.
So, tips for safe Ruby programming:
- Use namespaces (class Node for instance occurs 9 times, good thing all but 1 are namespaced.)
- Choose a good project name (not generic, checkout Rubyforge, RAA and gems first for conflict.)
- Avoid top level constants and functions (e.g. Rake is a bad example. Jim wrote Rake.)
- Try not to modify existing classes or at least add behaviour rather than modify.
- He recommends prefixing existing class modifications with your project name. I can’t say I agree, this is ugly and non-intuitive.
- Sometimes you should take risky steps to reap productivity advantages.
- You can wrap method definitions in a conditional block. Jim uses this to check if a method exists before he adds his own. Got to love Ruby.
- Forthcoming selector namespaces should help Ruby a good deal.
- Careful with cool tricks e.g. adapting to old calls with const_missing.
- Limit the scope of your changes as much as possible.
- Preserve the original behaviour as much as possible. This ties into Design by Contract. Feel free to improve internal code but don’t break the contract.
The conclusion though is that Ruby shouldn’t be crippled to protect against the ignorant. Very good talk, thanks Jim.
Why just arrived and will gives his talk in a few minutes. See you then.
Add New Comment
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Add New Comment
Trackbacks