12

Dead code elimination in clojurescript

 3 years ago
source link: https://blog.klipse.tech/clojure/2016/03/23/dead-code-elimination.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Dead code elimination in clojurescript

Mar 23, 2016 • Yehonathan Sharvit

Do you see any substantial difference between the two pieces of code below?

Code #1:

(if 2 3)

Code #2:

(def x (if 2 3))

They seem to be quite the same, so you’d expect their js transpiled code to be the same.

Let’s check it with KLIPSE:

xxxxxxxxxx
(if 2 3)
(def x (if 2 3))
cljs.user.x = (3)
;

Do you see what’s going on here?

Code #1 is completely dead code no matter what code will come after it. Therefore it has been completly eliminated by the cljs transpiler!

Feel free to continue to play with dead code with KLIPSE.

If you enjoy this kind of interactive articles would you consider a (small) donation💸 on Patreon or at least giving a star⭐ for the Klispe repo on Github?

Follow viebel to stay up-to-date with the coolest interactive articles around the world.

Discover more cool interactive articles about javascript, clojure[script], python, ruby, scheme, c++ and even brainfuck!

Give Klipse a Github star to express how much you appreciate Code Interactivity.

Subscribe to the Klipse newsletter:

Feel free to email me [email protected] for getting practical tips and tricks in writing your first interactive blog post.


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK