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

The Functional Discipline

Pedro Costa
September 22, 2017

The Functional Discipline

Slides of my talk at PartialConf 2017

Pedro Costa

September 22, 2017
Tweet

More Decks by Pedro Costa

Other Decks in Programming

Transcript

  1. 1 class GenerateBillText 2 attr_accessor :currency, :value 3 4 def

    initialize(currency:, value:) 5 @currency = currency 6 @value = value 7 end 8 9 def call 10 # ... generate image through ImageMagick ... 11 end 12 13 private 14 15 # ... any auxiliar method .. 16 end 17 18 GenerateBillText.new(currency: :eur, value: 1)
  2. 1 class StepChain 2 attr_accessor :klasses 3 4 def initialize(*klasses)

    5 @klasses = klasses 6 end 7 8 def call(initial) 9 klasses.reduce(initial) do |current, klass| 10 klass.new(current).call 11 end 12 end 13 end 14 15 StepChain. 16 new(GenerateBillText, ...). 17 call(currency: :eur, value: 1)
  3. 1 class BillTextImage 2 attr_reader :path 3 4 def initialize(path:)

    5 @path = path 6 end 7 end 8 9 BillTextImage.new(path: "~/tmp/bill_text.png")
  4. ?

  5. ?

  6. OMG

  7. Discipline is optional • You can reinvent the wheel, every

    time • You can be inconsistent • You can break boundaries • You just should not.
  8. –Daniel Kahneman, “Thinking, Fast and Slow” “System 1 operates automatically

    and quickly, with little or no effort and no sense of voluntary control.”
  9. –Daniel Kahneman, “Thinking, Fast and Slow” “System 2 allocates a!ention

    to the effortful mental activities that demand it, (…). The operations (…) are often associated with (…) agency, choice and concentration.”
  10. –Admiral William H. McRaven
 “University of Texas at Austin 2014

    Commencement Address” https://www.youtube.com/watch?v=pxBQLFLei70 “If you can’t do the little things right, you will never do the big things right.”