3 ms·
If you have to use java arrays, collections, methods and type hinting everywhere while also dismissing/avoiding more than half of the language to meet performan
by ithrow 6y ago
If you have to use java arrays, collections, methods and type hinting everywhere while also dismissing/avoiding more than half of the language to meet performance requirements (which is needed regularly in Clojure cause it's so slow), why not just write the thing in Java? Even Javascript will be much faster and your code won't get ugly that fast as in Clojure when you need performance.
- mumblemumble 6y agoI imagine it's like any high(er) level language. You start by writing high-level, idiomatic code, because that's the cheapest to write. If that isn't giving you the performance you need, then you take steps to incrementally improve the performance without making any radical changes. If that still doesn't get the performance where you need it to be, or you find that you really are having to put the code through a mangler to get there, then, and only then, do you pay the cost of rewriting those components in a lower-level language. IOW, don't take this list as a list of things that you should always do all the time. Take it as a list of specific things to help with solving specific problems, when you have those problems.
- agumonkey 6y agoIt's a very common thing actually. inline asm in C (you could argue just don't write C after all). Native modules in whatever slow dynamic language used in the mainstream. I suppose the main value of the language is still too important to not use it, and only brings a different idiom on the small and hot spot where it's clearly an unavoidable move to win big.
- vemv 6y ago> (which is needed regularly in Clojure cause it's so slow) Clojure is not "so" slow - it's built expertly on top of the world's most advanced virtual machine. Languages like PHP, Ruby, Python tend to lack a default VM that features GC or multithreading of such caliber.
- tombert 6y agoBecause a majority of the time, the idiomatic Clojure will be fast enough. I wouldn't consider Clojure to be a "slow" language, most of the time it'll perform pretty well, and has really great utilities for doing multithreaded code (which can also increase performance). By using Java, you sacrifice a lot of the cool lispey features that you get with Clojure, and as long as it's possible to optimize Clojure in the parts that need to be optimized, then I think the language is worth it; depending on the context, you might even be able to write a macro to do these optimizations automatically while keeping the code somewhat idiomatic (though of course one needs to be careful with macros).