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: May 2009

Writing Fast Ruby: Learning from Merb and Rails 3

Saturday, May 30, 2009 | Run time: 35:53

It has been said that Ruby is a slow language, but that is not true. Numerous Ruby projects have shown that it is possible to write fast, scalable software using Ruby. Merb, for instance, is faster than any major PHP web framework.
In this talk, Carl will show how to take the many available tools, such as ruby-prof, RBench, and kcachegrind, and turn any old Ruby into a speed machine. The tips and processes will be demonstrated with real world examples of optimizations that have been done to the Merb and Rails 3 projects.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Discussion Panel: Ruby Application Frameworks

Saturday, May 30, 2009 | Run time: 1:04:35

Many of us discovered Ruby because of Rails, but there are many more frameworks for both web development and other application domains. We have assembled authors and contributors from six of the major application frameworks written in Ruby: Rails, Merb, Sinatra, Adhearsion, RAD and Shoes. We’ll get to hear what they have to say about what makes Ruby good (or bad) for building frameworks, and what opinions they have of other frameworks. Come with your questions, and demand answers!

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Building Custom Web Proxies in Ruby

Saturday, May 30, 2009 | Run time: 38:20

A high-performance proxy server is less than a hundred lines of Ruby code and it is an indispensable tool for anyone who knows how to use it. In this session we will walk through the basics of event-driven architectures and high-performance network programming in Ruby using the EventMachine framework.

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

Building Cross Platform Mobile Apps with Ruby & PhoneGap (Ben Stein)

Pivotal Labs
Saturday, May 30, 2009

Ben Stein of Mobile Commons is giving a talk on Cross-platform Mobile App development. They hadn’t done any client mobile work, but lately clients have been asking “what about iPhone?,” “what about Android?” and the like. Whether or not this question of navigating the mobile client world is important to you now, Ben predicts it will soon be, as that’s where we’re headed.

Thoughts and experiences from Mobile Commons’ first mobile client apps:

Why Mobile?

Mobile give you capabilities not available elsewhere:

  • Location
  • Accelerometer & Orientation
  • Phone & Contacts
  • Camera
  • Sound & Vibrate

This is a big list – serious stuff.

Uncool things about mobile

  • Unreliable network connectivity
  • Java, Objective-C
  • Memory Management

Options for mobile

  • Maybe your Rails Web app is good enough
  • A mobile-formatted version of the web site
  • A client app

Mobile-formatted sites

  • alternate stylesheets
  • separate mobile subdomain
  • WURFL

Mobile-formatted cons

  • No cool mobile features
  • No app store distribution
    ** have to bookmark, no $$

iui, iPhone, Rails

  • iui & rails-iui: gives you stylesheet and typical iPhone ajaxy interaction
  • acts_as_iphone_controller
  • index.iphone.erb
  • Mime::Type.register ‘text/html’, :iphone

Native Apps

  • Rich User experience
  • Cool device features
  • App store distributions

Native Apps: Cons

  • New technologies
  • Different technologies
  • Frameworks to learn

“There are only so many hours in the day to learn new technologies.”

Alternative Tech Stack

  • Webkit rendering engine (HTML/CSS)
  • Business logic in web application
  • Javascript for mobile features
    (accelerometer, location, phone, &c.)
  • HTML5 Client-Side Storage (SQLite + JS)

This Javascript interface to phone features potentially allows consistent behavior across many devices. And hybrid we apps can serve double-duty, doing work both on and offline.

HTML 5

  • Proposed 6 years ago, working group started in 2007. Implementations emerging, particularly in Webkit, which is the common mobile renderer.

Features:

  • Canvas
  • Video Tag
  • Geolocation
  • Web Workers (i.e. Javascript Threads)
  • Client-side Storage
  • and more…

3 Types of Storage

  • Structured Storage
  • AppCache
  • Client Database

sessionStorage and localStorage are shared Javascript Hashes available across all your pages.

HTML5: App Cache

Also defines a mechanism for enabling intelligent client-side caching.

HTML5: Databases

  • Defines an interface for client-side databases
  • Javascript & SQLite Implementations

Ben then demos a sticky-note app which works currently in Safari, and works with client-side persistent storage.

Security & Privacy

This makes cookie resurrection easy, so the designers include a same-domain policy in the spec, to reduce access.

GMail on the iPhone

Currently uses the app-cache and asynchronous updates to enable offline access.

PhoneGap

  • Open-source Project by Nitobi
  • Javascript library + native code
  • Enables a common javascript interface to phone features

XUI Javascript Library

jQuery minus all the browser compatibility code, optimized for Webkit & Mobile phones.

HttpClient.app

Don’t use Curl to test these apps, use HttpClient, which deals with much of the basics, including authentication

Demo App

Mobile Commons has made an application for allowing individuals to receive messages including a link to immediately phone their representatives. This uses Mobile Commons’ legislative district database, and other phone features including location and client-side caching, accessed via Javascript.

The phone number is linked with the a ‘tel:// ‘ URI which then allows initiating a call from within the phone.

These projects can be built and managed out of eclipse for Android and XCode for iPhone.

Downsides

  • Apps don’t quite feel native. A bit slower, not quite as polished.
  • Not good for graphics, games, &c.
  • App store policies? Reports that some apps have been rejected for using these frameworks.

What’s Next?

  • HTML5 spec not yet finalized
  • Tons of fun work to add HTML5 functionality to Rails

Q & A

What about Migrations?

There’s no easy answer, this is one of the reasons we switched to Web development, because we have more control and the easy ability to push updates. Client migration support is also theoretically possible, but has yet to be implemented.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

There Will Be Ruby!

Saturday, May 30, 2009 | Run time: 28:19

Have you ever tried to catch a train running at a million miles an hour? Jumping into the traffic stream at Wikipedia is an insane adventure I’ve been going through. Exactly how do you launch a new platform that could instantly have millions of hits in a few hours? How do you do that and not spend 3 years researching? A fun tour of how I got Ruby at Wikipedia and did it with confidence, bravado, and alcohol. There will be cussing and lots of funny stories that should be highly educating and an insight into my technical philosophies.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

TrustTheVote: Open Source Digital Voting

Saturday, May 30, 2009 | Run time: 31:40

This talk will present the TrustTheVote project and the “I count!” movement. It will cover the technology roadmap, progress so far, and next steps, including expansion of development efforts and opportunities for involvement in design and construction of trustworthy voting technology that everyone will be able to see, touch, and try—technology that will be fully federally certified and have the endorsement of the States’ elections directors through a unique approach that can ensure widespread adoption. If you have ever wanted to know what you can do to make a difference in our electoral process, then this talk is for you.

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

SOLID Object-Oriented Design (Sandi Metz)

Pivotal Labs
Saturday, May 30, 2009

Sandi Metz, a Dukie visiting from NC, will be talking about SOLID principles of software development:

  • Single Responsibility
  • Open Closed
  • Liskov Substitution
  • Interface Segregation
  • Dependency Inversion

All of Sandi’s code is available here.

Change

Fact: your application is going to change. How will your application handle that change?

Robert Martin says your app can behave a couple of different ways:

  • Rigid: Making a change somewhere will break something somewhere else.
  • Fragile: You can’t predict where that break will be.
  • Immobile: It’s hard to change your code.
  • Viscous: It’s easier to do the wrong thing than to fix things.

In the beginning, though, your app was perfect. “Dependencies are killing you!”

Design might save you.

The Design Stamina Hypothesis says that, after a certain point, you’ll have done better if you had designed first.

“Skip design, if you want your app to fail.”

To avoid dependencies, your design should be:

  • Loosely coupled
  • Highly cohesive
  • Easily composable
  • Context independent

Ignorable Rules

SOLID principles we can ignore in ruby:

  • Interface Segregation

    Really only a problem for statically-typed, compiled languages. Because we’re in Ruby, we don’t have this problem! Win!

    “Dynamic languages obey this rule in the most extreme way possible: duck typing.”

  • Liskov Substitution

    When you design, don’t break the contract of the superclass in the subclass.

Testing Interlude

Sandi draws her examples of applicatoin change from the source code at: http://skmetz.home.mindspring.com/img28.html.

Lesson #1: Resistance is a Resource.

  • Don’t be attached to your first idea
  • Embrace the friction
  • Fix the problem

If testing seems hard, examine your design. Tests depend upon the design of the code. “TDD will punish you if you don’t understand design.”

During refactoring, ask yourself:

  1. Is it DRY?
  2. Does it have one responsibility?
  3. Does everything in it change at the same time?
  4. Does it depend on things that change less often than it does?

The answers should all be ‘yes’.

Important Rules

Sandi references her code to demonstrate when and how to mock and use dependency injection to achieve Single Responsibility, in which a class both downloads and acts upon the downloaded data.

She urges developers to do the simplest possible refactoring when extracting responsibilities from a class.

“Refactor, not because you know the abstraction, but because you want to find it.”

Sandi uses a very interesting example of building a Config class which behaves differently in different Rails environments. The first version had a lot of smell, and with a combination of hash parameters, YAML file, and metaprogamming, she demonstrates how to be open for extension, but closed for modification.

Sandi explains that paying attention to your classes’ dependencies is important. If a relatively static class is dependent on a class that changes more often, that’s a smell! Use dependency injection to avoid Dependency Inversion.

Summary

“TDD, BDD and DRY are all good, but they are not enough.”

“Design because you expect your app to succeed, and the future to come.”

Sandi recommends reading:

  • http://www.objectmentor.com/resources/articles/Principles_and_Patterns.pdf
  • http://www.mockobjects.com/book
  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Playing With Fire: Running Uploaded Ruby Code in a Sandbox

Saturday, May 30, 2009 | Run time: 28:40

In this session, David Stevenson explores how to run untrusted code inside a ruby application using a sandbox. With this powerful technique, users can upload code that integrates as part of a larger application, making it ideal for custom business rules, dynamic games (think SecondLife), and science/math applications. Ruby’s english-like syntax and ease of creating DSLs makes it a good scripting candidate for non-technical people.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Sinatra: The Framework Within

Saturday, May 30, 2009 | Run time: 26:42

Sinatra has been getting a lot of attention lately as the next great (micro-)framework. In writing apps, diving in, and contributing the reasons for its existence have become more clear. Sinatra is not just a toy or a neat trick, its the best way to create simple and non-obtrusive web interfaces to sit on top of a new or existing Ruby codebase. I’ll walk through the whats, whys, and tools for getting started with Sinatra.

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

Into the Heart of Darkness: Rails Anti-Patterns (Jake Howerton)

Pivotal Labs
Saturday, May 30, 2009

Jake Howerton gave a GoRuCo talk about Rails Anti-Patterns, drawn from his years as a rails developer.

Over lunch with Jake, I’d wondered aloud “where are all the wide-eyed optimistic presentations?” and Jake starts by saying he’s sorry that this will not be one of those talks.

We’ve been programming in Rails for several years now, and now more than ever we’re left with the problem of how to deal with, maintain and correct projects which may be riddled with out-dated thinking, mistaken ideas and problematic implementations.

In other skilled enterprises there are core ideas which are repeated by for practice and for their general utility. In martial arts, these are called “katas,” in programming, we have “patterns.” Patterns are general, reusable solutions to common problems in software engineering, which are often arrived at through emergent design. Anti-patterns, likewise, emerge in the general work on a project, but their presence is harmful. They’re the mistakes we make again and again in our projects.

Jake then laid out a few patterns and anti-patterns for your consideration:

1. Know your APIs

Some of the most egregious anti-patterns come from simple ignorance about the APIs available, and the consequential re-implementation of basic Ruby or Rails functionality. The Rails and Ruby APIs are both well-documented and important to your work. There’s no excuse not to know them.

2. script/plugin and gem installitus

While we must install a plugin or gem to use it, often we move on without doing the important job of cleaning up after ourselves.

3. Style

  • if not self.value.nil?

People litter ‘self’ all over the place. The only place you need self is on assignment. And all this could be replaced with the simple line:

if value

  • @value = 600 if @value.nil?

@value ||= 600

  • some_value == nil?

What does this even mean? ‘nil?’ is false unless inside NilClass

  • IRB-driven Design

Occasionally we hack away in IRB and, once we get the results we’re looking for, drop the code into our app without a second thought. This can produce some very buggy, obtuse, far-from-minimal code. Once we discover a mechanism, better to revisit the problem and produce the code in a more stable context.

  • !!value

Confusing. Not to be used outside of a predicate method.

4. Planning is Hard

Will you remember what your boss tells you to do a year ago? Will you unknowingly violate these past decisions and understandings? To avoid doing so it’s important to maintain active specs against your app.

Jake recommends Cucumber + Webrat for carrying this out.

5. How Bad Is It?

There’s a gem called metric_fu, a gem full of analytics. One in particular is known as Reek, which sniffs out code smells.

Run reek against your app, and it will find long methods, for example, and return all of the methods that are longer than 5 lines. And you can make your tests fail on the existence of these methods, to keep yourself and your team in check.

6. Orphans

Orphans are methods, models, views or controllers, or any other bit of functionality which is disconnected from the rest of your app. Like un-used plugins or gems, orphan code is noise which keeps your code from being easily maintainable.

7. (Dis)Organization

We can look to the more modular, merb-style project organization as a way of better structuring our projects. Likewise the Fat-model, Thin-controller design pattern helps us to create easily-testable, well-organized apps.

8. Testing!

  • The valueless test

assert_equal 2, User.count

This test fixtures, and activerecord, and its very presence hinders us by interfering with our view of more meaningful tests.

  • The slow test

Any slow test has a cost of both slowing the testing feedback loop and making it less likely that we’ll run the tests as often as we should.

  • The coupled test

Coupled tests mean that a test depends on the side-effects of other tests, or on the effects of an outside service or application. Instead we can mock out the outside web service or operation

  • Complex tests mean complex code

9. Make Decisions and Document Them

Discuss your code conventions and style with the team, settle on a set of best practices, and write them down. Store them in a style guide in the project root or document directory.

10. Continuous Integration

Jake recommends using Integrity Continuous Integration Server. Whether you use that or Cruise Control, or any other option, continuos integration insures your specs and tests are frequently and consistently run.

11. Build Artifacts

Generating and maintaining build artifacts, such as statistics reports from your reek run or performance tests can enable you to track your progress over time. In addition, you put minimal expectations on these

12. Reviews and Retrospectives

Taking time every few months to review your recent progress, and discuss problems and progress.

Q & A

Someone mentions a particularly egregious example of a test which deleted its own application code in the process of running.

Jake responds that in cases where tmp deletion and file generation, it may be appropriate to have a safe version of the test which runs locally, and a separate exhaustive test which runs in a sandbox staging environment. This allows you to exercise the more dangerous tests in a safe environment.

Yehuda mentions one way to do this is to mock in the safe version, and turn of that mock in the sandbox environment.

Egregious Code

Jake then shows a 45-line login method and points out how difficult it is to immediately grok. Newer-code built in the REST-ful style is much simpler to work with.

Conclusion

By discussing these approaches with old-hands and newbies alike, we can all improve the quality of our code, spend less time dealing with bugs or code comprehension, and more time building out the next great Rails projects.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Topics

  • agile (778)
  • rails (113)
  • testing (87)
  • ruby (83)
  • ruby on rails (70)
  • jobs (62)
  • javascript (54)
  • techtalk (44)
  • rspec (38)
  • activerecord (29)
  • productivity (29)
  • gogaruco (29)
  • ironblogger (29)
  • git (28)
  • nyc (27)
  • rubymine (25)
  • bloggerdome (22)
  • mobile (22)
  • cucumber (20)
  • process (19)
  • pivotal tracker (19)
  • 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)
  • tdd (13)
  • selenium (12)
  • css (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. 5
  7. 6
  8. 7
  9. 8
  10. →
  • 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 >