atual <- 1! ant <- 0! repita! num <- atual + ant! escreva ("num")! ant <- atual! atual <- num! cont <- cont + 1! ate (cont = n-2) The (not really) amazing Portugol
class Address attr_reader :street, :complement, :city ! def initialize(street, complement, city) @street = street @complement = complement @city = city end ! def to_s "#{street}, #{complement}, #{city}" end end A boring Address
require 'virtus' ! class Address include Virtus.value_object ! values do attribute :street, String attribute :complement, String attribute :city, String end end github.com/solnic/virtus
class BankAccount attr_reader :current ! def initialize @current = 0 end ! def deposit(amount) @current = current + amount end ! def withdrawal(amount) @current = current - amount end end a robust banking system
class BankAccount attr_reader :current ! def initialize(current) @current = current end ! def deposit(amount) BankAccount.new(current + amount) end ! def withdrawal(amount) BankAccount.new(current - amount) end end no mutations
Wanna learn more? ! Amazing blog post from the author of the Hamster lib http://www.harukizaemon.com/blog/2010/03/01/functional-programming-in-object-oriented- languages/ ! Anything Rich Hickey http://thechangelog.com/rich-hickeys-greatest-hits/ ! The Tar Pit paper http://shaffner.us/cs/papers/tarpit.pdf ! Clojure’s take on State http://clojure.org/state