Programming Throwdown Episode 61 [PODCAST]

Sign up for weekly Clojure tips, software design, and a Clojure coding challenge.

In this podcast, we talked about Clojure and Functional Programming as well as the best ways to learn them.

Programming Throwdown Episode 61

Transcript

**Patrick Wheeler**:  [00:15] Programming Throwdown," episode 61, Clojure with special guest Eric Normand. Take it away, Jason.

**Jason Gauci**:  [00:22] Hey, everyone. If you are a long-time listener, you may remember. We did an episode on Lisp almost three years ago. We are coming back, and we are covering in a lot of detail. One of the comments that we got when we did the Lisp episode from a lot of people was, "Hey, we want to learn more about Lisp." Here's some more details about Lisp and things like that.

[00:45] This is before we really had a strong social network presence where the only way you could really communicate was by emailing us. We got a lot of email about Lisp. We're really happy...Go ahead, Patrick.

[00:58] [crosstalk]

**Patrick**:  [00:59] We also briefly did mention Clojure on...We did a collective episode of a bunch of JVM languages.

**Jason**:  [01:05] That's right. We mentioned Clojure by name there. We have Eric Normand to talk in much more detail about Clojure and teach all of us a lot of really cool things about Clojure. Eric, tell us about yourself and what do you do?

**Eric Normand**:  [01:24] Hi. My name is Eric Normand. My current tagline is I help people thrive with functional programming. I run a site called PurelyFunction.tv where I teach people Clojure. I want to expand it to other functional programming languages. I basically teach with video and exercises and other online things.

**Jason**:  [01:53] What inspired you to build that site and to teach people Clojure and other functional languages?

**Eric**:  [02:00] It's evolved over time. I have always liked teaching. Well, always. I was a teacher in the Peace Corps. I was teaching math. When I got back, I started missing it. I started programming again. I started making videos off and on.

[02:24] At some point, I did a Kickstarter to get some Clojure videos made. That was a success. Ever since then, I've been adding more and more videos.

**Jason**:  [02:37] What is it like, running a Kickstarter? I've funded several Kickstarters. I've never Kickstarted anything. What was that process like?

**Eric**:  [02:49] It wasn't that big of a deal. I think the biggest thing was, beforehand, I talked to my friend who has funded a lot and saw what worked and what didn't. I hadn't been active on Kickstarter at all.

[03:07] It was a lot of discussions with him about, what should I set my goal at, what should my rewards be, that kind of thing. He helped me come up with the structure there.

[03:25] I'd 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. I did mine for 30 days, which at that time was the default. I don't know what the default is now.

[03:43] At that time, it was default to 30 days. That's 30 days of you tweeting, and promoting, and being generally on edge about whether you're going to make it. If I were to do it again, I would probably cut it down to like 10 days or 15 days.

[04:03] Most of the backers came in at either the beginning or the end. If you just cut out the middle, then I would have had the same amount. More or less [inaudible] .

**Jason**:  [04:15] One thing that I noticed is, the audience wants to have faith in you, in your delivering on the Kickstarter. If you're messaging every single day, like, "Here's what I ate for breakfast today. I ate Clojure-flavored Cheerios." [laughs]

[04:33] Then people know, OK, this person means business. If I donate, one, it's going to work out. Two, I'm donating to more than just a set of videos. It's like a cause.

**Eric**:  [04:47] For sure. It really helps to have an audience before you start. I think that's the number one failure reason, is people don't have anybody who can list. They're shouting into the void.

**Jason**:  [05:04] If you had to explain functional programming to someone who's never heard it before, how do you describe that? Let's say there's someone who has taken some courses. They get C++ really well, but they've never seen Lisp, or Haskell, or Clojure, any of these. How do you explain that to them?

**Eric**:  [05:33] That's a really hard and complicated question because I don't think there is a very agreed upon definition of functional programming.

[05:46] Functional programming comes from Lambda Calculus. Lambda Calculus is a mathematics that uses nothing but functions. There's definitely the notion of using functions as your main form of abstraction.

[06:08] Functions are higher order. That means that they can be passed to other functions as arguments and you can return functions from arguments. Functions are values that you can pass around.

[06:25] Languages like C, C++ you can...Let's take C because I know that a bit better. You can pass function pointers around and stuff and people do interesting stuff with that, but they don't have what's called lexical clojures. It's a technical term. It just means a function that can refer to variables that are defined where the function is defined.

[06:52] 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. You can't capture the environment that it was in. You can't really do the functional stuff.

**Jason**:  [07:21] That makes sense. One analogy is if you've ever played World of Warcraft or any of these MMOs or many games like it, in the beginning you get the wooden sword and you just hit the rat over and over again. As you get better and better, you get one of these swords that has what's called a proc which is short for procedure.

[07:47] It might be when you hit somebody, there's a 10 percent chance of them turning into a chicken or something.

[07:56] That process, that event is tied to that sword. Like you want to assign the turning into a chicken into that weapon and be able to if you give the weapon to someone else, you give that logic to them too.

[08:16] A part of functional programming is this idea that you can pass these functions around as sort of first-class citizens.

**Eric**:  [08:24] Wow, that's a really great metaphor there.

**Jason**:  [08:28] Yeah, I played too much World of Warcraft.

[08:30] [laughter]

**Eric**:  [08:32] Another way to look at it that I've heard about is if you're familiar with object-oriented programming, you've got objects that have methods. That's data with functions attached. In a lexical clojure like in a functional language, you have functions with data attached. The variables that are defined in the scope are the data that you can access from that function.

**Jason**:  [09:12] That's functional programming. We covered Lisp in the Lisp episode. Basically, what is clojure? When we covered clojure we just very superficially said clojure is Lisp on the JVM, but I'm sure it's much more than just that. You're, "How does clojure fit into this whole landscape?"

**Eric**:  [09:41] A good question. Clojure is a Lisp for the JVM. Lisp is cool because it's like a family, it's got dialects. Clojure is a dialect of Lisp that is made to be hosted on a virtual machine. JVM is like the first virtual machine that it's hosted on.

**Jason**:  [10:08] Is there something that you can't do in closure because of that? Because it's a dialect of Lisp, is there some things that aren't there or are there that aren't in regular Lisp?

**Eric**:  [10:22] That's a good question. It's a different language than Common Lisp. There's a lot of stuff that comes with Common Lisp that is built into the language. Whereas, in Clojure, because it's designed to be hosted, it just relies on what the host can do.

[10:44] I'll give an example. Common Lisp has this very sophisticated and a lot of features in the exception mechanism. When you throw an exception, you can actually do what's called a restart. You catch this exception and you can fix the problem, recall it and go right back to where the exception was thrown.

[11:09] If the fire's not found, you'd be, "Oh, not found. Well, let me make it." Then, you go right back in to where it was.

[11:19] Whereas, in Java, 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. The call stack gets unwound and it's lost. You can't go back to where you were.

[11:36] Clojure borrows all of that stuff from the host that it's on. That includes Clojure's numbers are Java numbers. Clojure's strings are Java strings. Functions in Clojure get compiled into a Java class. All this stuff becomes some concept on the JVM.

**Jason**:  [12:06] Got you. That makes sense. How are some of these things possible? In Java, you can't have Clojures, right? I'm assuming Clojure can't be built in Java. In other words, the concepts of Clojure have to be added in machine code to the JVM or something?

**Eric**:  [12:36] Actually, it's really interesting how it's implemented. Most of the language is written in Java. Most of the data structures, most of the logic and the compiler, it's all in Java.

[12:55] The way Clojures are implemented is, like I said, there's a class. When you have a new function that you're compiling, it extends that class, that function class.

[13:15] The function class has a bunch of methods on it. Each method is a different signature. It will have the zero argument method. It will have the one argument method, the two argument method, etc. The class it compiles to will extend those.

[13:39] All of the data in the Clojure, meaning the variables and the scope that it needs to access, get put into the class as member variables.

**Jason**:  [13:53] OK. That makes sense. Yeah, that's very clever. [laughs]

**Eric**:  [13:57] It's clever. It's a way to use the function or the method called semantics of the JVM without having to invent some other mechanism.

**Jason**:  [14:13] For somebody who's maybe really into web development or you've done a lot of C++, backend work, Java, why should they learn Clojure?

[14:30] For somebody who's already mastered one or two or several languages, we always talk about this metaphor of the toolbox and how there's not one magic language, just the same as there's not one magic wrench that just does everything, or not one magic tool that does everything. It's a wrench and a hammer and whatever.

[14:54] If someone wants to assemble this toolbox of languages that's comprehensive, what does Clojure add to that toolbox?

**Eric**:  [15:07] That is a really great question. It's something that I don't think is really fully answered. I can tell you there's no general one answer to satisfy that question. I'll tell you why I like it and also why people I know like it, too.

[15:33] When it first came out, the big story behind Clojure was that it handled concurrency really well. The JVM or Java, the language, has a lot of libraries and stuff for handling concurrency. There are books written about how to do concurrency right on the JVM.

**Jason**:  [15:57] Yeah, it's very hard.

[15:58] [laughter]

**Eric**:  [15:59] Yeah, it's hard. You have to read this book and do everything right or you're going to get bugs.

[16:07] What Rich Hickey, the creator of Clojure, did is he took that book and basically built the language around that. It works that way. It's very hard to not do it that way.

[16:25] A lot of the primitives in the language...there's all sorts of stuff in Java. You use the volatile key word. You make stuff immutable and things like that. All of that is taken care of for you.

[16:42] It has this really nice story of concurrency is the default. It works easily right out of the box. That is true. It's really nice. It's weird when I go to another language and I'm, "Well, how do I do this at the same time?" You can't. You have to do this other completely boiler plate system to get something else to run at the same time.

**Jason**:  [17:12] That's a huge, huge problem. What typically happens is, especially if you're building an app for the desktop, you have some kind of UI and the person specifies some files. You want to go off and do a bunch of work on those files. It's almost always embarrassingly parallel.

[17:32] Very rarely do you need to do very sequential, one thing at a time. Usually, someone gives you a batch of things to do. In most languages like C++ and Java this can get quite painful.

**Eric**:  [17:50] Yeah. It gets painful because all the pieces are there. Like, "Well, in Java, to make a thread, you just do new thread and you have a thread. What's the problem?" That's only half the answer.

[18:05] The other half is, now that you 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. It's all these ancillary problems, like, "Oh, maybe I need a cue."

[18:20] OK, you're going to construct the thread, and the cue, and the thing. It just never ends.

**Jason**:  [18:26] Yeah. Totally.

**Eric**:  [18:28] Whereas in Clojure, it's as simple as, "Well, I'll just have..." There's a bunch of different primitives. One of them is called an atom. An atom is the simplest kind of shared state. It's just one pointer that you can change.

[18:48] You can have multiple threads accessing this pointer, you can read from it, or you can write to it. It's thread safe. One of the reasons I really like it is, the focus of Clojure is on the simplicity of separating out all the different problems and solving them independently, so that you can compose them back together.

[19:17] You have the atom. All it does is keeps one pointer and makes 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.

[19:38] You can't see it halfway done. That is what allows multiple threads to read and write to it. Really, with very little code, you don't have to deal with locks and stuff like that. It's all handled by the atom.

[19:56] The simplicity of, "Here's the right tool for the job," and the language just gets out of your way, I really appreciate that.

**Jason**:  [20:10] It makes sense. 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. These things were important in the '90s.

[20:24] Now, it's like, if you have three threads and each one locks the UI updates and unlocks it, computers are fast enough where we don't need that level of control. If you are willing to sacrifice the level of control, you could have a much cleaner language.

**Eric**:  [20:44] Yeah, for sure.

**Jason**:  [20:47] There's people like Patrick, could do crazy robotic stuff, homebrew stuff. He's got a drone firing lasers that people come to his house.

[20:58] For the rest of us, the other 99 percent of us, we're either building a website, a desktop app, which could include a server that's serving web pages or a mobile app, like an iPhone app or an Android app. Can you do these three things, any or all of these things in Clojure? How does that work?

**Eric**:  [21:22] Yes, for sure. 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. Most of the Clojure Web systems are some wrapper that uses the servlet API.

[21:58] Actually, the Clojure ecosystem, Web ecosystem is evolving right now. For a long time, the main system was called ring. It's like Rack in Ruby. All it would do is it would take the request and turn it into a map. It has a standard format mat. The request method was under a certain key. There was a string.

[22:30] The port was a different key and it was a number. You could get this map and then you did whatever you want with it. You would return a response with another map in a similar format. There's three concepts.

[22:56] There's the adapter, which is the thing that connects to the servlet API, or whatever API you're using to do the Web stuff. That adapter connects to the API and converts requests into the ring request, and converts the ring response back into an HTTP response.

[23:18] You have your handlers, which are functions from requests to response, and then what's called middleware, which transform the request or the response as it passes through. It actually transforms the handler into a new handler.

[23:42] You would basically construct your Web app out of these pieces. Like I said, it's evolving. People are learning stuff. They want to do asynchronous stuff. Functions aren't great for doing async calls. That's still the main ideas, is that you got this request map and a response map.

**Jason**:  [24:07] If you're used to doing Java, server-side Web development, all of those ideas translate almost one-to-one to Clojure. Someone has written adapters. You can work in a completely Clojure environment to not have to worry about all of those bridges.

**Eric**:  [24:28] That's right. To me, it feels much cleaner. How do I put this? It's much more direct. In the servlet API, you get this request object that you query like...You call the method like get method, which gives you the HTTP method.

[24:56] You really have to understand this API really well and look up the docs. When you do the response, you have to do set header. You're not supposed to call set header after you've typed in the body. There's all sorts of rules for how to use these things.

[25:23] To me, that it's really hard to keep track of. In ring, the adapter is supposed to handle that. You handle that one time. 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 is done."

[25:50] That's the thing I really appreciate with the Clojure community. There's actually libraries that they're like, "It's done. We finished."

**Jason**:  [25:59] [laughs] Nice.

**Eric**:  [26:01] It's not this continuing thing, like, "Oh, we're trying to adapt it to this other situation, so you don't have this problem." We solved it." [laughs]

**Jason**:  [26:13] What about mobile? If you're building iPhone app or Android app, can you do that in Clojure?

**Eric**:  [26:20] There's a couple of options. 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. Most of the work now is in React Native.

[26:47] There was some stuff with PhoneGap. We didn't talk about this. Clojure also compiles to JavaScript. I talked about it being hosted on the JVM, or another host that Clojure can run on is JavaScript. When it's compiled to JavaScript, it's called ClojureScript.

**Jason**:  [27:09] Does it use the V8, or SpiderMonkey, or both?

**Eric**:  [27:13] It's whatever you want, it's JavaScript. You can run it on any of the JavaScript [inaudible] .

**Jason**:  [27:17] That is super cool.

**Eric**:  [27:22] You can run on node. You can serve it through a Web app, and 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.

**Jason**:  [27:42] That is quite remarkable. JavaScript is very universal. 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 Clojure would be much better.

[28:05] You can actually write Clojure, and it will compile or transpile down to JavaScript. That's pretty cool.

**Eric**:  [28:11] That's right. You said the word transpile. That's what it's doing. A lot of times when people think transpile, they think CoffeeScript. I have nothing against CoffeeScript. One of CoffeeScripts' goals was to be just JavaScript, but with better syntax.

[28:37] You could guess what JavaScript would be generated.

**Jason**:  [28:42] Yeah. It's two-way. You can actually...

**Eric**:  [28:45] You can convert it back? [laughs] I didn't know that.

**Jason**:  [28:47] No, sorry. It's not two-way, but there's a...what's the word? There's a JavaScript compiler for CoffeeScript. On the CoffeeScript website, you can paste CoffeeScript, and it will turn it into JavaScript.

[29:02] You just write there on the website. That's what I use CoffeeScript for, for taking other people's CoffeeScript and converting it to JavaScript.

**Eric**:  [29:14] I see. That's a valuable thing to do, is to make the syntax better, because JavaScript can get pretty verbose. ClojureScript is different. It really feels like a different language.

**Jason**:  [29:31] By that token, when you transpile it, you get JavaScript that's unintelligible. It's almost like looking at assembly or something.

**Eric**:  [29:42] Exactly. It doesn't do like asm.js. Clojure functions compile into JavaScript functions. A lot of the IF statements, you could read them. What gets hairy is that it does a lot...the compiler does some optimizations.

[30:10] What looks like a regular function call is actually going to turn into, in JavaScript, a dot call. Functions in JavaScript actually have methods, and one of them is dot call. When you're looking at the compiled code, it's a little crazy, because doesn't look like you would write JavaScript at all.

[30:35] That's OK because the source-mapping is all in there. 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 trace.

**Jason**:  [30:52] Nice, so source-mapping. Actually, it'd be amazing if you could explain it because I have no idea how it works. Basically, I've used it for TypeScript. What it does under the hood, I don't know. Hopefully maybe Eric can educate all of us. On the surface you've written in TypeScript, but the person and the browser is still executing JavaScript. The person could be you.

[31:17] When you get an error, you don't want it to just show you this completely unintelligible JavaScript. You want the error to actually redirect back to your code that you can actually modify. The Sourcemap helps make that happen.

**Eric**:  [31:33] For sure. That's a great explanation. If you're going to serve up some JavaScript, usually you're going to minify it and maybe ugly-fy it. It's going to be one long line of JavaScript, and that's going to be impossible to debug. It's going to say, "Line one."

[31:53] [laughter]

**Eric**:  [31:54] Bugs on line one."

**Jason**:  [31:55] It's always on line one.

**Eric**:  [31:57] [laughs] Exactly, exactly. 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 then the line that they correspond to in the original file in the code that you wrote.

[32:26] That works for JavaScript and CSS I think because people minify that, too. It's really nice now because they've got it where you can put break points. You can debug it and step through line by line, what you think of as a line because this is a code you wrote.

[32:49] You can put a break point there and walk through line by line, even though it is compiled into some crazy JavaScripts that you can't read.

**Jason**:  [32:58] Oh, man. That's awesome. I never actually knew you could do that. I always had unminified code when I was debugging. I'd never needed to do that. [laughs] That's cool.

**Eric**:  [33:12] That's actually largely thanks to one system that the ClojureScript compiler uses. It's called the Google Closure Compiler. That's closure with an "s." Google Closure. The Closure Script Compiler is a very simple naive compiler, but it outputs code that the Google Closure Compiler can read.

[33:40] The Google Closure Compiler is what Gmail has built in, and it does some really aggressive optimizations. There's different modes. When you're going to release your code, it does all this crazy optimizations on it like totally analyzing code paths, eliminating functions you don't call, and things like that.

**Jason**:  [34:05] Just to explain because it's super confusing. There's a Google Closure Compiler. I think it's...

**Eric**:  [34:14] The naming is really terrible. [laughs]

**Jason**:  [34:16] 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. Think of it as an optimizer. You could compile your code with DashO Zero with no optimizations, or you can compile your code with DashO Three.

[34:44] Even though it's the same code, same logic, it produces a totally different binary. That binary has all sorts of crazy GCC optimizations baked into it. Clojure is like compiling with DashO Three, but it's in JavaScript. JavaScript goes in. JavaScript goes out, but the Java Script that comes out is a much more efficient representation of what you originally intended.

[35:15] That's different than Clojure with a j, which is what we're talking about. You can actually use ClojureScript with Clojure to write in Clojure and produce really fast JavaScript.

**Eric**:  [35:31] That's right. That's right. It is some really cool technology. It's from Google. That's what they use to produce Gmail. There's stuff like what's called Module Splitting. Imagine you're developing this web app. Your front page is going to have some JavaScript on it, but you don't have to be logged in to do it. Most people who go to that front page aren't going to log in.

[36:05] Then there's all the people who log in, and they're going to have this rich web-app experience so a ton of JavaScript. The thing is, you don't want to serve that big JavaScript to just the people who just go to the front page.

[36:23] The idea behind splitting is that the compiler can analyze your code and figure out, "Well, the front page uses this bit of code. The back end uses this bit of code. Then this bit of code is shared between the two. You can cash that one that's shared between the two and only serve the home-page code and that shared code to the people who are visiting the front of your site.

[37:04] Then after they log in, they can get the rest of the code. It's a way to optimize the experience for people who don't need that part of the code.

**Jason**:  [37:15] Cool. That makes sense. 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 maybe 10 milliseconds, of course it depends on different products and different sites, that the front page takes to load, you lose x percent of your customers.

[37:44] It's pretty significant. If Clojure can separate that and speed that up, it's awesome.

**Eric**:  [37:52] That's exactly the reason that people want to do it. It's just that speed of first load, but still provide some JavaScript. The recommendations are to do all of that manually. Keep two files of JavaScript and to keep that manually. That's crazy.

**Jason**:  [38:18] It's way too much work.

**Eric**:  [38:19] It's way too much work. We've been talking about all this cool stuff we can do. The thing is, the development experience in my opinion is better than the JavaScript development experience. It's not like, "Oh, you get this great language," but then you've lost something because you have to have all this tooling and stuff.

[38:47] 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. Four years ago, the space wasn't so developed. I don't think Angular was even out yet. Backbone was new. It was all this stuff. We were using cat, the Unix command, to put different JavaScript files together.

**Jason**:  [39:21] Oh, no. [laughs]

**Eric**:  [39:22] There was no Bower and Grunt. I don't even know what they are. It was very simple times, and it worked. It worked. Then I went into ClojureScript. I was doing it the way you do it in ClojureScript, and ClojureScript was really new. A lot of it was raw, but it was evolving very quickly. Then I had to go back to JavaScript for another job, and I was just shocked.

[39:55] 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.

**Jason**:  [40:03] [laughs]

**Eric**:  [40:03] Yarn, NPM. I'm like, "NPM didn't exist when I left JavaScript before." It is just so crazy how many libraries and tools you need to develop nowadays in JavaScript.

**Jason**:  [40:23] It sounds like the ClojureScript is easier to work with than Emscripten. [laughs] If you've ever used that, it's a total nightmare.

**Eric**:  [40:32] I don't even know what that is.

**Jason**:  [40:35] Emscripten is this thing where it takes C++ code and turns it into JavaScript. It actually goes through LLVM and then goes LLVM to JavaScript. Zynga used it for all of their games. The idea is...

**Eric**:  [40:53] Ah, for games.

**Jason**:  [40:55] If you play Zynga Poker on your phone, that's almost all C++ code. There's just a little bit of your iOS or Android code to handle the drawing and things like that. If you play Zynga Poker on, say, Facebook.com or even Zynga.com but on the web version, that's also C++ code. It's the same code, but it's been translated to JavaScript with Emscripten.

[41:25] Talking to people who've worked at Zynga, it's just a total nightmare. [laughs] If you have a bug in the C++ part...

**Eric**:  [41:33] [laughs] Oh, man. No bugs.

**Jason**:  [41:34] you just have to catch it on mobile. If there is some bug where, if someone gets all four aces it crashes or something, you just won't catch it on the web. It's lost. [laughs] You just have to hope that you have that same bug on mobile.

**Eric**:  [41:50] I'll tell you. I don't mean to bash on all these languages. I love languages. They're great, but I recently had to work in C++. I don't know C++, so it was totally new to me. I was already dealing with all of the novelty of everything, but the build system...

[42:14] It took me over a week to get it to build on my machine. I could imagine if then you finally got it to build, now it's running in the browser, and you don't have any Sourcemaps or something like that to debug it, oh, man.

**Jason**:  [42:33] It's a total nightmare, but you're totally right. Now things are a little bit better. There's Bazel, and there's Buck. Bazel's from Google. Buck is from Facebook. They're basically the same thing, but even then, they're not great.

**Patrick**:  [42:54] Even dependency management in C++ is still really bad.

**Jason**:  [42:58] It's a total nightmare. There's really no repository that I know of. There's not really a central repository of C++. I don't even know how that would work because you wouldn't be able to keep the binary because it's machine-specific.

**Eric**:  [43:14] I don't even know where to begin with that. I'm not in that world, and I'm glad I'm not.

**Jason**:  [43:24] It sounds like ClojureScript is better than that, [laughs] is more mature than that.

**Eric**:  [43:32] The thing about JavaScript is it's a huge ecosystem. There's so many people in it. People are dissatisfied with their tools. They write new tools, but there's so much to keep up with. Every six months you have to rewrite your build system because it's not using the newest thing and you need a feature from the newest one. That's why in my personal website I use cat.

[44:02] I have a make file and I cat JavaScript together. JavaScript is like that. You can do that. You can just take two bits of JavaScript and smoosh them together, and you have a bigger [laughs] JavaScript. I guess I'm getting older. I just don't want to deal with these cycles of learning a tool and figuring out it's JSON config format. I can't deal with that.

**Jason**:  [44:42] Absolutely. When I was in college, I got a Gentoo. 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 like you get in. You install the boot loader. You spend about an hour entering all these different commands to install the boot loader.

[45:09] At the time, that was super cool because you feel like this Neo from "The Matrix," like some crazy hacker.

**Eric**:  [45:16] Windows took a long time to install, too.

**Jason**:  [45:19] In terms of effort, Windows definitely took a while to write to disk and all of that, but this was like you have your boot loader. You'd reboot to the command line to just a root prompt. Sometimes you'd do it wrong. You'd reboot, and nothing would happen. That was super, super fun at the time.

[45:44] As soon as you become a professional and someone says, "When is this going to be done?" and you say a week, then instead of taking 18 hours it takes 30 hours to install your OS, you're in big trouble. [laughs]

**Eric**:  [45:57] For sure.

**Jason**:  [45:58] It's not fun anymore. [laughs]

**Eric**:  [46:01] For sure.

**Jason**:  [46:02] You immediately switch to, "OK, I need something reliable that's quick that I could depend on.

**Eric**:  [46:10] Sure. I remember in the '90s I used to run Linux, and it was the same as you were saying. It would take this huge amount of time to select your video card and make sure that x Windows would work with it and get all the settings right. There was no auto detect at that time. Then at some point I would just be like, "OK, enough. I need to check my email."

**Jason**:  [46:40] [laughs] Right.

**Eric**:  [46:42] I would just use the barest x there was. Barest x windows, the one where you boot into x windows, and you have to right-click to get a menu... [laughs]

**Jason**:  [46:53] It's just like that weird...

**Eric**:  [46:55] or you just get a terminal.

**Jason**:  [46:56] That horrible grid of black and white dots, and your cursor is an x.

**Eric**:  [47:01] Exactly. [laughs] Exactly, exactly. You'd just have a terminal. I would just type Netscape [laughs] in my web browser, so nice.

**Jason**:  [47:11] Good old days. Let's say someone has a website already in JavaScript and it's using a bunch of different libraries. It's using Random and using all sorts of different libraries. Re-writing it is totally off the books, but now they need to do something which Clojure is really good at. How does that work? Is there some type of interoperability layer?

**Eric**:  [47:39] Yeah. Because Clojure and ClojureScript were designed to be hosted, the interop is just really seamless. You can call, first of all, any function. You can just call it like a JavaScript function.

**Jason**:  [47:55] Oh, nice.

**Eric**:  [47:55] If you get a JavaScript function from something, you just call it. If you get an object, 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. The hardest part with the interop is that you're not dealing with JavaScript arrays anymore. You're going to be dealing with Clojure's immutable data structures.

[48:28] If you are doing a lot of interop where you're building up a Clojure 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. There's going to be a little performance penalty there every time you convert it.

**Jason**:  [48:45] That makes sense. Most people use objects. There are cases where you need arrays, but that's more rare, I would think.

**Eric**:  [48:54] It's the same with objects. If you're using a plain JavaScript object, just like open curly braces, Clojure would in that case use a Clojure HashMap. You would need to convert it to a JavaScript object...

**Jason**:  [49:18] That makes sense.

**Eric**:  [49:19] which basically requires walking down the HashMap and converting everything into something that JavaScript would use.

**Jason**:  [49:29] That makes sense. Cool. We have a faction of the audience. I feel like faction's a connotatively positive word, but now I'm starting to doubt myself. [laughs]

**Patrick**:  [49:49] A portion?

**Jason**:  [49:50] We have a portion. We have a section of audience that's just really into the career side. It's people who want to get into the industry. Right now, they're really wondering, "What's the job market?" or, even if they're doing freelance, they want to do freelance work.

[50:13] They're wondering, "How would this affect my freelance work? If I'm given the freedom to use any language, does this boost my productivity? On the business end of it, how rich is Clojure right now?

**Eric**:  [50:37] That is a really a good question. I'm going to take it in parts. There's a lot of Clojure jobs out there right now. It's not JavaScript because basically every company has JavaScript. If they're going to dictate what language you're going to use, there's much fewer companies that are asking for ClojureScript, but they're out there. They're definitely out there.

[51:05] They're looking for people. I do have to say a couple of things. Because it's a smaller group, it is easier to get into, and it is, I believe...

[51:29] How do I put this? If you have the JavaScript normal curve, of quality of developer, and you have the ClojureScript normal curve of quality of developer, obviously the ClojureScript normal curve is a smaller, tiny little thing, next to the JavaScript curve. The average is higher...

**Jason**:  [51:51] Yeah, I'm noticing.

**Eric**:  [51:52] because Clojure and ClojureScript are probably not their first language, whereas in JavaScript, it's much more likely that JavaScript is their first language. Even if you just think someone with two languages is better than one, you've got that going for the Clojure and ClojureScript side...

**Jason**:  [52:14] That makes sense. I think there's a lot to be said for joining a smaller community, especially when you're just learning. There's a lot of resources, there are people who are very passionate about it. You're not just completely swamped.

[52:31] If you were to learn JavaScript as your first language and learn it in a professional sense, you're just completely swamped with this, as Eric mentioned, all the different tools, all the different libraries. It sounds like ClojureScript, with a smaller community, you can really dive deep and get a good understanding.

**Eric**:  [53:00] 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.

**Jason**:  [53:11] [laughs]

**Eric**:  [53:13] Whereas Clojure and ClojureScript have a much richer history. A lot of design work went into it. It's palpable, when you're a programming in it, that things were thought out much more than in JavaScript.

**Jason**:  [53:36] Things are starting to trend in the direction of more fully-featured languages. If you look at Haskell and Scala, for example, they have type inferencing. The browsers now are more sophisticated, so you can see the inferred type. The combination of the browser and the tooling getting more sophisticated, and also the projects just becoming more complex. It dictates languages that are more principle.

[54:13] That's one of the reasons why there's just so many alternatives to JavaScript, 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. I think ClojureScript would be a great first thing for people to learn.

**Eric**:  [54:36] I just did a workshop, and we did ClojureScript. A lot of them were first-time programmers, and it went well. I think we had to install two programs on their computer. We had to get the JVM on there because the ClojureScript compiler does run on the JVM. It's written in Clojure. Then we had to get Leiningen, which is the Clojure project-management tool.

[55:10] With those two things, you're done. This is really crazy. There's an editor called Nightlight that is just a plugin for Leiningen. You just type "Lein Nightlight," and you get an editor that you open your browser to a certain URL. You've got an editor editing the code in that project.

**Jason**:  [55:43] Oh, nice.

**Eric**:  [55:45] You've got live reloading with another plugin. You're typing, and you can see the change in your browser. You can see the effect of that. It's just an amazing experience that someone can type a couple commands at the terminal and get this development experience going.

[56:07] Now you mentioned freelancing. That one I think is probably where you're going to see the most bang for your buck. If you really can choose whatever language you want, which I think is the case in a lot of freelance situations, it's so much better than JavaScript in my experience. If I was going to do freelance, I would do Clojure and ClojureScript, no doubt.

**Jason**:  [56:44] You can definitely do some pretty sick arbitrage. 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.

**Eric**:  [57:04] Yeah, exactly. I've been waiting for a little bit, like a couple of years now. We've heard that React is functional. When you have a functional language and a functional framework, it just works so well together.

[57:26] The React wrappers in ClojureScript, there's actually several that are popular. The React wrappers make it so nice. A component is just a single function. You can do all the life cycle stuff if you want, but mostly, you don't need it.

[57:47] You keep your state in an atom, 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 sweep a hackathon.

[58:18] Do something amazing in 48 hours that no one else would believe was even possible, because they were using ClojureScript. I've been waiting for it to happen, but I haven't seen it yet.

**Jason**:  [58:32] Only a matter of time.

**Eric**:  [58:34] Yeah. Maybe. I don't think I've done it enough justice. Not only is the development experience great, where you have live reloading. When I say live reloading, it doesn't mean it just refreshes the browser automatically.

[58:56] What it means is your app state is still there, but the UI...you've changed your UI code. You could be a few clicks in. You're testing out your...

**Jason**:  [59:13] You have an email app and the email's half written.

**Eric**:  [59:17] Right. Then you're like, "That component doesn't really look right." Or, "Let me add bold to this toolbar," whatever. You just add the code and bold to the toolbar, and boom, the component just changes, and the email text is still in there.

**Jason**:  [59:40] That's awesome. When we explained functional languages, three years ago now, we told people...A lot of people say, "I've never done functional programming." We've told people, "Actually, yes, you have. And probably your parents have too. It's called Excel."

[59:57] [laughter]

**Jason**:  [59:57] When you're using Excel and you type a formula, and then you pace some data, and just magically, as you're changing the formula, the spreadsheet's just changing, it feels so alive and magical. It sounds like with ClojureScript, you get that same feeling, but with Web development.

**Eric**:  [60:18] For sure. You go back to where you have to reload, and then you click through a few things to open the thing back up that you were looking at, to make sure that you did it right. "I didn't do it right," or, "I want to change the styling a little bit more."

[60:35] You have to change the code and then reload. I have no patience for that anymore. I've been spoiled.

**Jason**:  [60:43] It makes sense. [laughs] If someone wants to learn Clojure, what's the best way that they can get started?

**Eric**:  [60:53] Good question. There's a lot of book, but I'm actually going to take this as a cue to plug my stuff. I've got PurelyFunctional.tv. There's, wow, 150-something videos on there...

**Jason**:  [61:15] Wow.

**Eric**:  [61:16] of varying length. Most of them are behind a paywall. There are some things that are available for free if you want to just test them out and see if you like it.

[61:32] There's one called "Intro to Clojure," that's not Clojure Script, it's regular Clojure. It's the same syntax, same data structures, same core library. It will help you on your way. Also, I've got a page set up, purelyfunctional.tv/throwdown, and I'll give you a nice coupon code for a discount on a subscription.

**Jason**:  [62:03] Very cool. Just to recap, if you could, what was the first part?

**Eric**:  [62:08] Purelyfunctional.tv

**Jason**:  [62:10] Purelyfunctional.tv/throwdown. I'm assuming all one word, no hyphens or anything?

**Eric**:  [62:17] Right.

**Jason**:  [62:18] Purelyfunctional.tv/throwdown. If you go to that URL, you actually get a discount for some of the premium content on the site.

**Eric**:  [62:29] Yeah. Get in touch with me. My email is eric@Lispcast.com. I love answering email about Clojure. Any questions you have, that'll be great too.

**Jason**:  [62:42] Awesome. 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 did learn them eventually, but it was not intuitive.

[63:03] 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...I'm trying to think of a good example. I think actually, JavaScript is one of them. JavaScript felt natural to me, insofar as, when I was doing it, I was just inspired to keep doing it.

[63:25] There are other things, Scala is a good example, where I write some Scala, and I just want to write less Scala.

[63:33] [laughter]

**Jason**:  [63:35] I had to do it for a job, so I powered through it. I feel React Native is one of these things, where the more I did it, the less I wanted to do it. I'm going to try with Clojure, with ClojureScript, and see if it feels more natural.

**Eric**:  [63:56] I actually had the same experience. I was using JavaScript and React Native for a client. There was just so much to learn, that was the real thing. It's like, I want to get something done, but there's all these life cycle things, and a lot of the tooling was weird.

[64:21] There was all the styling and the new components that you had to learn. The biggest thing of all, which I don't think we ever solved, I think no one has solved this yet, the routing. I don't do much mobile development, and apparently routing is really important, and I just don't get it.

**Jason**:  [64:44] Yeah, same here.

**Eric**:  [64:47] It has to do with keeping track of the back button, and stuff can slide in from the right and slide in from the bottom. When you hit the back button, you want to remember the right thing to go to. Anyway, apparently that's a hard problem.

[65:11] I got my bearings in the React Native, and that was cool. I tried it with ClojureScript and it was just so fun. Now, I didn't make 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.

[65:33] I wanted to make a...

**Jason**:  [65:35] Like a tip calculator or something?

**Eric**:  [65:37] Yeah, exactly. I run, so I want to track my runs. 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. I did it, and it's so nice. I'm actually making a course about that app that I made.

[66:06] 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.

**Jason**:  [66:25] Very cool. I think that wraps it up. Merry Christmas. Happy Kwanzaa. Happy Hanukkah. Other things I might have missed, because this episode will probably go around that time. Happy holidays and all that.

[66:46] Thank you, everyone out there, for supporting the show. Thank you, Eric, for coming on the show and explaining Clojure to us. We really appreciate your time. Do you want to give a shout-out to the link one more time, so people could get that discount?

**Eric**:  [67:04] Yeah, purelyfunctional.tv/throwdown.

**Jason**:  [67:11] There it is. Have fun. Happy hacking. Hopefully, you have a cool Christmas project. Patrick's probably going to build, as I said, some robot that will terrorize his neighborhood.

**Patrick**:  [67:26] I feel like you're just going to make the feds show up at my door.

**Jason**:  [67:28] [laughs] I don't really have anything in mind. Actually, I do plan on doing a lot of drawing. I wrote a script for a game. This is like role-playing. Like one of these RPG games where it's a lot about dialogue and characters. Now I want to actually go and draw all those characters.

[67:54] I think I'll probably make that my Christmas project.

**Eric**:  [67:58] That sounds really cool. Get away from the computer.

**Jason**:  [68:01] Have fun. Have a happy Christmas. We'll see all your listeners next year.

[68:07] Intro music is aXXo by Binarpilot.

"[68:10] Programming Throwdown" is distributed under a Creative Commons attribution ShareAlike 2.0license. 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 ShareAlike in kind.