Programming Throwdown - Clojure with Eric Normand
Episode Date: December 22, 2016On this show we discuss Clojure and ClojureScript, and all the amazing things you can build with them. Show notes: http://www.programmingthrowdown.com/2016/12/episode-61-clojure-with-eric-nor...mand.html ★ Support this podcast on Patreon ★
Transcript
Discussion (0)
programming throwdown episode 61 closure with special guest eric norman take it away jason
hey everyone um if you're a longtime listener,
you may remember we did an episode on Lisp almost three years ago, and we're coming back,
and we're covering it in a lot of detail. One of the things, one of the comments that we got,
and we did the Lisp episode from a lot of people was, hey, we want to learn more about Lisp,
and here's some more details about Lisp and things like that.
This is before we really had a strong social network presence,
where the only way you could really communicate was by emailing us.
And so we got a lot of email about Lisp.
And so we're really happy.
Oh, go ahead, Patrick.
Yeah, we also briefly did mention Clojure.
We did like a collective episode of a bunch of JVM languages. That's right. And so we mentioned Clojure on, we did like a collective episode of a bunch of JVM languages.
That's right. And so we mentioned Clojure by name there. And so we have Eric Normand to talk
in much more detail about Clojure and kind of really teach all of us a lot of really cool
things about Clojure. So Eric, kind of tell us about yourself and what do you do? Hi, my name is Eric Normand.
My current tagline is I help people thrive with functional programming.
Nice.
I run a site called purelyfunctional.tv where I teach people Clojure.
I want to expand it to other functional programming languages. And I basically
teach with video and exercises and other online things.
Cool. What sort of inspired you to build that site and to teach people Clojure and other
functional languages?
Well, it's evolved over time. I have always liked teaching well always i i was a teacher
in the peace corps and i was teaching math and when i got back i i kind of started missing it
i started programming again and uh i started making uh videos and off and on. And then at some point I did a Kickstarter to get some
closure videos made. And that was a success. And just ever since then, I've been adding more and
more videos. Cool. Very cool. What is it like running a Kickstarter? I've never actually,
I've funded several Kickstarters. I've never Kickstarted anything I mean how do you what was that process like uh so it was not I mean it wasn't that big of a deal um
I think the biggest thing was beforehand I talked to my friend who has funded a lot and like
kind of saw what worked and what didn't i i hadn't been active on kickstarter
at all and so it was like just a lot of discussions with him about like how what should i set my goal
at uh what should my rewards be uh you know that kind of thing and he helped me come up with the
uh the structure there um yeah i i would say that my biggest advice for someone
who's going to do a kickstarter is take into account the marketing that you're going to do
during the campaign so i did mine for 30 days which at that time was the default i don't know
what the default is now but at that time it was default to 30 days.
And so that's 30 days of you like tweeting and promoting
and like just being generally like on edge about whether you're going to make it and stuff.
And if I were to do it again, I would probably cut it down to like 10 days or 15 days.
Because most of the backers came in at either the beginning or the
end. And so if you just cut out the middle, then I would have had about the same amount. So
that makes sense. And one thing that I noticed is it's really, you know, you have to, the audience
wants to have faith in, in you, like in you delivering on the kickstarter and so if you're if you're messaging
every single day like you know here's what i ate for breakfast today i ate closure flavored cheerios
then like people know okay this person means business and and if i if i donate that it's
one it's going to work out and two like i'm donating to more than just a set of videos it's like a
cause yeah for sure it really helps to have an audience before you start um i think that's the
number one failure reason is is people don't have anybody that who can listen who know, you know, they're shouting into the void. Yeah, that makes sense.
So, you know, kind of explain, you know,
if you had to sort of explain functional programming to someone who's never heard it before,
how do you, you know, how do you sort of describe that?
Let's say there's someone who, you know, has taken some courses,
they get C, you know, C++ really well,
but they've never seen Lisp or Haskell or Clojure or any of these.
How would you sort of explain that to them?
Yeah, so that's a really hard and complicated question because I don't think there is a very agreed-upon definition of functional programming.
But functional programming, for sure, comes from lambda calculus.
And lambda calculus is a mathematics that uses nothing but functions.
And so there's definitely the notion of using functions as your main form of abstraction
and functions are higher order that means that they can be passed to other functions as arguments
and you can return functions from arguments so functions are values that you can pass around. And languages like C, C++, you can kind of, like let's take C because I know that a bit better.
You know, you can pass function pointers around and stuff and people do interesting stuff with that.
But they don't have what's called lexical closures.
It's a technical term.
It just means a function that can refer to variables
that are defined where the function is defined.
So like in JavaScript, if I have a variable defined,
let's say variable A equals one,
and then I have a function defined right after that,
then I can refer to A in the body of the function you can't do that in c so it becomes like you can't so you can't like capture the
environment that it was in so you can't really do the functional stuff yep that makes sense so i mean i think one analogy is if you've ever played
world of warcraft um or any of these you know mmos or many games kind of like it you know some of the
weapons you know in the beginning you get the wooden sword and like you just hit the rat over
and over again but then as you get better and better you get one of these swords that has what's called a proc, which is short for a procedure.
So it might be, you know, when you hit somebody, there's a 10% chance of them turning into a chicken or something, right?
And so, you know, that process, like that event is sort of tied to that sword. Like you kind of want to assign the turning into a chicken
to that weapon and be able to,
if you give the weapon to someone else,
you want to sort of give that logic to them too, right?
And so I think, yeah, part of functional programming
is this idea that like you can pass these functions around
as sort of first-class citizens.
Yeah, wow, that's a really great metaphor there.
Yeah, I played too much World of Warcraft. Another way to look at it that I've heard about
is... so you have... if you're familiar with object- programming you've got objects that have methods so that's data with functions attached well in in a closure in a in a lexical closure
like in a functional language you have functions with data attached so those that the the variables that are defined in the scope are the data that you can access from that function.
Yeah, that makes sense. So that i mean you know when we covered closure
we just very superficially said closure is lisp on the jvm but you know i'm sure it's
it's much more than just that um you know kind of how does closure fit into this whole landscape
oh uh good question well closure is a lisp for the jM. And Lisp is cool because it's like a family. It's got dialects. And so Clojure is a dialect of Lisp that is made to be hosted on a virtual machine. And JVM is like the first virtual machine that it's hosted on.
Oh, I see.
Is there something you can't do in Clojure because of that?
I mean, because it's a dialect of Lisp,
is there some things that aren't there or are there that aren't in regular Lisp?
That's a good question.
I mean, it's a different language than say common lisp so
there's a lot of stuff that uh comes with common lisp um that is built into the language whereas
enclosure because it's designed to be hosted uh it just relies on on what the host can do. So I'll give an example.
Common Lisp has this very sophisticated and just a lot of features in the exception mechanism.
So when you throw an exception, you can actually do what's called a restart.
So you catch this exception and you can fix the problem and then recall it and go
right back to where the exception was thrown so if like the file is not found you can be like oh
not found well let me make it and then you go right back into where it was right oh cool um
whereas in java and it's just built into the jvm it's not part of the java language it's it's just built into the JVM. It's not part of the Java language. It's part of the virtual machine.
The exception gets thrown
and like the call stack gets unwound
and it's lost.
Like you can't go back to where you were.
And so Clojure just kind of borrows
all of that stuff from the host that it's on.
So that includes like Clojure's numbers
are just Java numbers.
Clojure's strings are just Java strings.
Functions in Clojure get compiled into a Java class.
So, you know, all this stuff just becomes
some concept on the JVM.
Gotcha. That makes sense.
So, I mean, how are some of these things, like, possible?
Like, in Java, you can't have closures, right?
So, I mean, I'm assuming Clojure can't be built in Java.
It has to, like, in other words, like the concept of Clojures have to be added in machine code, I guess, to the JVM or something?
Well, actually, it's really interesting how it's implemented.
So what most of the language is written in java um most of the data structures
uh most of like the logic and the compiler it's all in java um the way closures are implemented
is like i said it's a there's a class and when you have a new function
that you're compiling, it extends that class
that function class. Oh, I see. And the
function class has a bunch of methods on it.
And each method is a different signature. So it'll have the zero
argument method, it'll have the zero argument method,
it'll have the one argument method,
the two argument method, et cetera.
And the class that it compiles to will extend those.
Gotcha.
And then all of the data in the closure,
meaning the variables in scope that it needs to access, get put
into the class as member variables.
Okay, that makes sense.
Yeah, that's very clever.
It's clever and it's a way to use the function or the method calls semantics of the JVM
without having to invent some other mechanism.
Right. That makes sense.
So for somebody who's maybe really into web development
or done a lot of maybe C++ kind of backend work, C++, Java,
like why should they learn Clojure? You know, for someone who's already mastered, you know,
one or two or several languages, like what, you know, you know, we always talk about this metaphor
of the toolbox and how there's not one sort of magic language. It's just the same as there's
not one magic wrench that just does everything or not one sort of magic language. It's just the same as there's not one magic wrench
that just does everything or not one magic tool that just does everything. That's a wrench and a
hammer and a, you know, whatever. And so, you know, if someone wants to, you know, assemble
this sort of toolbox of languages, that's sort of comprehensive, you know, what sort of disclosure add to to that toolbox that is a really great question
and it's something that i don't think is is really fully answered i can tell you like there's no
general like one answer to to to satisfy that question i'll tell you why I like it
and also why people I know like it too.
So when it first came out,
the big story behind Clojure
was that it handled concurrency really well.
So the JVM has a lot of java the language has a lot of
libraries and stuff for handling concurrency and there's books written about how to do concurrency
right on the jvm yeah it's very problem is yeah it's hard like you have to read this book and
then do everything right or you're going to get bugs.
And what Rich Hickey, the creator of Clojure, did is he took that book and basically built the language around that.
So it works that way.
It's very hard to not do it that way.
So a lot of the primitives in the language,
like, you know, there's all sorts of stuff in Java,
like you use the volatile keyword
and you have to, you make stuff immutable
and things like that.
Like all of that is just taken care of for you.
So it has this really nice story of like concurrency
is the default and it works really easily right out of the box um and and that is true and it's
really nice and it's weird when i go to another language and i'm like well how do i do this at
the same time and like oh well you you can't or you have to do this other completely um like
boilerplate system to get something else to run at the same time yeah um yeah that's a huge huge
problem i mean you know what typically happens you're building especially if you're building an
app for the desktop um you have some kind of ui and you use the person specify some files and then you want to go off
and do a bunch of work on those files and it's almost always embarrassingly parallel like very
rarely do you need to do like just one like very sequential one thing at a time usually someone
gives you kind of a batch of things to do and in most languages like c++ and java
this can get kind of quite painful yeah yeah it gets painful because like all the all the pieces
are there right like you know well in java to make a thread you just do new thread and you have a
thread and like what's the problem well that's only half the answer the other half is now that
you've got this thread how do you get information that it's calculating out back into the thread
where you're going to display it on the ui right yeah and and it's it's all these like ancillary
problems like oh i maybe i need a q okay well you know you're going to construct the thread and the queue and a thing and like
you just it just never ends right yeah whereas in in closure it's it's as simple as well i'll just
have there's a bunch of different primitives uh one of them's called an atom and an atom is like
the simplest kind of shared state it's just one pointer that that you can change and uh you you can have
multiple threads accessing this pointer you can read from it or you can write to it and it's uh
thread safe and um i mean this goes into like why one of the reasons I really like it is the focus of closure is on the simplicity of separating out all the different problems and solving them independently so that you can compose them back together. is keeps one pointer and make sure that whenever you transition from one state to the next,
you're transitioning from a consistent state to another consistent state, like in a transaction.
Gotcha.
You can't see it halfway done.
And that is what allows multiple threads to read and write to it. I mean, really
with very little code, you don't have to deal with locks and stuff like that. It's all handled
by the Atom. And this simplicity of sort of, here's the right tool for the job and the language just kind of gets out of your way.
I really appreciate that.
Yeah, it makes sense.
I mean, most of the time you don't need to do these hog wild things
where you have three different threads all updating the UI at the same time.
I mean, these things were important in the 90s,
but now it's like uh if if you have
three threads and each one locks the ui updates it and unlocks it computers are fast enough where
we don't need that level of control and if you if you uh are willing to sacrifice the
level of control you could have a much cleaner language yeah yeah for sure um so so most people
want to build i mean there's people like patrick who do crazy robotic stuff homebrew stuff he's got
you know a drone firing lasers at people who come to his house but but for the rest of us like the
other 99 of us we're either building you know a website a desktop app which could include like
a server that's serving web pages um or or a mobile app like an iphone app or an android app
so can you do you know these three things like any or all of these things in closure how does that kind of work? Yes, yes, for sure.
So the easiest one is the web app.
Web apps have been done in Java for a long time.
There's a thing in Java called servlets, servlet interface and most of the closure web systems are some wrapper that uses that uses the servlet api um there's the actually the closure ecosystem web ecosystem is evolving
right now but for a long time the the main system was called ring
and it was kind of like rack in uh in ruby and all it would do is it would take the request
and turn it into a map and it had a standard format you know the the request method was under a certain key
and it was a string and then the um like the port was a different string was a different key
and it was a number and the body was you know so you could get this map and then you did whatever you want with it and then you would return a uh in in a you would
return a response there's another map in a similar format and then there was a there's three concepts
there's the adapter which is the thing that connects to the servlet api whatever API you're using to do the web stuff.
So that adapter connects to the API and converts requests into the ring request
and then converts the ring response back into an HTTP response.
And then you have your handlers, which are functions from request to response,
and then what's called middleware,
which transform the request or the response as it passes through.
So it actually transforms the handler into a new handler.
Yep, that makes sense.
So you would basically construct your web app out of these these pieces um and like i said it's evolving like people are learning stuff they want to do asynchronous stuff functions
aren't great for doing like async calls um but uh that's that's that's still the main idea is that you got this request map and a response map.
Yeah, that makes sense.
So basically, all of the ideas, if you're used to doing Java, you know, server-side web development,
all of those ideas kind of translate almost one-to-one to Clojure.
And someone has written adapters so you can kind of work in a completely closure environment
and not have to worry about all of those bridges.
That's right.
And to me, it feels much cleaner.
And how do I put this?
It's much more direct.
So in the Servlet API, you get this request object that you, like, query, like, well, what, you know, you call the method, like, get method, right?
Yeah.
Which gives you the HTTP method and stuff like that.
And so you really have to understand this API really well and, and like look up the docs and then when you do the response you
have to like do set header and and you're not supposed to call set header after you've like
piped in the body you know and like there's all sorts of of like rules for how to use these things. And to me, that's really hard to keep track of.
Yeah, totally.
And so in Ring, the adapter is supposed to handle that.
So you handle that one time, right?
The adapter, once it's well-written
and conforms to the API and to the Ring spec,
it's done.
It's like you can just close that book and say, well, version whatever uh it's done you know you know it's it's like you can just close that book and say well version whatever it's done and um that's the kind of thing i really appreciate
with the closure community there's actually libraries that they're like it's done we finished
um it's it's not like this continuing thing, like, Oh, well, we're trying to adapt it to
this other situation.
So you don't have this problem and we solved it.
Yeah.
What about like mobile?
If you're building a iPhone app or Android app, can you do that in, in closure?
Uh, so there's a couple of options.
Um, I don't think that this is being done so much anymore,
but because the Clojure runs on the JVM,
it can run on the Android JVM, the Dalvik JVM.
Okay.
But I think most of the work now is in React native um there was some stuff with phone gap so
we didn't talk about this but closure also compiles to javascript and i talked about it
being hosted on the jvm well another host that closure can run on is JavaScript. When it's compiled
to JavaScript, it's called ClojureScript.
It's basically
the same language.
I mean, it's whatever you want. It's
JavaScript, so you can run it on
any of the JavaScript VMs.
That is super cool.
You can run it on Node.
You can run it,
serve it through a web app
and use it, whatever browser they've got, run it.
You can do React Native.
You can do Electron.
I mentioned PhoneGap.
People have been doing that for a while.
That is quite remarkable.
So if you, you know, I mean, JavaScript is very universal.
For sure.
But if you just, let's say you just hate JavaScript, or you're programming something in a certain
paradigm where a functional language would be much better, or at least, you know, Clojure
would be much better, then you can actually write Clojure and it will compile or transpile down to JavaScript.
That's pretty cool.
That's right. That's right.
And you said the word transpile, and that's what it's doing.
But a lot of times when people think transpile, they think CoffeeScript.
And I have nothing against coffee script but one of coffee scripts like goals was to be just javascript but with better syntax
right it's like right you could you could kind of guess what what javascript would be generated
yeah i think they even have a it's's two-way. You can actually...
You can convert it back?
Oh, I didn't know that.
Or maybe it's, oh, no, sorry, sorry.
It's not two-way, but there's a, what's the word?
Like there's a JavaScript compiler for CoffeeScript.
And so there's actually, on the CoffeeScript website,
you can paste CoffeeScript,
and it will turn it into JavaScript.
It's just right there on the website.
And that's what
i use coffee script for for for taking other people's coffee script and converting it i see
i see i see um yeah and so that's a really you know that's that's a a valuable thing to do
is to like make the the syntax better because javascript can get pretty verbose but closure script is different it
is it really feels like a different language oh i see and and by that token when you transpile it
you get javascript that's kind of unintelligible because it's it's meant to be it's almost like
looking at assembly or something right exactly so it doesn So it doesn't do like asm.js.
Functions compile into, you know,
closure functions compile into JavaScript functions.
A lot of the, like, you know, if statements and stuff,
like you could read them.
What gets hairy is that it does a lot, the compiler does some optimizations.
So, you know, what looks like a regular function call is actually going to turn into, in JavaScript,
a dot call. You know, functions in JavaScript actually have methods, and one of them is.call.
And so when you're looking at the compiled code, it's like a little crazy because it doesn't look like you would write JavaScript at all.
Yeah, that makes sense.
But that's okay because the source mapping is all in there.
So when you look at it in your Chrome dev tools,
you're looking at the
ClojureScript code and you're getting line numbers from your ClojureScript code through the whole
stack. Oh, nice. Yeah. So source mapping, and maybe actually it'd be amazing if you could
explain it because I have no idea how it works, but basically I've used it for TypeScript.
And what it does under the hood, I don't know, hopefully, maybe Eric can
educate all of us. But on the surface, you've written in TypeScript, but the person in the
browser is still executing JavaScript, the person could be you. And when you get an error, you don't
want it to just show you this complete unintelligible JavaScript, you want the error to actually redirect back to your code
that you can actually modify.
And the source map helps make that happen.
Yeah, for sure. That's a great explanation.
It's like if you're going to serve up some JavaScript,
usually you're going to minify it and maybe uglify it.
And so it's going to be like one long line of javascript
and that's going to be impossible to debug it it's going to say line one like bugs on line one
exactly exactly so they came up with this system the browser makers came up with this system where you have this other file that's included along with it that gives you the ranges of code in that original file and the line that they correspond to in the original file, in the code that you wrote gotcha um and that works
for javascript and css i think and because you know people minify that too yeah and so um it it
it's really nice now because they've got it where you can put break points you know you can debug it
and step through line by line like what what you think of
as a line because it's the code you wrote like you can put a breakpoint there and and walk through
line by line even though it is compiled into some crazy javascript that you can't read oh man that's
awesome yeah yeah i never actually knew you could do that that. I always had unminified code when I was debugging,
but yeah, I never needed to do that.
That's cool.
Yeah, and that's actually largely thanks to one system
that the ClojureScript compiler uses.
It's called the Google Clojure compiler,
and that's Clojure with an S, Google Clojure.
Right.
So the ClosureScript Compiler is a very simple kind of naive compiler, but it outputs code that the Google Closure Compiler can read.
The Google Closure Compiler what gmail is built in and um it does some really aggressive
optimizations there's different modes but like when you're gonna release your code like it does
all this crazy optimizations on it uh like totally analyzing code paths and like eliminating
functions you don't call and things like that yeah Yeah, just to sort of explain, because it's super confusing.
So there's a Google Clojure compiler.
Yeah, the naming is really terrible.
Yeah, it's spelled with an S,
and it has nothing to do with Clojure, at least directly.
All it does is it takes JavaScript code
and it makes it faster and more efficient.
Just like you could have a,
think of it as like an optimizer, right?
You could have, you could compile your code
with dash O, dash O zero, which no optimizations,
or you can compile your code with dash O three.
And it produces, even though it's the same code, same logic, it produces a totally different
binary.
And that binary has all sorts of crazy, you know, GCC optimizations, you know, baked into
it.
And so Clojure is kind of like compiling with dash 0 3, but it's in JavaScript.
And so it, JavaScript goes in, JavaScript goes out,
but the JavaScript that comes out is, is, is much more, a much more efficient representation
of what you originally intended. Um, and, uh, that's different than closure with a J,
which is what we're talking about, but, but you can actually use Clojure script with Clojure to produce, you know, to write in Clojure and produce really fast JavaScript.
That's right. That's right. And I mean, it is some really cool technology. It's from Google um what's called splitting module splitting which means like
okay so imagine you've got you're developing this web app and like your front page it's going to
have some javascript on it but you don't have to be logged in to do it and most people who go to
that front page aren't going to log in then there's all the
people who log in and they're going to have this like rich web app experience so a ton of javascript
and the thing is you don't want to serve that big javascript to just the people who just go to the front page so the idea behind splitting is that the compiler can
analyze your code and figure out well the front page uses you know this bit of code
the back end uses this bit of code and then this bit of code is shared between the two so you can cache that
one that's shared between the two and only serve the the you know the the home page code and that
shared code to the people who are visiting the front of your site and then then after they log in they can get the rest of the code
so it's it's a way to like optimize the experience for you know people who don't need that part of
the code cool yeah that makes sense i mean one thing one thing that people might not realize
there's an incredible amount of energy spent on making, especially the front page of any site load very quickly.
There's statistics that show for every, you know, maybe 10 milliseconds.
And of course it depends on different products and different sites,
but you know, for every 10 milliseconds that the front page takes to load,
you lose, you know, X percent of your customers.
And it's like pretty significant.
So, yeah, so if Clojure can kind of separate that and speed that up, it's awesome.
Yeah, yeah. And that's exactly the reason that people want to do it. It's just that speed of
first load, but still provide some JavaScript. And then not having to, like, you know,
the recommendations are to do all of that manually.
Like, keep two files of JavaScript and, you know,
keep that manually.
That's crazy.
Yeah, that's way too much work.
Yeah, it's too much work.
And so we've been talking about all this cool stuff we can do the thing is the development
experience in in my opinion is better than the javascript development experience so it's not like
it's you know oh you get this great language but then you've you've lost something because you have to have all this tooling and stuff.
I recently, so okay, let me give a little history.
About four years ago, I was doing a lot of front-end development,
back-end and front-end, but specifically I was working on a JavaScript app.
And four years ago, the space wasn't so developed i don't think angular was even out yet
backbone was new like it was all all all this stuff and uh i mean we were using cat the unix
command to put different javascript files together like that's there was no bower and grunt i don't even know what they are
yeah and um so it was very simple times and it worked you know it worked um and then i went into
closure script and i was doing the way you do it in closure script and closure script was really
new so a lot of it was like. But it was evolving very quickly.
And then I had to go back to JavaScript for another job,
and I was just shocked.
I mean, the number of tools you need and libraries and like,
oh, you're still using Grunt?
You should be using Yank or whatever it's called yarn npm like npm didn't
exist when i left javascript before and it's like i i just it is just so crazy how many libraries
and tools you need to develop nowadays in javascript and, and it sounds like the Clojure script
is easier to work with than mscripten.
So if you've ever used that, it's a total nightmare.
I don't even know what that is.
Oh, mscripten is this thing where it takes C++ code
and turns it into JavaScript.
It actually goes through LLVM
and then goes LLVM to JavaScript
and Zynga used it
for all of their games
so the idea is
if you play Zynga Poker on your phone
that's almost all C++ code
there's just a little bit of iOS or Android code to handle the drawing
and things like that.
If you play Zynga poker on, say, like, Facebook.com
or, I don't know, even Zynga.com,
like, but on the web version,
that's also C++ code, the same code,
but it's been, you know,
translated to JavaScript with Emscripten.
And talking to people who've worked at Zynga, it's just a total nightmare.
I mean, if you have a bug in the C++ part, you just have to catch it on mobile.
Like if there's some bug where if someone gets all four aces, it crashes or something,
you just won't catch it on the web.
Like it's lost. You just have to catch it on the web like it's it's lost
you just have to hope you have that same bug on mobile well i mean i'll tell you like i don't i
don't mean to bash on all these languages i love languages they're great but i i recently had to
work in c++ um and i don't know c++ so it's totally new to me so i was already dealing with all of the like
the novelty of everything but the build system i mean we were just taking like it took me over
a week to get it to build on my machine and i could imagine if then okay you finally got it
to build and now it's running in in the browser and you don't have
any way of no like you know source maps or you know something like that to debug it oh man yeah
i mean it's a total nightmare um yeah but you're you're totally right like i mean now things are a
little bit better there's basil um and there's buck's buck, uh, basil's from Google. Buck is from Facebook. They're
basically the same thing. Um, but, but even then it's, they're, they're not great. I mean,
well, even dependency management in C plus plus is still really bad. Oh yeah. It's a total
nightmare. If you want to pull, like, there's really no repository, not that I know of.
There's not really a central repository of C++.
You know, I don't even know how that would work
because you'd have to, you wouldn't be able to keep the binary
because it's machine specific, you know.
Right. Oh, yeah.
I mean, I don't even know where to begin with that.
I don't, I'm not in that world and I'm glad I'm not.
But yeah, it sounds like ClojureScript is better than that,
is more mature than that.
Oh, yeah, yeah.
And, I mean, the thing about JavaScript is it's a huge ecosystem.
There's so many people in it.
People are dissatisfied with their tools, and they write new tools.
But there's so much to keep up with every six months you have
to like rewrite your build system because you know it's not using the newest thing and you need a
feature from the newest one or um i mean that's why like in my personal my personal website, I use cat. I have a make file and I cat JavaScript together.
And JavaScript is kind of like that.
You can do that, right?
You can just take two bits of JavaScript
and smush them together
and you have a bigger bit of JavaScript.
Yeah.
And that's, I just don't, I guess I'm getting older.
I just don't want to deal with these cycles of learning a tool
and figuring out its JSON config format.
Yeah, absolutely.
I mean, when I was in high school, or I guess maybe college.
Yeah, when I was in college, I got Ubuntu,
not Ubuntu, I got Gentoo.
And for people who don't know,
it takes about 18 hours to install,
or at least at that time,
it took about 18 hours to install Gentoo.
Now, you don't have to be there for 18 hours,
but it's kind of like you get in,
you install the bootloader,
you spend about an hour entering all these different commands
to install the bootloader.
And at the time, that was super cool
because you feel like Neo from The Matrix,
like some crazy hacker.
Yeah, and Windows took a long time to install too.
Yeah, but in terms of effort,
I mean, Windows definitely took a while to write to disk and all of that.
But this was like you have your bootloader.
You'd reboot to the command line, like to just a root prompt.
And sometimes you'd do it wrong and you'd reboot and nothing would happen.
And that was super, super fun at the time.
But as soon as you become a
professional and someone says when is this going to be done and you say a week and then instead of
taking 18 hours it takes 30 hours to install your os you're kind of in big trouble like yeah it is
not fun anymore you know and so yeah you immediately switch to, okay, I need something reliable, you know, that's quick that I could depend on.
Yeah, sure.
I mean, I remember I used to be like in the 90s sure that X windows would work with it and get all the settings right.
There was no auto detect at that time.
And then at some point, I would just be like, okay, enough.
I need to check my email.
I would just use the barest X there was yeah barest x windows the one
where you like you you boot into x windows and you have to like right click to get a menu yeah
it's just like that or you just get a terminal that horrible grid of like black and white dots
and your cursor is an x exactly exactly and you just have a terminal and i would just type netscape
a web browser uh so nice yeah good old days so so let's say someone you know has a website already
in javascript and uh it's using you know a bunch of different libraries it's using you know random
and using all sorts of different libraries um
you know they they rewriting it is totally off the books but now they need to do something which
closure is really good at how does that work like is there some type of interoperability layer
yeah so because closure and closure scripts were designed to be hosted the interop is just really
seamless uh you can call first of all any function you can just call it like like a javascript
function you get a javascript function from something you just call it if you get an object
like let's say you get a promise, you can just call methods on it
just like normal JavaScript.
And you can access the properties too.
So the hardest part with interop
is that you're not dealing with JavaScript arrays anymore.
You're going to be dealing with
Clojure's immutable data structures.
Gotcha. So you're going to be dealing with closures, immutable data structures. Gotcha.
So you're going to, if you are doing a lot of interop
where you're like building up a closure vector of data
and then you need to pass it to something that's expecting an array,
you're going to have to convert it.
And so there's going to be a little performance penalty there
every time you convert it.
That makes sense, but most people use objects.
There are cases where you need arrays,
but that's more rare, I would think.
Well, it's the same with objects.
If you're using a plain JavaScript object,
just like open curly braces,
you're going to need to convert from...
So Clojure would, in that case,
Clojure would use a hash map,
a Clojure hash map.
So you would need to convert it to a JavaScript object.
Okay, that makes sense.
Which basically requires walking down the hash map
and converting everything into something that
javascript would would use yeah that makes sense cool um so what about i mean you know we have sort
of a faction of the audience um a faction is is faction like a i feel like faction is a connotatively positive word but now
i'm starting to doubt myself we have a portion yeah we have we have a portion we have a section
of the audience that's just really into the career side you know it's it's people who want
to get into the industry um and and so they're you know right now they're really wondering
what's the job market
or even if they're doing freelance
they want to do freelance work, they're wondering
how would this affect my freelance work
does this give me some
if I'm given the freedom to use any language
does this boost my productivity?
And so what is sort of the, you know, on the business end of it, how rich is sort of Clojure right now?
That is a really good question.
So I'm going to take it in parts.
There's a lot of Clo of closure jobs out there right
now i mean it's not it's not javascript right because you know basically every company has
javascript right um and so if they're going to dictate what language you're going to use there's
there's much fewer companies that are asking for closure script um but they're out there they're definitely out
there and they're looking for people um i i do have to say a couple of things because it's a
smaller um smaller group it is easier to to get into um and it is i believe
um how do i put this if if you have the javascript normal curve of like quality of developer
and you have the closure script normal curve of quality of developer obviously the closure
script normal curve is like a smaller like tiny little
thing next to the javascript curve but the average is higher yeah because closure and closure script
are probably not their first language whereas in javascript it's it's more much more likely that
javascript is their first language so even if you just think someone with two languages is better than one,
you've got that going for the Clojure and ClojureScript side.
That makes sense.
I think there's a lot to be said for joining a smaller community,
especially when you're just learning.
I mean, there's a lot of resources. There's people
who are very passionate about it. And you're not just completely swamped. I mean, if you were to
learn JavaScript as your first language and learn it in sort of a professional sense, you're just
completely swamped with, as Eric mentioned, just all the different tools, all the different libraries. And it sounds like ClojureScript, you know, with a smaller community,
you can really kind of dive deep and get a good understanding.
Yeah, for sure.
And it is a, I mean, everyone, or not everyone,
many of us have heard this story that JavaScript was actually designed in 10 days, which is kind of an exaggeration, but it's not far from the truth.
Whereas Clojure and ClojureScript have a much richer history and a lot of design work went into it.
So it's palpable when you're programming in it
that things were thought out much more than in JavaScript.
Yeah, and I think things are starting to trend
in the direction of more fully featured languages.
I mean, if you look at Haskell and Scala, for example,
they have type inferencing,
and the browsers now are more sophisticated,
so you can see the inferred type.
And so a combination of the browser and the tooling
getting more sophisticated,
and also the projects just becoming more complex,
it sort of dictates languages that are more principled.
And so that's one of the reasons why there's just so many alternatives
to JavaScript, like so many different ways you can write JavaScript
because people just can't get by with native javascript when the
project gets very large and complicated um and so yeah i think i think closure script would be a
great first thing for people to learn yeah i mean i just did a workshop and we did closure script
um it's and a lot of them were first-time programmers. And it went well.
The number of things we had to install,
I think we had to install two programs on their computer.
We had to get the JVM on there
because the Clojure script compiler does run on the JVM.
It's written in Clojure.
And then we had to get L lining in which is the closure project
management tool and with those two things like you're done like that even the editor
this is really crazy but there's an editor called nightlight that is just a plugin for lining in so it runs like you just type line nightlight
and you get an editor that you know you open your browser and to a certain url and you've got an
editor editing the code in that project oh nice, nice. And you've got live reloading with another plugin.
So you're typing and you can see the change in your browser.
You can see the effect of that.
And so it's just an amazing experience
that someone can type a couple commands at the terminal
and get this development experience going.
Yeah, very cool.
Yeah.
Now, you mentioned freelancing.
So that one, I think, is probably where you're going to see
the most bang for your buck.
Like, if you really can choose whatever language you want um which i think is the case in a lot of freelance situations i mean it is such a it's so much better
than than javascript in in my experience like if i was going to do freelance i would do closure
and closure script no doubt um you can definitely do some pretty sick arbitrage.
I mean, if there's a project where ClojureScript
would make this so much more efficient,
but the person expects you to be writing this in JavaScript,
you could actually do it twice as fast.
Yeah, exactly. And I, I'm kind of,
I've been waiting for a little bit, like a couple years now, but with React, so we've heard that
React is functional, right? Well, when you have a functional language and a functional framework,
it just works so well together.
The React wrappers in ClojureScript,
there's actually several that are popular,
but the React wrappers make it so nice.
Like a component is just a single function.
And I mean, you can do all the lifecycle stuff if you want,
but mostly you don't need it.
And you keep your state in an atom.
And it's just so clear how your UI is changing based on the state and adding stuff to the state, removing stuff from the state,
changing the UI.
Anyway, it is such a nice development experience
that I've been expecting someone to, like, sweep a hackathon, you know,
just, like, do something amazing in 48 hours
that no one else would believe was even possible
because they were using
closure script.
I've been waiting for it to happen,
but I haven't seen it yet.
So only a matter of time.
Yeah.
Yeah.
Maybe,
maybe because like,
like the closure script.
So I,
I,
I don't think I've done it enough justice.
So not only is the development experience great
where you have live reloading,
and when I say live reloading,
it doesn't mean it just refreshes the browser automatically.
What it means is your state, your app state,
is still there,
but the UI, like you've changed your UI code.
And so you could be like a few clicks in, you know,
like you're testing out your app.
Yeah, you have an email app and the email is half written.
Right.
And then you're like, ooh, that component doesn't really look right
or let me add bold to this toolbar, you know, whatever.
And you just add the code to add bold to the toolbar and boom, the component just changes
and the email text is still in there. That's awesome. Yeah, when we explained functional
languages three years ago now,
you know, we told people, a lot of people say, oh, I've never done functional programming.
And what we've told people is actually, yes, you have, and probably your parents have too. It's called Excel, right? And you know, when you're using Excel, and you type a formula, and then you
paste some data, and just kind of magically, you know, and as you're using Excel and you type a formula and then you, you paste some data and just kind of magically, you know,
and as you're changing the formula, the spreadsheet is just changing.
And if it feels so kind of alive and magical, I mean,
it sounds like with, you know, a closure script,
you get that same feeling, but with web development.
Yeah, for sure. For sure.
And you go back to where you have to reload and then like click through a few
things to open the thing back up that you were looking at to make sure that you did it right.
And then, oh, I didn't do it right or I want to change the styling a little bit more and you have to change the code and then reload.
And like I have no patience for that anymore.
I've been spoiled so so if someone wants to learn
closure what's sort of the best you know way that they can get started
oh good question uh there's a lot of books um but i'm actually going to take this as a
as a cue to plug my stuff um so i've got uh purely functional.tv there's um oh wow
150 something videos on there oh wow of varying lengths um and most of them are like behind a
paywall but there are some things that are um that are available for free
if you want to just test them out and see if you like it um there's one called intro to closure
and that's not closure script it's it's regular closure but it's the same syntax, same data structures, same core library.
So it'll help you on your way.
And also, I've got a page set up, purelyfunctional.tv slash throwdown.
And I'll give you a nice coupon code for a discount on a subscription.
Oh, very cool.
So yeah, just to recap, if you go to um what was the first part purely functional.tv purely functional.tv slash throwdown i'm assuming all
one word no hyphens or anything right yep so so uh purely functional.tv slash throwdown if you go to
that url um you actually get a discount for discount for some of the premium content on the site.
Yeah, yeah.
And, you know, get in touch with me.
My email is eric at listcast.com.
I love answering email about Clojure.
Any questions you have, that would be great too.
Cool.
Awesome.
Yeah, I mean, I'm definitely going to check this out.
This is super cool.
I had no idea, actually,
that Clojure could be used with React and React Native.
I've struggled trying to learn React and React Native.
I mean, I did learn them eventually,
but it was not intuitive.
And so I'm going to give
this a shot and see if it feels more natural. It's weird. I feel as if there are some things like,
trying to give a good example. I think actually JavaScript is one of them. Like JavaScript felt
natural to me insofar as when I was doing it, I was just inspired to keep doing it.
There are other things, like Scala is a good example,
where I write some Scala and I just want to write less Scala.
I had to do it for a job, so I kind of powered through it.
And I feel React Native is one of these things
where the more I did it, the less I wanted to do it.
And I'm going to try with Clojure,
I guess with Clojure Script,
and see if it feels more natural.
Well, I actually had the same experience.
I was using JavaScript in React Native for a client,
and it was, I mean, there was just so much to learn that was the real thing it's like i want to get something done but
you know there's all this life cycle things and um a lot of the the tooling was was kind of weird
and then there was uh all the styling and the the new components that you had
to learn yeah um and then the the biggest thing of all which i don't think we ever solved i think
no one has solved this yet the routing which i don't like i don't do much mobile development
apparently routing is like really important and i just don't get it um yeah same but but uh you know it has to
do with like keeping track of the back button and stuff can slide in from the right and slide in
from the bottom and like you want it when you hit the back button like you want it to remember the to go to um anyway apparently that's a hard problem and um i then was like well i got my
i got my bearings in the react native and that and that was cool and so then i tried it with
closure script and it was just it was just so fun now i didn't make like a complicated app with a
lot of screens and stuff but it actually
felt like wow i can now make all those little apps that i thought should be easy to do you know
like i wanted to make a like a tip calculator or something yeah yeah exactly like i want to track
my i run so i want to track my runs and i I use RunKeeper, but it's overly complicated for what I need.
I just want something like I click a button and I start running.
And I did it, and it's so nice.
So I'm actually making a course about that app that I made.
I've given a talk about it.
It's a really simple app you can make,
and it shows off how nice that live reloading is.
You're tweaking the UI,
and it just magically changes in your little iOS simulator.
Very cool.
So, yeah, I think that kind of wraps it up.
So Merry Christmas, Happy Kwanzaa, Happy Hanukkah,
other things I might have missed, you know,
because this episode will probably go out, you know, around that time.
Have, you know, happy holidays and all that.
Thank you, everyone out there, for supporting the show.
Thank you, Eric, for coming on the show and explaining Clojure to us.
And we really appreciate your time.
Do you want to give a shout-out to the link over time so people can get that discount?
Yeah, purelyfunctional.tv slash throwdown.
Cool.
So there it is.
And yeah, and have fun.
Happy hacking.
Hopefully you have a cool Christmas project.
Like Patrick's probably going to build, you know, like, you know, as I said, some robot
that will, that will uh you know terrorize
his neighborhood i feel like you're just gonna make the feds show up at my door yeah um i don't
really have anything in mind but uh oh actually i do plan on doing a lot of uh drawing um i wrote a
script for um for a game but this is like a role-playing,
like one of these RPG games
where it's a lot about dialogue and characters,
and so now I want to actually go and draw those characters.
I think I'll probably make that my Christmas project.
But whatever your project is,
have fun,
and have a happy Christmas,
and we'll see all you listeners next year.
The intro music is Axo by Binar Pilot.
Programming Throwdown is distributed
under a Creative Commons Attribution
Share Alike 2.0 license.
You're free to share, copy, distribute,
transmit the work, to remix, adapt the work,
but you must provide attribution
to Patrick and I,
and share alike in kind.