views:

1824

answers:

11

I've just started to learn Clojure by reading some tutorials and watching every presentation by Rich Hickey, and I'm totally impressed by the language... so different from any C-like language (actually any language I've seen so far), yet so elegant... So I started to wonder... why is everyone so thrilled by Scala but not by Clojure? Is it because Scala is more Java-like? Because of Clojure's parenthesis? Because it's functional?

Clojure's interop with Java looks very good, performance seems okay, and while the syntax is weird at the beginning, it all makes sense if you see the reasoning behind all this.

So, what are the reasons?

+22  A: 

Most people just don't like LISP. I don't think there's much else to this phenomenon than just that.

Stefan Kendall
+1: While this may sound like a stupid reason, I fear it's true. LISP was always exotic and too complicated/high-level/foreign for many. And to be honest, I gotta admit that the simplicity of the syntax is totally freaking me out sometimes.
delnan
I guess people have had half a century to like LISP. That's probably not going to change overnight. Or ever.
Tom Hawtin - tackline
@Tom: That implies that we've had half a century of people trying LISP -- when really, we've had a half century of people being frightened of its syntax, and NOT trying LISP. But your prognosis may well be right, since whichever the best language is, it's never the one that wins.
Rob Lachlan
@Rob Lachlan: That's not always true. Smalltalk didn't "win" because it had a price.
Stefan Kendall
+4  A: 

I think it's almost completely related to syntax. Java programmers are used to curly brackets. However, the majority of people coming to Clojure appear to be Java programmers, so I'm not sure this is entirely accurate. Plenty of Java developers like Clojure.

Rayne
Agree - I'm a Java developer, I now love Clojure but the LISP syntax put me off for quite a long time. It was only after a concerted effort to understand what was going on that I "got it" and realise quite how wonderful all those parentheses are.....
mikera
what parenth... ohhh there they are. forgot about those things.
Arthur Ulfeldt
Come on! There is a way deeper difference between Scala and Clojure than just syntax. The support for OOP programming is the big thing. Scala is a primarily OOP-language (with full FP support), but like Ruby it has support for mixin, a technique that makes OOP more useful. You can write imperative OOP code in Scala if you want, and if you do it feels the same as writing Java code. Clojure is not a replacement for Java in the same way, it is a completely different way of programming.
olle kullberg
That said, Scala borrows the functional syntax from the ML-languages (F# is also ML-family), Clojure borrows from/is Lisp. The difference between ML and Lisp is not only syntax, for example ML is statically typed but Lisp is not.
olle kullberg
@[olle kullberg] I don't think the OP asked for us to detail the differences between the two languages. He asked for reasons why Java programmers tend to go for Scala but not for Clojure. I feel that reason is almost directly related to Clojure's syntax. I never tried to detail the differences between the languages, rather I thought I'd answer his question instead.
Rayne
@Rayne I understand this, and I understand your view, but my opinion is the complete opposite of yours. I think it is the underlying functionality of the 2 languages that is key to what people like or do not like.
olle kullberg
@[olle kullberg] We'll have to agree to disagree. I've been a Lisper long enough to know that the number one deterrent of Java developers to Clojure is their first look at a Clojure application. The ones we get are the ones that aren't thrown off so much that they research the reason that Lisp has parentheses.
Rayne
" You can write imperative OOP code in Scala if you want, and if you do it feels the same as writing Java code. "However, Scala does cut down on the boilerplate for doing so, especially for constructors.
MJP
+21  A: 

Scala is much more like Java than Clojure. Scala's object system is at least recognizable to that of Java. The syntax is fairly similar. Integration between Java and Scala components is easier (in my opinion). Scala and Java are both statically typed.

Clojure, on the other hand, is rather different than Java. It emphasizes functions over objects. Its syntax is radically different. It's dynamically typed.

mipadi
+4  A: 

As Rich says, clojure is not for everyone or every type of problem. He wrote it to solve the kind of problems he works on. So the type of projects someone is coming from are going to play a big role in how much value they see in Clojure. If they are coming from distributed data processing for voting systems they will see more value than if they are coming from a career writing swing gui's for instance.

The syntax is a bit different and people seem to get over that if they see enough value in the language to justify the effort of learning a new syntax.

Arthur Ulfeldt
+5  A: 

EDIT - below is exactly why I shied away from Clojure so whether you like the reason or not, it is a correct answer and not deserving of downvotes (in my opinion). I would like to re-iterate the point made in the comments below:

Whilst Rich Hickey is most likely a genius and a great guy, he created Clojure because Java didn't seem a good solution for the problems he was coming across in his work - given the fact that he didn't have the background of Odersky (explained below) and given that this is exactly the reason why we have 20 gazillion Java web frameworks, I approached Clojure with the suspicion that it would die a death when Rich decided to move on to his next thing.

This one of the genuine reasons why I did not invest more time in Clojure and I believe it probably goes for others also, whether you like it or not.


Martin Odersky, the creator of scala, essentialy wrote the Generic Compiler for Java (and his language, Pizza, actually became generics-for-Java). This is an excellent pedigree and meant I could have a lot of confidence that scala would have some serious longevity! Unfairly or otherwise, it seemed like Clojure was a language created by some guy, in the same vein as the yet-another-web-framework mentality.

At the time I chose to migrate across, EDF, Twitter and other serious companies were using scala. I could be reasonably sure that Scala was a usable language within the enterprise (even with its academic roots).

Then I took a look at the Clojure syntax and... There is no way I was going to succeed persuading myself that migration would be easy, never mind my colleagues!

oxbow_lakes
Rich Hickey is not "some guy", I'd say he's actually a f***ing genius :-) and he put A LOT of work in Clojure. But I agree with the rest of your arguments :-).
Helper Method
@HelperMethod - I totally agree with you and I even pointed out that the appraisal was unfair. However, the point still stands - Rich Hickey said he created Clojure because Java didn't seem a good solution for the problems he was coming across in his work - given the fact that he didn't have the background of Odersky and given that this is exactly the reason why we have 20 gazillion Java web frameworks, I approached Clojure with the suspicion that it would die a death when Rich decided to move on to his next thing.
oxbow_lakes
Oh, and whilst I'm sure Mrs. Hickey loves and cherishes Rich, to me he **is** Some Guy! There are plenty of geniuses and visionaries out there and plenty of languages to look at.
oxbow_lakes
That's the worst appeal to authority I've read in a while. Odersky designed a type system (that got noticed by Sun, a "serious" company), and therefore he must be able to design a language? Rich, on the other hand, just has opinions: none of which have been noticed by Sun.Look, there are plenty of languages, tools and books I haven't given the time of day, despite their merits. There is only so many hours in a day, and I'd rather focus on making something. But, next time, when you realize an argument isn't fair, it's probably best not the spread it, and just admit you don't know.
Mike Douglas
Very superficial answer, just as dismissing any language just based on the syntax.The real appeal of Clojure has more to do to is persistent data structures, non-mutability and STM.. which may actually make it much more future-proof than most old approaches (which simply cannot handle parallel processing in a Scalable way).
inger
**The question is not about the appeal of Clojure FFS**! The question is about why Java programmers may be attracted more to Scala
oxbow_lakes
@Inger - dismissing a language based on syntax is a perfectly valid thing to do when you have a company of very experienced Java programmers with little or no Scheme knowledge. When making big decisions (like changing a language), you need to *take people with you*.
oxbow_lakes
You are right, Odersky is more of an academic. A lot of research went into scala (type system, traits ...) but Rich is pretty awesome too. He specialized in from the wight paper architecture of big complicated systems. Rich is about solving hard problems and Odersky is more about academic stuff. (I said more not only, compared to rich knot SPJ)
nickik
+4  A: 

Subjective:

History has shown that C, C++ and it spawn is very popular and since Scala is simular to C++, Java and C# the learning curve going to Scala is low or nonexistant if using only the OOP parts compared to switching to Lisp like languages.

Hovever I think Lisp like languages are very popular in certain fields such as NLP, yet there is work done in Scala in said area.

oluies
+8  A: 

Humorous:

To quote "A Brief, Incomplete, and Mostly Wrong History of Programming Languages" by JAMES IRY

1958 - John McCarthy and Paul Graham invent LISP. Due to high costs caused by a post-war depletion of the strategic parentheses reserve LISP never becomes popular1

While

1Fortunately for computer science the supply of curly braces and angle brackets remains high.

oluies
Reminds me of http://xkcd.com/297/
Helper Method
+12  A: 

Clojure is a dynamically typed, Lisp-derived language with syntactic macros. Scala is a statically-typed, type-inferred language with a bunch of advanced features in the type system. As such, the difference between them is rather stark; apart from the fact that they both support more interesting concurrency primitives in their standard library than Java does, they're really very different in approach.

I think a lot of Java programmers are more comfortable with Scala simply because, in a large number of cases, the process of converting a Java class to a Scala class involves moving the type declarations to after the variable names, and with a couple of other minor syntactic tweaks you can have a functional Scala class that compiles to nearly identical bytecode to the Java version. This means that the learning curve for adopting Scala can be essentially as shallow or as steep as you want it to be. When moving to Scala, it's likely to take you longer to convert your build infrastructure than it would to convert any given class... and if you're using Maven, all that converting your build system requires is adding a plugin to your pom.xml.

That being said, I think that there's a great need for Clojure-style syntactic macros in real-world applications in most language, because even with an advanced language like Scala there ends up being a huge amount of structural repetition. You can see evidence for this in the fact that the Scala compiler itself provides what is essentially a macro system for class generation in its "case class" and closure/function literal syntax features. The fact that such a macro system was not exposed to the end-users of the language is something that I really hope will eventually be remedied.

Kris Nuttycombe
+2  A: 

I am a professional Java developer, I don't love Scala, but I do find Clojure very interesting, let me tell you why.

My first experience of Scala was back in 2008, I took a university course on the subject. It felt syntactically quite odd, the IDE support was bad and I didn't understand functional programming at all. I still managed to finish the course work by coding Java in Scala.

9 months later I had a course on functional programming in which we used Haskell. It was a bit of an eye opener and I thought I must try Scala out again. Haskell I dismissed as being a bit too academic.

Last spring I had some extra time and I decided to give Scala a new chance. Many of the annoying niggles that I suffered from the last time around were still there. Big API changes between releases, guessing when the compiler/parser requires parenthesis or spaces, IDE support still sucked, odd syntactic constructs that forced you to think really hard what the hell is going on, and compared to something like Haskell it was very verbose. As an example of my last point I'd like to give the map function signature from Scala.

def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That

I really really tried, but I just didn't feel I was getting my money's worth. I felt, and still do, that Scala is just a better Java. Lots of neat concepts like traits, type inference etc. but the ecosystem around the language is still too fragile. This ruled it out for work usage. The fact that coding Scala didn't feel even close to as much fun as Lua or Ruby basically made it a complete dud from my perspective.

And then we have Clojure. Being a Lisp its code examples such as #(* %1 %2) makes you think it telling you to go f*** yourself. I dismissed it early on as being not a real world language, too hard, basically the same as Haskell.

This summer for some reason I decided to watch a few video presentations of Clojure by Rich Hickey. I got interested. The language still looked odd, even basic concepts seemed very difficult and confusing, but a lot of things just made sense. The strong focus on immutability was one of them, a very strong focus on Java interoperability was another. Scala is in many ways closer to Java, but does it honestly make coding Java any easier? The most vocal Scala enthusiasts want Java to go '{ :fu "ck" } itself.

I am still a total Clojure noob. Not coming from a Lisp background I find the language scary powerful. But besides finding a lot of the key concepts very sensible, I also think it is fun, something Scala just wasn't, no matter how hard I wanted it to be.

ponzao
As a newbe one should NOT look in the source. Do you look in the Java sources ? API docs http://www.scala-lang.org/docu/files/api/index.html which states eg : def map[B](f: (A) ⇒ B): List[B] : Builds a new collection by applying a function to all elements of this list.
oluies
+1 For mentioning the fun aspect.
Helper Method
Are you saying that you're afraid of an implicit parameter?
MJP
And how do you use this method? List(1,2,3).map(2 * _) Nothing scary here. And when you call the Scala ecosystem "fragile" (which was true to some extend before 2.8 came out), what is with Clojure's ecosystem? Has it even one? If you know a little bit Haskell and tried out Scala after this and found it not "scary powerful", you are doing something deeply wrong. Calling it just a better Java is like calling a Katana a better kitchen knife. I don't want to say something about Clojure, as I don't know it enough, but your reasons to dismiss Scala seem to be really weak.
Landei
@Brent I do look at language sources when I don't understand its point from the signature or when I want to know how to implement something similar. The Scala documentation actually offers both `map` signatures. At least in Java I run into situations in which I don't have the documentation, just the method signature.
ponzao
@MJP I am afraid of having to read code on daily basis that I will have a hard time to understand. Especially because I want my methods and their tests to be the documentation. I watched High Wizardy in the Land of Scala and Spiewak said something like "this code is difficult to understand, you just have to trust the magic works". Ok, that is good if that is the case always, I am willing to bet though I will run into a situation where I have to understand some deep type magic which doesn't really related to the problem I am trying to solve.
ponzao
@Landei Yep, the usage is very simple. What if I want to create my own generic function, it probably isn't that easy anymore?I read the 2.8 release notes, I was excited about the improved REPL and Eclipse plugin. The REPL kept its promise, the plugin not so much. With Clojure VIM has been enough, with Scala the code-compile-run -cycle felt very tiresome.I clearly didn't emphasize enough that Clojure forces me to think in ways I wouldn't with Java, Scala doesn't. A logical choice would be to choose Scala after Java, I feel it is not yet ready.
ponzao
+4  A: 

Martin Odersky has said that he views object-oriented and functional programming as complementary, and puts the two paradigms on roughly equal footing in Scala. However, looking at the Clojure website, I get the impression that Rich Hickey is somewhat hostile to OO and views FP as a superior replacement to it. As such, Clojure will definitely have a much steeper learning curve coming from Java, to say the least.

MJP
This is key! Scala is actually very similar to Smalltalk and Ruby in the way that OOP is fundamental to the language. Scala is in no way a functional language like Lisp or Clojure, it is simply a OOP language that fully supports functional programming (ML-style). It is a HUGE difference. Apart from this, the static typing in Scala is also a very big thing.
olle kullberg
+2  A: 

I work in a Java shop and I can tell you that my colleges would be fearful of both Clojure and Scala. Fear, because it would to their mind invalidate everything they had invested in Java. I have seen it many times when I have tried to show them these languages (I know, I'm annoying).

The FUD that they come out with shows their uncertainness.

"The syntax looks funny/hard"

"I can't refactor it with (insert ide here)"

"I could write that faster in Java"

"They are slow"

Now they may be right about some of these fears. Learning a language takes time and you will go back down to the level of a beginner for a short time. But I think it is worth it just for the benefits learning new language will give you. It shows you how to think about problems in your old language new ways.

I really think it comes down to the The Blub Paradox.

Lewis Jubb
+1 I think another important point is that programmers are afraid to invest heavily in new languages which may never popular (JavaFX, I see you ;-)).
Helper Method
they need to learn that to only reason for refactoring so often is because java sucks.
nickik