Hacker News new | ask | show | jobs
by cageface 5109 days ago
This is exactly the opposite of the advice recently given by Rich Hickey in his keynote at RailsConf 2012, where he strongly recommends using simple, transparent data structures without a lot of OO wrapping baggage.

Personally I'm on the fence but when you look at how much boilerplate this Virtus example needs to get rid of the code "smell" you have to wonder if maybe he has a point.

3 comments

Rich is so spot-on. Here's a variant of that talk: http://www.infoq.com/presentations/Simple-Made-Easy

And funnily enough I had the itch to say I'm a primitive obsessive today: http://williamedwardscoder.tumblr.com/post/25916255470/taxon...

It almost feels like a reply to this post, but it was an coincidental bit of pontification.

I think it just comes down to differences between the OO approach vs the functional approach.

In OO code I try to create types to represent every concept in my code. It seems overkill at first but I have found in most cases it pays off with reduced duplication. It almost always removes the question of where to put static utilities. Lets say you have a postcode - by creating a Postcode type you can put postcode validation, postcode formatting, etc, directly on that type rather than floating in different parts of your codebase.

Additionally, in a statically typed language it adds type safety - so for example you can't pass a postcode into an address parameter.

I agree. Unless one has Algebraic Data Types, primitives are almost always the better option.