• ☆ Yσɠƚԋσʂ ☆OP
      link
      fedilink
      arrow-up
      2
      ·
      3 years ago

      I’ve seen this kind of stuff, but my experience is that it’s very limited in practice and doesn’t work reliably. I think there are some inherent limitations using an imperative language because you have a lot of shared mutable state, and when you try to reload parts of the app it’s very easy to break other parts in the process.

      Big advantage of being able to reload parts of the app that change is that you can build up state and work within that context. Let’s say you have a complex app where a user has to log in, navigate to a particular view, then load some data, and then you need to implement the part that operates on that data. Being able to get the app in that state and then play around with different ways of presenting the data will save a lot of time compared to having to repeat all the steps each time you make a change.

      The other aspect of ClojureScript workflow is that you have a REPL, so you can run any code in the app directly from the editor and see what it’s doing.

        • ☆ Yσɠƚԋσʂ ☆OP
          link
          fedilink
          arrow-up
          2
          ·
          3 years ago

          As I mentioned, my experience is that the benefits aren’t really comparable to what you get with cljs, but I realize that not everybody has the option of using it. So, it’s nice that you get some form of hot loading in js nowadays.

          It’s worth noting that cljs toolchain offers a lot of other benefits as well. For example, the compiler does minification and code pruning out of the box. Code pruning works down to function level because the compiler can reliably tell where a function comes from and where it’s used. If you include a library and use single function from it that’s what gets included. The compiler is also able to do things like code splitting based on namespace hierarchy. So, you can trivially break up your app into separate bundles.

          All of these things are really important for front-end code since you want to reduce bundle size that’s sent to the browser. And while it’s possible to do a lot of this stuff with js, just as with hot loading it’s not consistent or reliable.

          This comparison really illustrates the benefits of the above. ClojureScript with re-frame actually beats React+Redux in performance even though it uses React under the hood. It produces a significantly smaller bundle, and results in second least code out of all the frameworks tested.

          ClojureScript does take a bit more up front effort to learn coming from a different family of languages, but I would argue the effort is well worth it. Learning to look at problems from a different perspective is a valuable skill that’s transferable to imperative languages as well. I certainly gained a lot more appreciation of the problems with having shared mutable state after using Clojure. This is something I didn’t even consider when I worked exclusively with imperative languages.