Code Smells @ YouTube

MountainWest RubyConf 2013 Code Smells: Your Refactoring Cheat Codes by John Pignata

It’s great presentation which talks about refactoring the code by showing examples. The actual refactoring part is 20-minutes or something, but it has a lot of nice viewpoints. Defining the roles of modules and their interactions are the key factor of designing maintainable codes. Always, actual example-code works well understanding the concept.

One concern point (which I felt) is some of the classes are cross-communicating each other, making the class relationship a little complex.


  1. PushDaemon <-> UDPServer
  2. UDPServer <-> Client <-> Job
  3. Worker <-> Job

These classes are arbitrarily calling the other one’s method. As ruby’s duck typing doesn’t define the specific interface, it’s a little difficult to identify the method call-graph. Maybe, at least for the 1st item, instead of calling pre-fixed method each other, apply observer pattern (subscribe/notify) from one side makes it clear about their relationship?

require "observer"

class Server
  include Observable

  def start
    sleep 1
    notify_observers("sample response")

class Daemon
  def initialize
    @server =
    @server.add_observer(self, :call)

  def run

  def call(message)
    puts "called by listener with message: " + message

Posted on July 11, 2013, in Ruby, Software Design, Web. Bookmark the permalink. 1 Comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: