• 프로그램 개발과 유지/보수 시간 단축 --> 프로그래밍 생산성의 증가

  • 프로그램 실행 속도보다 프로그램 개발 속도가 더 중요하다.

1. 클로저 코드는 짧고 간결하다.

2. 클로저는 다른 동적 언어들에 비해 속도가 월등하게 빠르다.

3. 클로저는 Lisp 계열 언어다.

4. 클로저에서는 자바의 라이브러리를 그대로 불러 쓸 수 있다.

  • 클로저스크립트에서는 자바스크립트의 라이브러리를 그대로 불러 쓸 수 있다.

5. 클로저는 함수형 언어다.

  • Rich Hickey는 "클로저는 80% 함수형 언어다."

  • Haskell처럼 어렵지는 않다.

  • 함수형 언어가 주목받는 이유: immutability(변수의 내용을 한 번 초기화한 이후에는 변경 불가능)의 도입으로 상태(state)를 최대한 제거함으로써 프로그램의 복잡성을 최대한 줄여준다.

OOP:  code + data = class: data를 숨긴다
FP:   code와 data의 분리: data를 노출시킨다
객체지향언어에서의 상태 관리

oop

Clojure에서의 상태 관리

fp

6. 클로저는 동적 언어(Dynamc Language)이다

"It is better to have 100 functions operate on one data structure than 10 functions on 10 data structures."

— Alan Perlis
  • Ruby나 Python같은 다른 동적 언어들: 클래스(User-defined Type) 기반의 객체지향 언어

  • Clojure는 지원하는 데이터형이 많지 않다. (총 15개)

    • 장점: 함수의 합성이 용이

    • 단점: 세밀한 type checking을 하기 어렵다.

6.1. Ruby의 예

# box.rb
class Box
   # constructor method
   def initialize(w,h)
      @width, @height = w, h
   end

   # accessor methods
   def printWidth
      @with
   end

   def printHeight
      @height
   end
end

# create an object
box = Box.new(10, 20)

# use accessor methods
x = box.printWidth()
y = box.printHeight()

puts "Width of the box is : #{x}"
puts "Height of the box is : #{y}"
$ ruby box.rb
box.rb:12: warning: instance variable @with not initialized
Width of the box is :
Height of the box is : 20

6.2. Clojure의 예

(def box {:width 10
          :height 20})

(defn print-box [box]
  (println "Width of the box is" (:with box))
  (println "Height of the box is" (:height box)))

(print-box box)
; => Width of the box is nil
;    Height of the box is 20