Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Micro Libraries FTW

Micro Libraries FTW

Piotr Solnica

March 16, 2014
Tweet

More Decks by Piotr Solnica

Other Decks in Programming

Transcript

  1. BIG LIBRARIES MICRO LIBRARIES Solving many problems Solving just one

    problem Big LOC Small LOC Wide interfaces Narrow interfaces High churn even after 1.0 Low churn especially after 1.0
  2. Rails is in favor of huge libraries ActiveSupport and a

    wide adoption of monkey- patching ActiveRecord-like style - one object with a plethora of responsibilities and mixing seemingly related concerns
  3. “Many UNIX programs do quite trivial things in isolation, but,

    combined with other programs, become general and useful tools” The UNIX Programming Environment
  4. require "equalizer"! ! class GeoLocation! include Equalizer.new(:lat, :lng)! ! attr_reader

    :lat, :lng! ! def initialize(attributes)! @lat, @lng = attributes.values_at(:lat, :lng)! end! end! ! loc1 = GeoLocation.new(:lat => 123, :lng => 321)! loc2 = GeoLocation.new(:lat => 123, :lng => 321)! ! loc1 == loc2 # true! ! loc1.inspect! => #<GeoLocation lat=123 lng=321>
  5. require "anima"! ! class GeoLocation! include Anima.new(:lat, :lng)! end! !

    loc1 = GeoLocation.new(:lat => 123, :lng => 321)! loc2 = GeoLocation.new(:lat => 123, :lng => 321)! ! loc1 == loc2! # => true
  6. require "virtus"! ! class GeoLocation! include Virtus.value_object! ! values do!

    attribute :lat, Float! attribute :lng, Float! end! end! ! loc1 = GeoLocation.new(:lat => "123", :lng => "321")! loc2 = GeoLocation.new(:lat => "123", :lng => "321")! ! loc1 == loc2! # => true
  7. module ROM! class Mapper! ! # Abstract loader class! #!

    # @private! class Loader! ! # some stuff is here! ! # @api public! def call(tuple)! transformer.call(tuple)! end! ! end # Loader! ! end # Mapper! end # ROM This is morpher’s transformer and it takes care of everything
  8. Gather libraries that meet specific criteria Make it easy to

    find the right tool for the job Help in connecting maintainers and contributors Promote style of development that adheres to the unix philosophy Promote frameworks that are built on top of micro libraries