7 ms·
Horses for courses: choosing Scala or Clojure
- moomin 13y agoFor those of you who don't know of Robert, he works for Guardian, writes a lot of Scala and is one of founders of the London Clojure group. Indeed, he's talking about Riemann on Tuesday @ SkillsMatter.
- moomin 13y agoWhilst I understand that you can have good reasons for want to integrate to the libraries he mentions, I can't help feeling that Hibernate is a library that solves a problem caused by the type system, so just using a dynamic language and forgetting Hibernate strikes me as a good approach. Indeed, all the libraries listed look avoidable.
- playing_colours 13y agoRight, you should have reason to use all these JPA, Hibernate, EJB in Scala, in most cases you can just go with Scala's modern alternatives (Play, Slick etc.) and build robust apps. Dynamic languages aren't often a pill for everything, especially with larger codebase and when performance is considered.
- lmm 13y agoHibernate is limited by the language it finds itself in. Enhance it with a few macros and you get something truly wonderful - type-safe handling of data from outside your application. (as for spring, I'm working on a type-level alternative as we speak)
- pjmlp 13y ago> Indeed, all the libraries listed look avoidable. Not on an enterprise context, like it or not, most consulting projects on the enterprise world require interaction with them.
- gngeal 13y agoIs that the IT equivalent of legally requiring a man with a red flag to run sixty yards ahead of the car?
- luu 13y agoIf you are going to work with concurrency ... I think you definitely want to be using Clojure. Is it widely accepted that Clojure is better for concurrency? [1] I haven't used Clojure much, so I can't comment on their relative merits. But, I've played with actors in Scala some, and done a bit with STM, and they make concurrency relatively straightforward. It's plausible that Clojure has a better concurrency story (and this blog post has inspired me to try it out) but, concurrency is easy enough in Scala that I don't think of it as a weakness of the language, the way I would with something like C. [1] This is not a rhetorical question.
- Skinney 13y agoClojure uses STM and has persistant datastructures by default. This makes it pretty safe when it comes to concurrency. Clojure also has good support for paralellism through pmap and reducers. Making something run in paralell is often just changing the name of a function or importing a diffrent namespace. I don't know Scala that well, but actors in scala still shares state, and doesn't give the same level of protection when it comes to changing state. Actors also introduce some overhead in case you just want to read a single variable from a datastructure safely. You have to send a command and receive a message, wheras in clojure you just retrieve the value you want. Actors however are, to my knowledge, easier to scale across machines as actors doesn't necessarily have to be in the same process, or even on the same machine.
- dkhenry 13y agoOver the years Scala has adopted some of the concurrency primitives from clojure, now I think if you compare the two there isn't much of a difference between them, however when you start to add in third party libraries I think Scala is actually pulling ahead of clojure. With Akka not only does it do single node concurrency well it also does multinode concurrency with two or three extra lines of code.
- Skinney 13y agoWell, when you add in third-party libraries, Clojure can use these too. I wasn't aware Scala had incorporated Clojuires STM, I thought Scala was married to Actors/Akka?
- zerr 13y agoWhen it comes to more or less large and real world systems - I really can't imagine how one can work with dynamically typed languages.
- Skinney 13y agoWhy? Static languages ensure type safety (which are uncovered in unit tests anyway) and to ensure this type safety, they need more information from you, the developer. Clojure allows you to write less code which, depending on who you talk to, equals faster development time. Static languages are also usually faster, so I guess the tradeoff stands between raw performance and code size. There are numerous succesfull projects using dynamic languages. Github, as far as I know, uses Ruby.
- happy_dino 13y ago> Static languages ensure type safety (which are uncovered in unit tests anyway) Wrong. > ... and to ensure this type safety, they need more information from you, the developer. Wrong. Anyway, correlation != causation. If I would claim that there are some projects which are successful, despite being untyped, I could pretty much use the same data points to make my claim.
- Skinney 13y ago> Wrong. What? Static languages doesn't ensure type safety? Or errors due to wrong use of types doesn't get uncovered in unit tests? Unit tests runs the code, so when it runs code where wrong types or names are a problem, the code will fail, thus uncovered... Doesn't help for code you don't have tests for though, which instead require manual testing. The type system does need more information from the user to allow the same kind of flexibility in a type safe environment. Polymorphism either through interfaces or class inheritance is basically a way to tell the compiler that "Hey, i know these objects look different, but they do support the function/method I'm calling, so relax ok?". When someone says they don't understand the use of dynamically typed languages in a real world setting, it makes sense to mention that a company like GitHub mainly uses a dynamically typed language in their product. Heck, even Facebook uses a dynamically typed language quite extensively in PHP. Yes, you could make the argument that alot of successfull projects use statically typed languages, and naturally they do. The point is that dynamically typed languages work just fine in a real world setting.
- talloaktrees 13y agowhat is meant by "multi-core concurrency"? Isn't that just paralellism?
- mhaymo 13y agoYes. I guess he was distinguishing from multi-machine concurrency i.e. distributed systems, which are a different matter and one which both languages have tools for, but the author chose not to address.
- Skinney 13y agoParalellism is about using multiple cores to speed up a certain operation. Cuncurrency is about doing many things at once. Multi-core concurrency means that your concurrent operations can happen at the same time and thus corrupt shared state.
- gngeal 13y agoI think the notion of operation serializability is important in this context. From what I understand, in the broadest possible strokes, "concurrency" means "it doesn't matter in what order the sequence of operations happens and how their execution is reshuffled as long as the dependency invariants are maintained".
- happy_dino 13y agoI'm no Clojure expert, but listening to the Scala parts was like “Ok, I might disagree, but one can claim that ... WOW, that's factually wrong ... nod ... this is pretty misleading the way it is described ... ok, this sounds reasonable ... no, that's just wrong”. Can a Clojure expert comment on whether the Clojure part is as wrong/inaccurate as the Scala part?
- Uchikoma 13y agoI like compile time / IDE type checking, so I'm a Scala user. But Rich Hickey is such an amazing guy, steering Clojure, with pragmatic solutions catering to developers while Scala often feels like an exercise in academic language development.
- seanmcdirmid 13y agoAs long as you are hero worshiping, Martin Odersky is an amazing guy also who is quite focused on pragmatic Scala. Ya, scala has lots of features and it does attract more academics, but there is nothing really flimsy ivory tower about it.
- vorg 13y agoIt's important for a programming language to have a technical person leading it. If the language development is managed by a business person without any academic IT background, you end up with smoke and mirrors.
- Uchikoma 13y agoAfter 5yrs of Scala usage, I'm sorry to disagree. Martin might be a very clever guy, but Scala is not catered towards developers but language enthusiasts. From my personal point of view, and everyone else might disagree, it's very slow to compile, has complicated error messages, the API is implemented to be powerful not towards easiness of use etc.
- happy_dino 13y agoI'd love to see a code example!
- seanmcdirmid 13y agoI know Martin, I worked for him 5 years ago. He is like a "hacker's hacker" who deeply understands "programming." Perhaps this doesn't translate very well into "developing," and Scala is a great language for "programmers." We can argue about the trade offs he made, I think Scala represents a reasonable point in the language design space: its not for everyone, but a lot of people like it a lot; it is probably more popular than Clojure (though LISP'ers tend to be more vocal in general). It is definitely not a programming language for language enthusiasts, who tend to be more picky than programmers and developers and usually have their personal esoteric favorites.
- jamii 13y agoI didn't find that comparison very useful/accurate (having used clojure heavily for a year or two and scala full-time for the past month). The main differences I find are: When evaluating language tradeoffs the scala community values power more and the clojure community values simplicity more. Scala wants to provide you with the most powerful language possible. Clojure wants to make it easy for you to mold your own language. Scala language tooling works at compile-time and analyses the language statically. Clojure language tooling connects to a running environment and uses introspection. Scala has much better static checking and clojure has much better introspection. While both languages have a repl, the clojure community puts much more emphasis on live, interactive programming. Clojures syntactic extension mechanisms are much simpler, being based on sexps. Scalas are powerful (eg can access the lexical environment) but much more heavy-weight. Clojure has run-time eval. This makes it possible to do eg domain-specific jit (eg compiling DSLs -> clojure code -> java bytecode on the fly). Scala has a run-time interpreter which I haven't used but is reputed to be slow. I haven't yet explored non-jvm backends for scala but I suspect that clojure will eventually dominate on that front for two reasons: 1) when clojure-in-clojure is finished porting clojure to a new platform will be far easier than scala and 2) clojure was designed from the beginning to be a parasitic language and delegates many features to the underlying platform. Scala breaks backwards compatibility much more often than clojure. Whether this is a pro or con is up for debate. There are lots of small niggling things in clojure I would like to change but on the other hand maintaining scala code across compiler updates is a pain in the ass. Personally, I believe that the number one problem a language needs to address is managing complexity. The clojure community largely seems to get that and is driving for simple, orthogonal language features and libraries to an extent that I've not seen in any other community (eg http://blog.getprismatic.com/blog/2012/10/1/prismatics-graph-at-strange-loop.html http://blog.getprismatic.com/blog/2012/10/1/prismatics-graph...). In addition, the most exciting research I've seen on that front (eg http://www.vpri.org/pdf/tr2011004_steps11.pdf http://www.vpri.org/pdf/tr2011004_steps11.pdf http://boom.cs.berkeley.edu/ http://boom.cs.berkeley.edu/ ) and most of my favorite tools rely on powerful introspection and runtime code generation. I think Yegge describes this better than I can - http://steve-yegge.blogspot.co.uk/2007/01/pinocchio-problem.html http://steve-yegge.blogspot.co.uk/2007/01/pinocchio-problem....
- Uchikoma 13y ago
- jcromartie 13y agoI think the major error in this piece is assuming that Clojure is really geared towards any one type of problem. Instead, Clojure is designed to give you a set of tools that you can freely combine for the problem at hand. It achieves this by separating concepts that are commingled in other languages, like identity, value, and type. By splitting out those concepts, you get a very solid foundation on which you can build pretty much any other paradigm.