Jim Lynch Codes
  • Blog
  • About Jim

Writings about one coder's stories & experiences.

Is ClojureScript's Hot Reload Better Than OUR Hot Reload?!

10/26/2016

0 Comments

 
Update: It turns out this no-refresh Hot-reload functionality is possible in both Angular and React JavaScript world! Scroll to the bottom for more information.

Let me preface this post by saying that I'm really not a ClojureScript developer (nor am I really even a Clojure developer). I've gone through a few episodes where I looked at Clojure, but I always deemed it as too crazy to actually be a viable programming language... until recently.   There's something especially magical about Clojure's hot reload that makes it better than other hot reload tools; actually, two things:
​
  • You don't need to refresh the page after the code reloads. 
    ​

  • Your app state is preserved after the page reloads.
    ​
This may not seem like much, but  if you are familiar with the current state of "hot reload" tools for Angular, React, or just JavaScript in general you'll probably be aware that those tools don't have these two characteristics above. As you'll see, this subtle improvement can have a substantial impact on your productivity as a developer for multiple reasons. Let's dive into them!

Front End Frameworks Rise To Power

The early days of browsers on mobile devices were brutal. The web was full of error messages on sites running java applets, flash player, etc. to the point where virtually everything was killed off except JavaScript. Although the recent Es2015 version of JavaScript adds support for things like classes and block-level scoping, JavaScript has a rough history with it's strange behavior at times quirky traps. Douglas Crockford wrote a very short book called JavaScript: The Good Parts, and people took this somewhat jokingly to imply that there were many "bad parts" in JavaScript. The community though it was so bad in fact that a plethora of javascript frameworks pooped up to try to modularize web apps into components and (sometimes) to bring OOP to web development.     

Hot Reload for JavaScript- It's Pretty Hot

When you are developing an application that runs in the browser it makes sense to see it running (obviously!). Of course, you quickly get tired of the process to must go through just to see a minor change. Make a change in the code, switch over to the browser, click refresh, navigate to the spot you want to test, check it, repeat. This is terribly tedious, but with tools like BrowserSync and LiveReload we now have a slightly more comfortable development environment; when you make a change to the code your browser automatically reloads! Huzzah! That's pretty spiffmatic (yes, I did just make up that word), and so much so that pretty much every yeoman generator, project starter, and medium-to-advanced template for Angular, React, and pretty much every other JavaScript browser project has some form of this Hot Reload functionality built into it. If you're a JS dev you might look at others without similar tools and scoff at their inefficient, barbaric ways. But don't get too smug, JS devs, because you're about to be pretty jealous...

What the Heck is Clojure?

Unlike most mainstream programming languages, Clojure comes from the Lisp family of languages. This explains why Clojure looks so much different from other languages and why some coders can be very turned off by its syntax (seriously. If you aren't familiar with a Lisp go take a look at some Clojure code. It can be incredibly cryptic to the untrained eye). ClojureScript is not a very mainstream language, but it is built on extremely solid computer science principles and is quite stable now, almost 6 years after it was released in 2011 (and the original Clojure for JVM was created in 2007). Although it may seem like the the silver bullet language in some ways, there is a sizable learning curve for mastering Clojure. Not only that, you (assuming you are running a software organization) need to have programmers who want to learn and code in Clojure (which also is quite rare). Although I would not recommend anyone try to learn Clojure or ClojureScript as their first language, I think everyone should give it a fair chance because it's pretty dang awesome one you get the hang of it (although it can be quite an elusive hang to get).

Why Clojure's Hot Reload Is Scorching-Lava-Hot-As-The-Sun Hot!

Clojure is a pretty niche language and ClojureScript is even more so. Therefore, you could imagine that the tooling for it might not be as good as some of the more popular languages. Sure that was the case for a while... until figwheel came along. With figwheel (by the way, I have no idea where that name came from. You should ask it's creator, Bruce Hauman) as soon as you make a change in the code everything just updates... like magic. There is no browser reload. The change just takes effect in the app. There is no browser reload! Wow. No, seriously. This subtle difference actually makes ALL the difference. Regardless of which bundler you are using (browserify, webpack, or the hot new jazz of today) you still need to round up all of your files, convert them to JS / HTML / CSS, and ultimately load up a new instance of your application, thus losing your place in the webapp where you were before the refresh happened. So with figwheel our app just updates, reflecting the change in code, without restarting the app or changing anything about our state. Combine this with the sheer number of seconds saved by not waiting for your hot reloader to actually reload, add in a multiplier for how you never lose your "flow" or thought process because of the reloading, and one can begin to see how you could seriously improve your productivity by developing like this. This blew my mind the first time I learned about it, and it doubly blew my mind when I was able to witness a seasoned Clojure developer in action creating a site with this figwheel tool. It was truly magical, and I hereby formally endow the figwheel tool with considerably large props and thanks.

Should We All Switch to ClojureScript?

This is a tough question, and unfortunately I don't think the answer is undoubtedly "yes". First of all, is it possible for you build whatever front-end browser thing you want to make with just ClojureScript? Pretty much yes, you can. ClojureScript can just call a JavaScript function, and there's a pretty flexible interop api. One thing that might make you wary is the lack of Clojure jobs out there right now. Sure, some companies are hiring Clojure or ClojureScript developers right now but it's a small fraction of the number of postings for JavaScript, Java, Python, Ruby, etc. If I were a programmer reading this post with no prior knowledge of Clojure I'd say keep your day job but be open-minded and give Clojure a chance. Play around with it in coderpad.io or try to build something with Om (a library for React + ClojureScript), Reagent (another library for React + ClojureScript), or Gyr (AngularJS + ClojureScript). You could also experiment with ClojureScript for targeting Node.js! I'm curious to see if there will ever be a figwheel equivalent for JavaScript. My gut feeling was that if it was possible it would exist already and that the key to making it possible lies in the functional nature of Clojure code.

What Do You Think?

Are you a ClojureScript developer who uses fighweel? How are you liking it?
Are you a JavaScript developer interested (or not) in ClojureScript? I want to hear from you too! :)
Leave a comment or tweet me @webWhizJim

Update - 11-/17/16

I'm glad to say that the state of JavaScript web development has indeed improved, and we now have magical tools akin to figwheel for Angular and React projects! The term that's commonly used in the JavaScript world is, "Hot Module Replacement". On changes, your modules are just "replaced", and no page load occurs. Awesome! I'm exactly sure how it works under the hood, but it seems that something about the Webpack file bundler is also making this possible. For Angular 2, definitely check out this Angular2-Webpack-Starter project which has this hot module replacement feature integrated. For React, definitely check out React Production Starter, React-Redux-universal-Hot, or React-Redux-Starter-Kit!
0 Comments

Your comment will be posted after it is approved.


Leave a Reply.

    ​Author

    Picture
    The posts on this site are written and maintained by Jim Lynch. About Jim...
    Follow @JimLynchCodes
    Follow @JimLynchCodes

    Want FREE access to
    my daily stock tips 
    ​newsletters??
    Sign up here:

    - Triple Gainers
    - Rippers N' Dippers
    - Growingest Growers
    ​

    Categories

    All
    Actionscript 3
    Angular
    AngularJS
    Automated Testing
    AWS Lambda
    Behavior Driven Development
    Blogging
    Business Building
    C#
    C / C++
    ClojureScript / Clojure
    Coding
    Community Service
    CS Philosophy
    Css / Scss
    Dev Ops
    Firebase
    Fitness
    Flash
    Front End
    Functional Programming
    Git
    Go Lang
    Haskell
    Illustrations
    Java
    Javascript
    Lean
    Life
    Linux
    Logic Pro
    Music
    Node.js
    Planning
    Productivity
    Professionalism
    Python
    React
    Redux / Ngrx
    Refactoring
    Reusable Components
    Rust
    Security
    Serverless
    Shell Scripting
    Swift
    Test Driven Development
    Things
    TypeScript
    Useful Sites
    Useful Tools
    Video
    Website Development
    WebStorm
    Writing

    Archives

    February 2021
    January 2021
    October 2020
    September 2020
    May 2020
    April 2020
    February 2020
    January 2020
    December 2019
    October 2019
    September 2019
    August 2019
    July 2019
    June 2019
    May 2019
    April 2019
    March 2019
    February 2019
    January 2019
    December 2018
    November 2018
    October 2018
    September 2018
    August 2018
    June 2018
    May 2018
    April 2018
    March 2018
    February 2018
    January 2018
    December 2017
    November 2017
    October 2017
    September 2017
    August 2017
    July 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    December 2015
    November 2015
    October 2015

    RSS Feed

  • Blog
  • About Jim
JimLynchCodes © 2021