Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Monthly Archives: February 2010

David Goudreau

Make the RubyMine 2.0.1 debugger work for you…

David Goudreau
Wednesday, February 17, 2010

In the latest Rubymine 2.0.1, we’ve had lots of problems on our workstations with getting it working reliably. Seeing as how I love using a debugger and look forward to leaving the days of puts behind, I’ve spent a fair amount of time troubleshooting this problem.

Here’s the deal – Rubymine 2.0.1 must have ruby-debug-ide -v=0.4.7 installed to work correctly, not the latest, which is ruby-debug-ide -v=0.4.9. You should also check out the Console tab of the debugger if you need any additional troubleshooting help.

So go ahead, uninstall 0.4.9, install 0.4.7 open up Rubymine 2.0.1 and start debugging – your inner troubleshooter will thank you.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Glenn Jahnke

Standup 2/17/2010: A New Jasmine Release

Glenn Jahnke
Wednesday, February 17, 2010

Interesting Things

There is a new release of Jasmine, the Javascript testing framework written by several people here at Pivotal Labs, due to a bug found in CI related to implementing Rack.

For those uninitiated to Javascript BDD testing, here is a quick example.

it('should be a test', function () {
  var foo = 0
  foo++;

  expect(foo).toBeTruthy();
  expect(foo).toEqual(1);
});

Be sure to check out Jasmine at Github.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Will Read

API Cake

Will Read
Monday, February 15, 2010

A made up conversation with myself:

Let’s say I have a cool service. Now I want someone to take my cool service and develop against it. So I make an API. I’m using RESTful methods in RoR so it’s pretty straight forward to expose the CRUD actions. Done!

I release it in to the wild. People are jazzed, and they start to make clones and clients that do the same thing as my service. That’s cool, it’s driving an extra .5% of the traffic to my site. But I’m waiting for someone to innovate and blow my mind. With what? I don’t know!

Well, I gave them the ingredients, and the instructions, and they took my API and made an API cake, just like I showed them to make. They can read the product catalog, or they can post messages, and they do.

The cool part for developers is the “intellectual property”, the numbers in most cases. Let me get at how people are using my cool new service so I can start to make conjectures like “if A happens in the context of B, then we usually see C”. Like what if I had the number of facebook status messages about a new comedy show premier, and I search those for the word “funny” and plotted them over time? I could paint you a picture of what parts of the show were entertaining. But I can’t get at that kind of data.

Similarly, what if Amazon told me how many self help books were sold in New Jersey over time? Then I could make a map of where a psychologist should open up a practice.

Some of this information deals with privacy of the users. Some of the information can be anonymized, but is still too close to something the company views as a core process which is currently giving them a competitive edge. That’s exactly why it is interesting, why those developers are hungry for it, why you should release it, and give your users a tremendous experience. If you set loose the data, your developers will be able to creat more than just a copy of existing functionality, they can really innovate and tell you things about your business that your customers didn’t even realize.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Davis W. Frank

What's so funny 'bout pseudo-classical inheritance (in JavaScript)?

Davis W. Frank
Monday, February 15, 2010

Our customers are asking for richer interfaces and user experiences. And so we – and by “we” I mean the Rails development community – are writing more and more JavaScript. We’ve gone from ignoring JS (using RJS server-side) to rendering JSON and writing our own jQuery plugins.

But in this transition some of us left our objects & design patterns on the server. Just because you’re writing a click handler in JavaScript doesn’t mean it couldn’t, or shouldn’t, be a method on an object.

If you have a long-lived page, its data are clamoring for object orientation. That data needs to be loaded, reloaded, and paginated via AJAX calls – why build that code (or that interface) more than once?

What about APIs that you’re accessing via AJAX? Wrapping an API in an object means you can more easily mock out the actual service in test and keep all the parameter logic separated from your data models. Or even more exciting, you can reuse your API code on the server (thanks for the timely example, Dion!).

JavaScript already has objects, but how do you organize your code in a more object-oriented way?

I’m a fan of a more Pseudo-classical approach to my JavaScript. (Sorry, Mr. Crockford, but I’m spending nearly all my time in Palm webOS these days and Mojo new‘s my objects). I’m not a fan of Prototype.js’s Class.create – $super is awkward, puts too much responsibility on the coder, the errors you get when you forget one are confounding, I don’t need to rename my constructor…the list is a bit longer, but you get the idea.

Instead we use JavaScript prototypes a lot like Ruby’s Classes – objects that implement common “class”-wide behavior. We setup an inheritance graph between child & parent prototypes – much like Google’s Closure. And we explicitly call functions on parent prototypes when we need “super”.

The result is a set of techniques that behaves enough like Classical inheritance for us to be productive. More importantly, we like it and the code we write with it – if there’s demand, I’ll write up an example.

Defining objects for purposes of encapsulation, abstraction and ease of testing (no matter the technique) is not only possible in JavaScript, they (surprise!) offer all the same benefits they do in other languages: less code that’s more robust and that you don’t mind extending & maintaining.

Why else is this important now? THE FUTURE.

Writing HTML5/RIA/MobileWeb applications in JavaScript is different than Rails/MVC web development. In order to make our code manageable we’ll need and want to crib from the object-oriented patterns of desktop client development.

But that’s another post.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Second thoughts on initializing modules

Pivotal Labs
Monday, February 15, 2010

This morning Yehuda Katz posted a response to my previous post, Technique for extending a method from a module, showing how a more modular organization of the Person class would allow for a solution that does not require a crazy meta programming hack. The idea is that by extracting the method we want to decorate into an ancestor class, Ruby makes it a lot easier to do what we want.

Previously I was aware that there were other ways I could structure the host class to make the module’s job easier but I did not try that because but I was writing the code with the knowledge that I would only be in control of one side of the equation, the module. The host class was going to be written by the end-user of the Rubygem the module was to be packaged in. Since I did not want to try dictate how the end-user structured the host class I ended up adding a lot of complexity to the module. The goal became how to write the module in a such a way that the class would “just work” upon including Teacher without requiring any additional steps to be taken. Asking the user to create an AbstractPerson class that contained their initialize method and then creating a subclass felt like an obtrusive request to make through a README that would ultimate negatively impact the user’s experience with the library.

Shortly after I put that blog post up I got this tweet from Josh Susser:

egad! are you sure you're solving the right problem?

I was trying to solve how to decorate the initialize method from a mixed-in module. My real problem however, was that I was trying to modify the behavior of the host’s initialize from a module which is a good way to get into trouble. I am now of the opinion that if the module does need to be instantiated in some way, a good solution is to provide a initialization style method that the host class can call.

class Person
  include Teacher

  def initialize
    initialize_teacher
    # initialize person
  end
end

An added benefit of this approach is that initialize_teacher can be called from anywhere, and doesn’t have to happen within Person.new. This explicit instantiation violates my original goal of being unobtrusive to the user but it sidesteps the can of worms that the original approach has. One obvious problem that was likely to come up was the case where the module’s initialize needs to take a parameter. Once that happens it is not longer completely transparent to user. Even worse is if the host class’s initialize needs to take it’s own parameter. At that point it falls apart completely.

Credit to Austin Putman for suggesting this in a comment on the first post. Also thank you to Yehuda Katz for his informative post on writing modular ruby code.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Technique for extending a method from a module

Pivotal Labs
Sunday, February 14, 2010
Update: Read the follow-up post Second thoughts on initializing modules

I was recently presented the problem of appending to the initialize method from a module that was being included. To do this it would need to override the class’s initialize method with my own but keep the functionality of the original initialize method.

Whenever I need to do something in Ruby that I know will require some experimentation I like to move outside of my application and reproduce the problem in a simple way. For this problem I created a Person class that mixes in a Teacher module.

module Teacher
  def initialize
    puts "initializing teacher"
  end
end

class Person
  include Teacher

  def initialize
    puts "initializing person"
  end
end

The goal is to get the following output when a Person object is created:

> Person.new
initializing teacher
initializing person

The basic program fails as expected; Teacher.new prints “initializing person” because Person’s initialize is trumping Teacher’s. Our immediate goal is to replace Person’s initialize with Teacher’s but in a way that preserves the original initialize method. By using alias_method we can create a copy of the original initialize method that we can call later.

module Teacher
  def self.included(base)
    base.class_eval do
      alias_method :original_initialize, :initialize
      def initialize
        puts "initializing teacher"
        original_initialize
      end
    end
  end
end

This solution is the simplest thing that could possibly work, unfortunately it also has one major limitation. For it to work the call to include Teacher in Person has to come after Person’s definition of initialize. This is may be fine in situations where you have total control over the Person class, but what if Teacher is going to be part of a library you are distributing? Asking your users to place the include line to your module in a specific spot is unacceptable.

To make this work we need to be able to capture definitions of the method we want to redefine even after our module has been included. This sounds like a good time to use Ruby’s method_added hook.

module Teacher

  def self.included(base)
    base.extend ClassMethods
    base.overwrite_initialize
    base.instance_eval do
      def method_added(name)
        return if name != :initialize
        overwrite_initialize
      end
    end
  end

  module ClassMethods
    def overwrite_initialize
      class_eval do
        unless method_defined?(:custom_initialize)
          define_method(:custom_initialize) do
            puts "teacher initialized"
            original_initialize
          end
        end

        if instance_method(:initialize) != instance_method(:custom_initialize)
          alias_method :original_initialize, :initialize
          alias_method :initialize, :custom_initialize
        end
      end
    end
  end

end

Whoa! As you can see a lot of complexity has been added to Teacher. However, what it’s doing is actually really cool. Here is the breakdown:

What self.included is doing:

  1. The ClassMethods module containing overwrite_initialize is added to base (Person).
  2. overwrite_initialize is invoked.
  3. method_added is defined on Person at the class level.

What overwrite_initialize does:

  1. If a method called custom_initialize does not exist it defines one. custom_initialize runs Teacher’s initialize logic and then defers to Person’s initialize.
  2. If the current initialize method is not our custom_initialize method then initialize is preserved as original_initialize and a copy of custom_initialize is made to replace initialize.

What method_added is doing:

  1. Watches for new methods with the name “initialize”.
  2. When an initialize method is defined method_added calls overwrite_initialize to put the chain from custom_initialize to this new initialize method in place.

What is particularly nice is that this implementation is flexible enough to handle multiple redefinitions of initialize. This is important because a subclass of Person may also define initialize. It is not perfect though—if the initialize in the subclass of Person calls super the program will go into an infinite loop where custom_initialize and the subclass’s initialize call each other indefinitely. If anyone has a suggestion on how to get around this please post a comment or fork the gist on Github.

Read the follow-up to this post Second thoughts on initializing modules.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Dan Podsedly

Pivotal Tracker down for an upgrade tonight (Friday) at 7pm PST

Dan Podsedly
Friday, February 12, 2010

Pivotal Tracker will be down for an upgrade tonight, Friday (2/12/10), starting at 7pm PST. We anticipate to be back up within about an hour.

Apologies for any inconvenience.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Standup 2/11/2010: Sass with Jasmine

Pivotal Labs
Thursday, February 11, 2010

Interesting Things

  • If you are testing with jasmine, it’s a good idea to include your CSS files in the test runner. This prevents, for example, issues where you’ve hidden an element in the CSS and expect it to be visible in your JavaScript. If you are using Sass, then you should regenerate your CSS from the Sass before running the jasmine tests. The current version of haml-edge updates the sass command-line tool with an update command. On one of our client projects, we added the following to our jasmine_config.rb file:
  def update_sass
    puts "Updating sass files..."
    rails_root = File.expand_path(File.dirname(__FILE__) + "/../../../")
    sass_path = "#{rails_root}/vendor/bundler_gems/ruby/1.8/gems/haml-edge-2.*/bin/sass"
    puts `#{sass_path} --update #{rails_root}/app/stylesheets:#{rails_root}/public/stylesheets/generated`
    puts "done."
  end

  alias_method :old_start, :start
  def start(*args)
    update_sass
    old_start(*args)
  end

  alias_method :old_start_server, :start_server
  def start_server(*args)
    update_sass
    old_start_server *args
  end
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Standup 2/10/2010: Calling all railsplugins.org

Pivotal Labs
Wednesday, February 10, 2010

Interesting Things

  • When testing with jasmine and using jQuery live events, be sure to stop the events between tests. If you don’t, they can cross tests and cause confusing results.
  • RailsPlugins.org is asking that all Rails plugin developers register their plugins on the site. This will both help determine the set of plugins that are ready for Rails 3, and also provide a comprehensive directory of plugins.
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Standup 2/9/2010: Bundler 0.9.x, Amazon S3 versioning, and Safari console debug questions

Pivotal Labs
Tuesday, February 9, 2010

Interesting Things

  • Bundler is now at version 0.9.x. The 0.8 to 0.9 release included many improvements and large internal changes. Everyone should probably upgrade, but be aware that this may be disruptive to your project, as the bundle command has changed names. You should be aware of this before upgrading. Yehuda has posted a comprehensive blog post about using Bundler that is worth reading. Since Bundler is in beta, it will probably keep changing.
  • Amazon has released a beta versioning feature for S3 that allows you to keep a full history of changes to your S3 objects. This looks useful.
  • There is some question about what state of a DOM node is shown in the Safari console when console.debug is called. Is it the state of the DOM node from exactly when the call was made, or is it some later state due to Safari asynchronously displaying the console messages? We are going to do some research and will update at a future standup.

Edit:

It sounds like the Safari issue occurs when logging a reference. Mentioned workarounds for the Safari issue include:

  • explicitly logging the variables that you are interested in; i.e., console.log(obj.a, obj.b)
  • using the debugger
  • transforming the object to JSON
  • using console.dir
  • logging a string
  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Topics

  • agile (780)
  • rails (113)
  • testing (88)
  • ruby (83)
  • ruby on rails (70)
  • jobs (62)
  • javascript (55)
  • techtalk (44)
  • rspec (38)
  • ironblogger (32)
  • productivity (30)
  • activerecord (29)
  • gogaruco (29)
  • git (28)
  • nyc (27)
  • rubymine (26)
  • bloggerdome (23)
  • mobile (22)
  • process (21)
  • pivotal tracker (20)
  • cucumber (20)
  • jasmine (19)
  • design (18)
  • ios (18)
  • webos (17)
  • objective-c (17)
  • android (16)
  • palm (16)
  • "soft" ware (16)
  • fun (15)
  • tracker ecosystem (15)
  • ci (15)
  • cedar (15)
  • rails3 (14)
  • performance (14)
  • bdd (14)
  • gem (13)
  • css (13)
  • tdd (13)
  • selenium (12)
  • goruco (12)
  • bundler (12)
  • meetup (11)
  • railsconf (11)
  • nyc-standup (11)
  • capybara (10)
  • mac (10)
  • mojo (10)
  • chef (10)
  • api (10)
Subscribe to Community Feed
  1. ←
  2. 1
  3. 2
  4. 3
  5. 4
  6. →
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >