Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Perhaps we can try to do it in a proper functional language?

  (ns restaurant.pizza
    (:require [restaurant.oven :as oven]
              [restaurant.package :as pack]))

  (defn make-order [size sauce cheese kind]
    {:size size
     :sauce sauce
     :cheese cheese
     :kind kind})

  (def toppings-map
    {"Veg" "Veg toppings"
     "Meat" "Meat toppings"})

  (defn prepare [order]
    (assoc order :toppings (:kind order)))

  (defn bake [prepared-order]
    (oven/bake prepared-order :pizza))

  (defn box [baked-pizza]
    (pack/box baked-pizza :pizza))

  (defn pizza [order]
    (-> order
        prepare
        bake
        box))

  (comment 
    (def order (make-order 26 "Tomato" "Mozzarella" "Meat"))
    (pizza order))


It's short and overwhelmingly granular, but for the sake of illustration. Large and complex codebases sliced up this way has not alternative in terms of ease of testing and reasoning about the code.


In your experience, how do LISPs compare to ML family languages in typing and readability?


I don't necessarily have opinions on ML languages. Haven't used any of it to the extent of writing more or less complex production system.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: