Hacker News new | ask | show | jobs
by kasey_junk 4533 days ago
Having made the choice between Clojure and Scala many times, always in favor of Scala, here are the 3 main reasons I keep going back to Scala (even though I don't particularly like it):

1. I like type systems. I want strong typing, I'd prefer stronger typing in Scala (ie purity constraints as type information etc). I don't want optional typing (if I need dynamic interop, I can make a case for opt-out typing, but I've never needed).

2. Performance. I spend a lot of time dealing with performance issues, specifically latency & throughput. I often have to back off of idiomatic Scala to achieve these goals (especially when it comes to GC pressure). Scala makes that easy & painless. Clojure doesn't.

3. Style (purely subjective). I don't like LISP style languages. My very first experience in programming is in Scheme, so it's not that, I just don't like how they look. It's fine for other folks to like them, different strokes and all that, but I don't like it.

There are a ton of things I don't like about Scala, but for me and my projects, right now, if I'm targeting the JVM it is the best choice and Clojure isn't even second.

2 comments

> 1. I like type systems.

I believe with schema you can get much of the same benefit and even more on top of that.

I think schema will still evolve and work together with core.typed (witch will also evolve) will be a awesome combo.

I generally prefer not having to right the types but putting down some automatically enforced documentation is nice once in a while.

> 2. Performance. I spend a lot of time dealing with performance issues, specifically latency & throughput.

I cant really say on this issue. But I know that the story here really changed and keeps changing. Because of macros we get library's that are where fast but feel easy and simple to use.

Some teams like prismatic, runa and relevance did some pretty performant APIs and used Clojure.

"I often have to back off of idiomatic Scala to achieve these goals (especially when it comes to GC pressure). "

Can you give an example of when you had to do this? I often wonder about the performance costs of chaining together several collection API calls.

Options are the most obvious:

def foo(opt: Option[Bar]) = opt.map(_.toString).getOrElse("")

This non-obviously creates an extra object in the Some case. As opposed to:

if(opt.isDefined) opt.toString else ""

which creates 0. Not a huge deal in this specific case (unless this is a hot call). But this sort of thing is endemic to all of the standard libraries.

Edit -- only 1 extra object, but it is in both the Some & None case (which is sort of the point, it is hard to know with idiomatic Scala)