A friend, who has been a long time Java developer, asked me if there's any truth to the idea that you need to be a better programmer to utilize Ruby. While I wish it were true, I don't believe that to be the case.
The truth is, weak programmers probably wont get themselves in trouble with Ruby because they don't know enough to do anything interesting or dangerous. I've seen plenty of Ruby code that can be written in exactly the same way in Java or C#.
Average programmers are the most likely to cause problems because they can become drunk with their own power and do things that they shouldn't, but can. But, I'm not sure that the situation is any different in a statically typed language. I've seen interesting things like an application that utilized a dependency injection framework to create every object in the application. Clearly someone was overextending a concept and the project suffered because of it.
Good programmers are generally good regardless of the language. They tend to care about things like performance, maintainability, readability, and extendability. If you keep those things in mind, you generally don't get yourself in trouble no matter how much power a language bestows upon you.
You can write good or bad code in any language, and more junior team members slow productivity no matter what tools you give them. Utilizing a less powerful language just increases the chances that they will cause trouble in some other way. The only real way to ensure that a junior team member wont get you in to trouble is to work with them and raise their skill level.
Saturday, January 26, 2008
Ruby/Rails Conferences
Today I was browsing the web for Ruby/Rails conferences to submit speaking proposals to. Unfortunately there doesn't seem to be a list of Ruby/Rails conferences anywhere (that I could find). Hopefully this list will save some time for anyone else looking for a similar list.U. S. Regional ConferencesWhat other Ruby/Rails conferences have I missed?
Sunday, January 13, 2008
Werewolf is the best conference session
Several months ago Charles asked Is Werewolf Killing the Hackfest. Obie responded, noting that the open communication and friendliness in the community is a good thing. Obie was on the right track, but I don't think he hit it on the head.
It's very easy to forget that People Matter Most. A Hackfest might bring about a JRuby version of Mongrel, but a game of Werewolf with Charles ensures that I will feel comfortable contacting him with JRuby questions in the future. Those relationships are much more likely to ensure that my project succeeds than any framework would.
I love attending conferences, but I usually dislike conference sessions. There's generally 2 kinds of sessions: beginner and very specific. The beginner talks always put me to sleep because they cover what I could read in a blog entry in half the time. Conversely, the specific sessions rarely cover things I care about. It's very rare that I need to include a framework in my application and at the same time I happen to be at a conference where the framework is being shown. The specific sessions are good at showing what's available, but they are too detailed. Most framework sessions are better off as lightning (5 minute) talks.
So why do I love conferences? For the informal conversations that always occur. Happy hour used to be the place that I actually heard what the industry leaders were looking into. Happy hour is good, but industry leaders aren't always approachable. However, Werewolf puts you in a game where you are forced to interact with someone you may otherwise be apprehensive about talking to. Building relationships with industry leaders is the number one reason I attend conferences and Werewolf is the easiest way to expand your network.
While Hackfests are about building software for our community, Werewolf is about building the community itself. Because I believe that people matter most I also believe that Werewolf is actually the best way to spend your conference time.
It's very easy to forget that People Matter Most. A Hackfest might bring about a JRuby version of Mongrel, but a game of Werewolf with Charles ensures that I will feel comfortable contacting him with JRuby questions in the future. Those relationships are much more likely to ensure that my project succeeds than any framework would.
I love attending conferences, but I usually dislike conference sessions. There's generally 2 kinds of sessions: beginner and very specific. The beginner talks always put me to sleep because they cover what I could read in a blog entry in half the time. Conversely, the specific sessions rarely cover things I care about. It's very rare that I need to include a framework in my application and at the same time I happen to be at a conference where the framework is being shown. The specific sessions are good at showing what's available, but they are too detailed. Most framework sessions are better off as lightning (5 minute) talks.
So why do I love conferences? For the informal conversations that always occur. Happy hour used to be the place that I actually heard what the industry leaders were looking into. Happy hour is good, but industry leaders aren't always approachable. However, Werewolf puts you in a game where you are forced to interact with someone you may otherwise be apprehensive about talking to. Building relationships with industry leaders is the number one reason I attend conferences and Werewolf is the easiest way to expand your network.
While Hackfests are about building software for our community, Werewolf is about building the community itself. Because I believe that people matter most I also believe that Werewolf is actually the best way to spend your conference time.
Ruby: Staying Current
I'm asked fairly often what I do to stay current in the Ruby/Rails/Software Development communities. Previously, I published a list of the blogs I read, but manually posting that list now and then isn't really a long term solution.
So, to solve the issue I created whatdoiread.com. You can subscribe to the Ruby feed or the Software Development feed (or both) and you'll be reading the same blog posts that I read.
Other than blogs I also really like the audio and video content that's becoming more popular. In particular I try to stay up to date on the Rails Envy Podcast and Peepcode Screencasts.
Of course, I read books also, mostly Pragmatic Programmer titles these days, but I've also enjoyed the AW Professional Ruby Series. Generally I stick to titles that have been recommended by a few people I trust.
I also find conferences to be great places to meet the people who are shaping the industry. Some of the most enlightening conversations of my career have been over drinks when the sessions have ended.
Lastly, working for ThoughtWorks is the best possible career decision I could have made. The internal mailing lists and the people I work with on a daily basis constantly challenge and educate me.
So, to solve the issue I created whatdoiread.com. You can subscribe to the Ruby feed or the Software Development feed (or both) and you'll be reading the same blog posts that I read.
Other than blogs I also really like the audio and video content that's becoming more popular. In particular I try to stay up to date on the Rails Envy Podcast and Peepcode Screencasts.
Of course, I read books also, mostly Pragmatic Programmer titles these days, but I've also enjoyed the AW Professional Ruby Series. Generally I stick to titles that have been recommended by a few people I trust.
I also find conferences to be great places to meet the people who are shaping the industry. Some of the most enlightening conversations of my career have been over drinks when the sessions have ended.
Lastly, working for ThoughtWorks is the best possible career decision I could have made. The internal mailing lists and the people I work with on a daily basis constantly challenge and educate me.
Saturday, January 12, 2008
Ruby: Hash#to_mod
I was recently working with some code where I wanted to initialize an object with a hash. The following example should illustrate what I'm trying to do.
I'm sure that doesn't look very surprising if you are familiar with creating ActiveRecord::Base (AR::B) subclasses; however, my current project has no database and the Movie class was not a subclass of AR::B. Additionally, the Movie instance needed readers for title, subtitles, audio_track_1, and audio_track_2, but the instance is immutable so writers are not necessary. Lastly, I wanted my Movie instances to be able to have any attribute that the hash passes in as a key.
Since I needed the attributes to be dynamic based on the hash I started with a loop that defined methods on the instance.
The above code works fine, and the constructor logic could be abstracted and defined in Class instead to make the Movie definition cleaner; however, I thought it would be nice to create a solution that didn't need to class_eval on the metaclass. Extending a module is another easy way to define additional behavior on an object, so I put together the following code that converts a hash into a module that has a method defined for each key and the return value of the method is the associated value.
With the Hash#to_mod method available the constructor of Movie simply extends the new instance with the module created by the hash.
Pat Farley pointed out that this solution is also nice because it allows me to avoid costly typos by converting my Hash instances into an object with methods. For example, If I have a params hash in a controller I can easily create an object and access it's methods instead of using keys with the hash.
Of course, Pat also pointed out that Hash#to_obj could be defined to make things look even a bit nicer.
Lastly, Pat recommended a recursive version that would allow you to access the entire hash by way of method calls.
Movie.new(:title => 'Godfather', :subtitles => 'English',
:audio_track_1 => "English", :audio_track_2 => "French")I'm sure that doesn't look very surprising if you are familiar with creating ActiveRecord::Base (AR::B) subclasses; however, my current project has no database and the Movie class was not a subclass of AR::B. Additionally, the Movie instance needed readers for title, subtitles, audio_track_1, and audio_track_2, but the instance is immutable so writers are not necessary. Lastly, I wanted my Movie instances to be able to have any attribute that the hash passes in as a key.
Since I needed the attributes to be dynamic based on the hash I started with a loop that defined methods on the instance.
class Object
def metaclass; class << self; self; end end
end
class Movie
def initialize(options)
metaclass.class_eval do
options.each_pair do |key, value|
define_method key do
value
end
end
end
end
end
movie = Movie.new(:title => 'Godfather', :subtitles => 'English')
movie.title # => "Godfather"
movie.subtitles # => "English"
The above code works fine, and the constructor logic could be abstracted and defined in Class instead to make the Movie definition cleaner; however, I thought it would be nice to create a solution that didn't need to class_eval on the metaclass. Extending a module is another easy way to define additional behavior on an object, so I put together the following code that converts a hash into a module that has a method defined for each key and the return value of the method is the associated value.
class Hash
def to_mod
hash = self
Module.new do
hash.each_pair do |key, value|
define_method key do
value
end
end
end
end
endWith the Hash#to_mod method available the constructor of Movie simply extends the new instance with the module created by the hash.
class Movie
def initialize(options)
self.extend options.to_mod
end
end
movie = Movie.new(:title => 'Godfather', :subtitles => 'English')
movie.title # => "Godfather"
movie.subtitles # => "English"Pat Farley pointed out that this solution is also nice because it allows me to avoid costly typos by converting my Hash instances into an object with methods. For example, If I have a params hash in a controller I can easily create an object and access it's methods instead of using keys with the hash.
class PersonService
def self.process(name, blog)
# ...
end
end
class PersonController < ApplicationController
def create
params # => {:person=>{:name=>"Pat Farley", :blog=>"http://www.klankboomklang.com/"}}
person = Object.new.extend(params[:person].to_mod)
PersonService.process(person.name, person.blog)
end
endOf course, Pat also pointed out that Hash#to_obj could be defined to make things look even a bit nicer.
class Hash
def to_mod
hash = self
Module.new do
hash.each_pair do |key, value|
define_method key do
value
end
end
end
end
def to_obj
Object.new.extend self.to_mod
end
end
class PersonService
def self.process(name, blog)
# ...
end
end
class PersonController < ApplicationController
def create
params # => {:person=>{:blog=>"http://www.klankboomklang.com/", :name=>"Pat Farley"}}
person = params[:person].to_obj
PersonService.process(person.name, person.blog)
end
endLastly, Pat recommended a recursive version that would allow you to access the entire hash by way of method calls.
class Object
def to_obj
self
end
end
class Hash
def to_mod
hash = self
Module.new do
hash.each_pair do |key, value|
define_method key do
value.to_obj
end
end
end
end
def to_obj
Object.new.extend self.to_mod
end
end
class PersonService
def self.process(name, blog)
name # => "Pat Farley"
blog # => "http://www.klankboomklang.com/"
end
end
class PersonController < ApplicationController
def create
params # => {:person=>{:blog=>"http://www.klankboomklang.com/", :name=>"Pat Farley"}}
PersonService.process(params.to_obj.person.name, params.to_obj.person.blog)
end
end
Subscribe to:
Posts (Atom)