Share
Embed
Transcript
66 slides
-
@ArgesRic WHO AM I? • Ricardo J. Méndez • Entrepreneur,
founder, Numergent • Clojure articles at http://numergent.com/articles/ • Twitter: @ArgesRic -
@ArgesRic WHAT DO I DO? • CTO for hire running
projects for large companies • Working on our own projects (open source and otherwise) • Previously: • Data analysis for banking, healthcare • Game development -
@ArgesRic HOW DID WE GET TO CLOJURE? • First encountered
LISP over 20 years ago • Genetic programming! • Fascinated with the language… • Limited tooling and libraries. -
@ArgesRic HOW DID WE GET TO CLOJURE? • It was
different. • Had access to the full Java platform… • …while still giving you a fully functional approach. • New paradigms shake up your thought process. -
@ArgesRic OTHER OPTIONS? (Event though it aims to solve the
same problems as Clojure) -
@ArgesRic WHAT WE’LL TALK ABOUT • Not a language intro.
• For a great one, see Rich Hickey’s “Clojure, Made Simple” https:// www.youtube.com/watch?v=VSdnJDO-xdg • Focus on how design decisions affect your work. • Won’t be overloaded with code samples. -
@ArgesRic BIASES • Somewhat personal talk - will focus on
why it works for me. • I’ve always found the elegance of LISPs appealing. • SPOILER ALERT: Unapologetically positive about it… • … so we’ll start with the scary bits. -
@ArgesRic IT WILL SEEM WEIRD • Not because of grammar…
• Not because it’s a different vocabulary… • But because it has different semantics. -
@ArgesRic … BECAUSE OF ITS SEMANTICS • Clojure doesn’t just
use different words, • Clojure’s mechanism for making meaning is different. -
@ArgesRic … BECAUSE OF THE PROBLEMS IT SOLVES “We can't
solve problems by using the same kind of thinking we used when we created them.” — Albert Einstein (Totally not an appeal to unrelated authority) -
@ArgesRic DOCUMENTATION into (into to from) (into to xform from)
Returns a new coll consisting of to-coll with all of the items of from-coll conjoined. A transducer may be supplied. -
@ArgesRic DOCUMENTATION “the site is fucking useless, its more confusing
than helpful” — Radu (Related authority on the learning curve) -
@ArgesRic DOCUMENTATION • Doesn’t tell you that you can ignore
transducers for now. • Doesn’t tell you that there’s a conj verb. • Doesn’t tell you anything else that might help a newbie. -
@ArgesRic DOCUMENTATION • It's going to take one collection, and
move it into a different collection by conjoining items to it. • Why conjoining? • conjoin as a verb has a specific meaning in Clojure. -
@ArgesRic IMMUTABILITY AND FUNCTIONAL PROGRAMMING Show of hands… how many
are doing functional programming? -
@ArgesRic IMMUTABILITY AND FUNCTIONAL PROGRAMMING • Functions are not methods
by a different name. • Take values, returns a value… • … but doesn’t change anything in the middle. -
@ArgesRic IMMUTABILITY AND FUNCTIONAL PROGRAMMING • C# has LINQ, which
sorta gets you there… • Java is finally catching up… • … but neither enforces immutability. • You’re still juggling objects. Some will methods will change properties. -
@ArgesRic IMMUTABILITY AND FUNCTIONAL PROGRAMMING • That’s fine when you
have a couple classes. • Maybe you can keep the side effects in mind as you code. • Maybe you know what that ProcessTransactions() returns a value, but changes a couple of things… • … but we are fallible, with finite mindspace. -
@ArgesRic IMMUTABILITY AND FUNCTIONAL PROGRAMMING Even assuming you can keep
all those side effects in mind… why would you want to? -
@ArgesRic IMMUTABILITY AND PARALLELISM • Immutability makes parallelism much simpler.
• Look ma, no locks! • You don’t care where it runs, since nobody will modify the data. • Had to do parallelism by hand before. Never going back. -
@ArgesRic MASSIVE SYNTAX • Bigger problem than unfamiliar semantics. •
You only need to learn semantics once, syntax is an on-going cost. • Again… it uses up headspace. • Would you rather use it for the syntax, or for the concepts? -
@ArgesRic MASSIVE SYNTAX • Code is read more than it
is written. • We need to convey meaning quickly, without unnecessary ceremony… • Doesn’t matter if it’s a new programmer, or you six months after you wrote it. • And that’s before we discuss the baroque class architectures people build on top. -
@ArgesRic INCONSISTENCY • You need to experience it. • Clojure
thinks in terms of collections and encourages you to use maps. • Same functions act over everything. Even records are map-like. -
@ArgesRic NATURAL LANGUAGES • English: Trivial grammar, pronunciation is a
mess. • Spanish: straightforward, clean, pronunciation; grammar is more elaborate than English. • Romanian: … -
@ArgesRic CLOJURE GRAMMAR • Weight is on the verbs. •
Verb goes first. • Verb is followed by anything it acts upon. -
@ArgesRic CLOJURE GRAMMAR (+ 1 2 3 4) (map :val
[{:id 1 :val "a"} {:id 2 :val "b"} {:id 3 :val "something else”}]) (auth/create-auth-token (:username content) (:password content)) -
@ArgesRic CLOJURE GRAMMAR (+ 1 2 3 4) (map :val
[{:id 1 :val "a"} {:id 2 :val "b"} {:id 3 :val "something else”}]) (auth/create-auth-token (:username content) (:password content)) -
@ArgesRic MIND THE SEMANTICS, THOUGH • It’s not about learning
a new function now and then. • You have to use it to get acquainted with the semantics. • Need to learn how to express yourself differently. • It’s not about understanding the language, it’s about grokking its semantics. -
@ArgesRic MIND THE SEMANTICS, THOUGH grok: “to understand so thoroughly
that the observer becomes a part of the observed” — Robert Heinlein, Stranger in a Strange Land -
@ArgesRic IT’S ABOUT DOING You can’t just subscribe to a
running magazine, you have to get out there and run. 4Clojure.com is your friend. -
@ArgesRic LEARNING CURVE “I am to going to fetch the
value..” They’re trying to hang the mental constructs of their much more complex first language onto the simplicity of English grammar. -
@ArgesRic LEARNING CURVE The tricky thing about Clojure’s grammar is
that it’s much simpler than you expect. -
@ArgesRic LEARNING CURVE • Most of my time goes to
figuring out what I want to say. • In C# or Java, I spent a lot of time in scaffolding and ceremony before getting to that. • There’s no boilerplate. It’s just you and what you want to calculate. -
@ArgesRic THE CLOJURE WAY • Small, focused, easily replaceable libraries
• Templates over frameworks. See Luminus (http:// www.luminusweb.net/) • No automagic -
@ArgesRic NO AUTOMAGIC • No method injection… since we don’t
even have objects. • I used to love Grails’ approach… until I realized I couldn’t control it. • Full control over what’s going on. • Libraries are easy to replace, since you don’t have to wonder about what goes on behind the scenes. -
@ArgesRic REFACTORING - CLOJURE, REVISITED • Immutability helps with refactoring.
• Code is trivial to manipulate, since… • … it’s a tree structure • … you don’t need to worry about context. -
@ArgesRic REFACTORING - CLOJURE, REVISITED • Yes, code is read
more than it is written… • … but writing is rewriting. • We will not get it perfect the first time. -
@ArgesRic REPL - CLOJURE, WHILE EXPLORING • Trivial use of
your functions as you develop. • Excellent for exploring someone else’s functions (remember, no context!) • I’ve found myself experimenting with my new functions on the REPL, then codifying those as tests. -
@ArgesRic CLOJURESCRIPT - CLOJURE, ON THE BROWSER • Gets
transpiled to Javascript. • All of Clojure’s advantages, on the browser. • Straightforward and consistent. • Both front and backend on the same code. • Enables some amazing tools. -
@ArgesRic CLOJURESCRIPT COMPONENTS: REAGENT • React wrapper: https://reagent-project.github.io/ • Clean,
straightforward, excellent examples. -
@ArgesRic CLOJURESCRIPT, REACTIVE: RE-FRAME • Reactive pattern using Reagent •
https://github.com/Day8/re-frame • Tiny surface area affected when modifying front end code. -
@ArgesRic CLOJURESCRIPT, RELOADED: FIGWHEEL • Created by Bruce Hauman •
https://github.com/bhauman/lein-figwheel • Scans ClojureScript source folders, reloads the application live. • “Presses F5 for you, big whoop” • No data loss. -
@ArgesRic FINAL SUGGESTIONS • Start off small. Unlike going from
C# to Java, it’s not just about learning new vocabulary. • There will be a learning curve. • Don’t get too used to blindly hack off templates at first just because you want to start big. • 5 mistakes Clojure newbies make: http://adambard.com/blog/five-mistakes- clojure-newbies-make/