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
John Barker

Start small and compose: A strategy for using FactoryGirl

John Barker
Tuesday, March 5, 2013

While I’m still not entirely sold on FactoryGirl, I often see it being used in a particularly lazy way. Imagine your basic factory:

factory :project

Before long you’re adding relations to projects, and the first thing people do is this:

factory :project do
  association :user
end

This immediately means that every single time you instantiate a project, you’re getting a user as well. In most cases this is more than you want, and if you continue to follow down this path you end up with a huge slow test suite. I prefer a slightly different strategy: start small and compose.

factory :project do
  ...
end

trait :with_manager do
  association :user, factory: :manager
end

This defines a very simple factory :project which gives you only a project and allows you to build a project with an associated user like so:

FactoryGirl.create(:project, :with_manager)

The result is a couple more arguments when you use the factory, but the overall code is more intention revealing.

If this is too much, you could always create a more descriptive factory:

factory :managed_project, parent: :project, traits: [:with_manager]

If you stick with this strategy, you’ll find that tests are more concise, factories are more useful and your test suite run time won’t grow as fast.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
John Barker

All evidence points to OOP being bullshit

John Barker
Thursday, February 21, 2013

This is the second part in a series I’m writing about lessons that can be learned from functional programming. Find the first part here.

Object Oriented Programming (OOP) as an idea has been oversold. The most commonly used languages in use today are designed around the idea of OOP. Extremist languages like Java force you to think of everything in terms of objects. But is Object Orientation (OO) a good idea? Does it have problems? Is it the right tool for everything? Let’s explore some of these questions in a slightly tongue in cheek and cathartic rant.

Imperative vs Declarative

The object-oriented model makes it easy to build up programs by accretion. What this often means, in practice, is that it provides a structured way to write spaghetti code. — Paul Graham

Procedural programming languages are designed around the idea of enumerating the steps required to complete a task. OOP languages are the same in that they are imperative – they are still essentially about giving the computer a sequence of commands to execute. What OOP introduces are abstractions that attempt to improve code sharing and security. In many ways it is still essentially procedural code.

Declarative languages on the other hand are about describing computation. While a a declarative language necessarily maps down to imperative code, the resulting code often reveals less incidental complexity and can sometimes be much more easily parallelized.

State

The problem with object-oriented languages is they’ve got all this implicit environment that they carry around with them. You wanted a banana but what you got was a gorilla holding the banana and the entire jungle. — Joe Armstrong

State is not your friend, state is your enemy. Changes to state make programs harder to reason about, harder to test and harder to debug. Stateful programs are harder to parallelize, and this is important in a world moving towards more units, more cores and more work. OOP languages encourage mutability, non determinism and complexity.

As someone who was initially hostile to the idea that state is the root of all problems, I initially greeted this idea with skepticism. Mutating state is so easy and fundamental in OOP that you often overlook how often it happens. If you’re invoking a method on an object that’s not a getter, you’re probably mutating state.

Nouns and Verbs

Java is the most distressing thing to happen to computing since MS-DOS. — Alan Kay

The typical college introduction to OOP starts with a gentle introduction to objects as metaphors for real world concepts. Very few real world OOP programs even consist entirely of nouns, they’re filled with verbs masquerading as nouns: strategies, factories and commands. Software as a mechanism for directing a computer to do work is primarily concerned with verbs.

OOP programs that exhibit low coupling, cohesion and good reusability sometimes feel like nebulous constellations, with hundreds of tiny objects all interacting with each other. Sacrificing readability for changeability. Many of  OOP best practices are in fact encouraged by functional programming languages.

Inheritance vs composition

Object-oriented programming is an exceptionally bad idea which could only have originated in California — Edsger W. Dijkstra

Inheritance is one of the primary mechanisms for sharing code in an an OO language. But this idea is so problematic that even the keenest advocates of OO discourage this pattern. Inheritance forces you to define the taxonomy and structure of your application in advance, with all it’s connections and intricacies. This structure is resistant to change which is one of the primary problems software developers face every day. It also fails to model some pretty fundamental concepts.

Further reading

This is far from an exhaustive list of the criticisms leveled at OOP. While I believe the problems with OOP are extensive, I do think it is a valuable mechanism for developing software. But is certainly not the only one. The biggest problem in my mind is thus:

When people overcome the significant hurdle of fully appreciating OOP, they tend to apply it to every problem. OOP becomes the solution, and every problem looks like a nail.

There’s got to be a better way…

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
John Barker

Why you should care about functional programming.

John Barker
Wednesday, January 30, 2013

I’ve been experimenting with functional programming (FP) languages for a little while now and their acceptance is generally increasing amongst the wider developer community. This is the first post in a series of articles I hope to do that explore FP, what it is and what we could learn from this trend.

Why now?

Functional programming languages are by no means new. LISP often thought of as one of the first programming languages was developed in 1958. IPL a sort of assembler like symbolic language appeared in 1954. The foundations of FP are embedded in mathematical constructs much older than the concept of an electronic computer.

But for all intents and purposes they sort of disappeared into obscurity, replaced by procedural languages like C or Object Orientated (OO) like C++ or Java. Partially because they were impractical – some of the constructs used by FP languages performed worse than their imperative counterparts. In a time when CPU power was scarce, this was not an option.

A different age

Thanks to Moore’s law this has changed somewhat. Computers now are certainly more powerful then they were when the first LISP interpreter appeared. But the ever scaling MHZ peak has slowed. New CPUs come with more cores, not more cycles. To take advantage of these improvements we need to look to parallelization and FP languages are inherently suited to this kind of work.

I am not alone in recognizing this. IBM released this article recognizing the rising trend. ThoughtWorks has identified Scala and Clojure in its technology radar and recognizes momentum building behind several FP languages: http://www.drdobbs.com/mobile/thoughtworks-eyes-seismic-shift-in-progr/240009675. Spend any time on Hacker News and you’ll regularly see links on the topic.

I feel like FP is an idea whose time has come and I’m very excited by the new languages, ideas and technologies that are appearing. Hopefully Pivotal Labs will someday join me on this journey.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Andrew Fader

Field Trip Chronicles: Pivotal NYC Hardware Hacking Club

Andrew Fader
Thursday, October 4, 2012

Pivotal NYC’s resident solder-happy Arduino-slingers (Pivotal Labs Labs, if you will) took a field trip today to Hack Manhattan, a hacker space, garden, and science laboratory on 14th street near our office. Hack Manhattan has, among other useful tools, a CNC mill, lathe, plotter, and several 3D printers in various stages of assembly. Members and friendly visitors are free to use the tools provided they know how, and may attend classes on various topics.

A joint venture between followers of the collective hacker ethos espoused by Brooklyn space NYC.Resistor, and a team of vigilante biologists, Hack Manhattan also boasts a rooftop garden complete with a solar-powered hydrolysis device and a chest of lively bees. Click through to a brief photo tour of our trip.

























  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Paul Meskers

09/07/12: Comedy Hackfest

Paul Meskers
Friday, September 7, 2012

Interestings

  • Open Shift now supports Rails 3.2, Sinatra, MRI 1.9.3, MySQL, Postgres, and MongoDB

They even have a wizard for bootstrapping a Rails application.

https://openshift.redhat.com/community/developers/get-started

Or signup/login here to try out the wizard: https://openshift.redhat.com/app/login?redirectUrl=%2Fapp%2Fconsole

Events

  • Saturday: Comedy Hackfest

All weekend.

partner comedians and developers together to see who can come up with funny apps.

http://comedyhackday.eventbrite.com/?access=4thelulz

  • Sunday: Comedy Hackfest

All weekend.

partner comedians and developers together to see who can come up with funny apps.

http://comedyhackday.eventbrite.com/?access=4thelulz

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Dimitri Roche

[Standup][NY] 09/06/12: PG 9.2 to include JSON data type!

Dimitri Roche
Thursday, September 6, 2012

Interestings

  • Postgres 9.2 to include native JSON data type

Postgres 9.2 will include a native JSON datatype. In addition to verifying that the data stored in the field is valid JSON, there’s also a couple of SQL functions that could be handy (array_to_json, and row_to_json).

There’s a promising pull request for ActiveRecord to support the new json data type.

  • Show gem license on rubygems.org

Our open source developers this week have submitted a pull request to rubygems.org to display a gem’s license on the gem version’s page.

Make sure you add a license to your gemspecs!

Gem::Specification.new do |s|
  s.license = "MIT"
  #....
end

or…

Gem::Specification.new do |s|
  s.licenses = ["MIT", "BSD"]
  #....
end

Pull request: https://github.com/rubygems/rubygems.org/pull/458

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Dimitri Roche

[Standup][NY] 09/04/12: Math proofs like unit tests?

Dimitri Roche
Tuesday, September 4, 2012

Interestings

  • Gotcha

Don’t make a helper method called config in your rails app. It will blow up in your face.

  • Cool 3D js UI hack for displaying menus

This looks great for touch devices, but may not be obvious to users.

Try this URL for standup:
http://lab.hakim.se/meny/?http://ny-whiteboard.herokuapp.com

  • Bootstrap 2.1 dropdown data-* fail

Links within dropdowns which leverage data-* method’s currently broken in Bootstrap 2.1.

Events

  • Wednesday: Agile Experience Design Meetup
  • Tuesday: Tech Talk- Why is a Math Proof like a Unit Test?

There are many conceptual similarities between writing a mathematical proof and test driving a story. In this talk, I will explore these similarities in an effort to explain what is satisfying about TDD, and what makes it a great learning tool. Join us for lunch as Daniela previews her upcoming GoGaRuCo talk.

Daniela majored in Math, attended a Railsbridge, apprenticed at Pivotal SF and now is a developer at SharesPost.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Mark Gangl

08/31/12: Labour Day!

Mark Gangl
Friday, August 31, 2012

Interestings

  • :last-child vs :first-child

Just a friendly reminder that :last-child is less cross-browser-friendly than :first-child (IE8 and earlier do not support it).

  • rails 3.2.8 + increment!

increment! doesn’t call before_update callback

https://github.com/rails/rails/issues/7306

  • devise with no database

Looking for tips on using devise without a database

Events

  • Monday: Labor Day!!
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Andrew Fader

NYC Standup 7/18/2012

Andrew Fader
Wednesday, July 18, 2012

Interestings

  • Array.new(size, obj) vs Array.new(size) { block }

Array.new(size, obj) will duplicate the object, whereas Array.new with a block will call the block n times, resulting in different objects.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Andrew Fader

NYC Standup 8/24/2011: iTerm Time Machine

Andrew Fader
Wednesday, August 24, 2011

Interesting Things

  • Ben discovered that Cmd+Opt+B is a magical time machine for iTerm, complete with a scroll bar for traveling back and forth in the buffer. He was quick to point out that this feature, cool as it is, will not actually send the user back in time.
  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Topics

  • agile (781)
  • 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 (21)
  • cucumber (20)
  • design (19)
  • jasmine (19)
  • ios (18)
  • webos (17)
  • objective-c (17)
  • android (16)
  • tracker ecosystem (16)
  • palm (16)
  • "soft" ware (16)
  • fun (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 nyc Feed
  1. 1
  2. 2
  3. 3
  4. →
  • 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 >