Thursday, June 09, 2011

Readable Racket

The two Racket snips are functionally equal, but 'read' different.  To my ill-trained mind the logic in netpay is easier to read, while netpay2 is dense and hard to parse, on first glance.

#netpay

(define (wage h)
(* 12 h))

(define (tax h)
( * ( / (* 12 h) 100 ) 15))

(define (netpay h)
( - (wage h) (tax h)))


# netpay2

(define (netpay2 h)
( - (* 12 h) ( * ( / (* 12 h) 100 ) 15)))

Possibly the profusion of parenthesis in a LISPy programming is, for me, a pickle.

Anyway. That's another exercise from 'How to Design Programs' out of the way. My monkey-brain has got it's reward pellet for the morning. Onward, Excelsior and etc.
blog comments powered by Disqus