Hacker News new | ask | show | jobs
by lkrubner 4539 days ago
About this:

"until you get some optional typing"

There is work being done on an optional type system:

https://github.com/clojure/core.typed

There are also some interesting experiments in enforcing specific data structures:

https://github.com/prismatic/schema

Much effort has been made to make contract programming easy in Clojure:

https://github.com/clojure/core.contracts

And if you would feel the urge to respond with something like "why is such important functionality in a library", I'll point out enforcing pre and post conditions (on a function) has a nice syntax that is part of the language:

http://blog.fogus.me/2009/12/21/clojures-pre-and-post/

I find that every time I read an article about Scala I am left wondering "Why don't these people just use Clojure?"

2 comments

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.

> 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)

This is why I'm really happy with the Clojure community. People in Clojure get that types are useful and important. You don't have the "I don't understand that, so I'm going to call it unimportant" attitude. Instead, you have people using Clojure as a lens to explore and, one hopes, solve the problem-- even when it seems so difficult as to be almost infeasible (such as static typing on a Lisp).

Clojure is a dynamically typed, JVM language-- now. (However, ClojureScript is also pretty far along.) It might not always be that way. It will evolve according to the needs of computer science over the next 20+ years.

> even when it seems so difficult as to be almost infeasible

That is quite fun. Lisp had experiments with static types for a long long time. Look at things like Qi and there history.