tdc2016poa | trilha programacao funcional - considere usar clojure/clojurescript na sua próxima web...

48
Considere usar Clojure/ClojureScript na sua próxima web App What is it and why is it interesting?

Upload: tdc-globalcode

Post on 15-Apr-2017

203 views

Category:

Education


0 download

TRANSCRIPT

Considere usar Clojure/ClojureScript na sua próxima web App

What is it and why is it interesting?

About [email protected]

in/devpaulomarquesfb/devpaulomarques

ADS Senac-RSDomTI

“APRENDER UMA NOVA LINGUAGEM DE

PROGRAMAÇÃO É SÓ APRENDER A SINTAXE”

Algum amigo seu.

Timeline

● Lisp 1958● Clojure 2007● Clojure 1.0 2009● Clojure 1.8 2016

What is Clojure?

Clojure is a functional Lisp that targets the JVM and enables simpler software design.

Clojure is a Lisp

Clojure is a Lisp

Clojure is a Lisp

Code as data

Clojure is a Lisp

No sintax

It looks like this

(def a 1)

(def f (fn [x] (* 2 x)))

(f a) ;; 2

(f (+ a 10)) ;; 22

Clojure is a Lisp

REPL

Read-Eval-Print-Loop

Macros(defmacro expect [value to|!to matcher match]

(let [assertion (if (= matcher 'be)

`(= ~value ~match)

`(~matcher value match))]

(if (= to|!to 'not-to)

`(is (not ~assertion))

`(is ~assertion))))

;; isso expande para:

(testing "Sum is working"

(is (not (= (+ 2 2) 3)))

(is (= (+ 2 1) 3)))

Macros

????

Macros(defmacro expect [value to|!to matcher match]

(let [assertion (if (= matcher 'be)

`(= ~value ~match)

`(~matcher value match))]

(if (= to|!to 'not-to)

`(is (not ~assertion))

`(is ~assertion))))

;; isso expande para:

(testing "Sum is working"

(is (not (= (+ 2 2) 3)))

(is (= (+ 2 1) 3)))

Paradigms as Libraries

Design by Contract - core.contracts

Logic Programming - core.logic

Lightweight threads + channels - core.async

Optional/Gradual Type system - core.typed

What is Clojure?

Clojure is a functional Lisp that targets the JVM and enables simpler software design.

Targets the JVMConstructornew Person("Paulo");

(Person. "Paulo")

Static Member Math.PI // 3.141592653589793

Math/PI ;; 3.141592653589793

Instance Method " Hello world! ".trim(); //Hello world!

(.trim " Hello world! ") ;;Hello world!

Targets the JVMChained Access person.getAddress().getState().getCode();

(.. person getAddress getState getCode)

Targets the JVMChained Access person.getAddress().getState().getCode();

(.. person getAddress getState getCode)

(macroexpand '(.. person getAddress getState getCode))

(. (. (. person getAddress) getState) getCode)

Targets the JVMMultiple Updatesperson.setFirstName("Ben");

person.setLastName("Mabey");

person.makePresenter();

(doto person (.setFirstName "Ben") (.setLastName "Mabey") .makePresenter)

What is Clojure?

Clojure is a functional Lisp that targets the JVM and enables simpler software design.

Clojure is functionalAvoid state changes

First class functions

High order functions

Why is Clojure interesting?

● Succinct

Why is Clojure interesting?

● Succinct● Java Interop

Why is Clojure interesting?

● Succinct● Java Interop● Multi-threaded

Why is Clojure interesting?

● Succinct● Java Interop● Multi-threaded● Lazy

Why is Clojure interesting?

● Succinct● Java Interop● Multi-threaded● Lazy● Fun● ...

ClojureScript

JavaScript

ClojureScript

ClojureScript

Why ClojureScriptGoogle closure compiler

Why ClojureScriptGoogle closure compilerModularity

Why ClojureScriptGoogle closure compilerModularityImmutability

Why ClojureScriptGoogle closure compilerModularityImmutabilityAnd...

REPL

React

Cljs + Reagent

Reagent minimalistic interface between ClojureScript and React

HiccupHiccup is a library for representing HTML in Clojure

Reagent

Reagent

Add some style

Garden

Cljs + Reagent + Garden

Thanks