4 ms·
No, it's not. Try `(+ 1 "1")` in clojure and clojurescript. In clojure, it produces a runtime exception. In clojurescript it silently errs, resulting in a "11".
by darksaints 8y ago
No, it's not. Try `(+ 1 "1")` in clojure and clojurescript. In clojure, it produces a runtime exception. In clojurescript it silently errs, resulting in a "11".
The compiler correctly infers and warns of the problem, but that is of no use if your inputs change types on you. In the case of the service I'm referring to, an external service started serving up json strings for large numbers, whereas it had previously been json numbers. Since there was no exception produced, it silently corrupted data for a couple weeks before it was caught.
- didibus 8y agoWoa, you're right. I had never realized they were compiler warnings and not JS errors. Thanks for the tip.
- ajss 8y agoPeople were running a real money service that consumed JSON from another service and it didn't validate the incoming JSON? Wow.
- saosebastiao 8y agoThe problem comes from the fact that clojure and clojurescript are two different type disciplines, but people approach them with the same expectations. That exact problem would have errored out if they were running clojure, and a thrown exception is good enough validation for many developers. But because they were duped into a false safety net by thinking clojure == clojurescript, it slipped right underneath their radar.
- didibus 8y agoI asked about this here: https://clojureverse.org/t/clojurescript-is-weakly-typed/3117 https://clojureverse.org/t/clojurescript-is-weakly-typed/311... And documented to what extent types are automatically coerced. Also got the rational behind this: performance. And that every new release of the compiler performs smarter and smarter type inference and can warn about more of these cases. Though it still misses some as of now.