Ask HN: What is your experience with Scala?
73 points| wsieroci | 9 years ago
what is your experience with Scala language? Do you like it? Would you use it for your next project? Are you thinking of something else?
Cheers, Wiktor
73 points| wsieroci | 9 years ago
what is your experience with Scala language? Do you like it? Would you use it for your next project? Are you thinking of something else?
Cheers, Wiktor
[+] [-] allengeorge|9 years ago|reply
The unexpected side-effects and the library situation frustrates me the most: I feel like I'm always dealing with "code in progress" written by people who're enamored with the features Scala provides over building something robust and easy to understand.
Obviously, my opinion. There are plenty of people out there who love Scala.
[+] [-] kahnpro|9 years ago|reply
However I have to agree with many of the common criticisms. My last team had many WTF moments with the language. We also suffered from poor type inspection and IDE support, failed attempts at writing an SBT plugin, and slow compilation. Having access to Maven repos is great, but using Java libraries is often a frustrating experience where you end up having to write a whole wrapper library around the Java lib just to work with something idiomatic.
The language is a great stepping stone to bring hardcore Java devs into the world of FP, but honestly, if you don't need the JVM, I would rather be using Haskell.
[+] [-] merb|9 years ago|reply
I.e when you get types that can't be introspected you definitly don't work with simple scala. I've been playing around with really big projects and even made some contributions to the Playframework project: (https://github.com/playframework/playframework) and even that has barly/no types that won't work. (Oh while working on Multipart I had Java Code that didn't worked on IntelliJ 15 (works in 2016.X now)). I know there are certain libraries that are akward to work with in any ide but these libraries should be avoided. And they are mostly based on scalaz and I would even consider specs2 as harmful. But nothing applies to scalatest its imo way faster.
While you see SBT as a productivity sink you can stick to gradle or maven, both are supporting Scala. Still even the slowness of sbt (which isn't so slow it just needs to do everything twice in IntelliJ when you use it inside the console and your ide) isn't so bad for me since it's really simple to make AutoPlugins (this isn't so simple in Maven/Gradle) What error message is poor for you? I barly had issues with them. My issue's were more some stack traces but on Java the same stack traces annoyed me aswell but that was on runtime crashes.
Actually its true that some libraries are akward. But my ruling for libraries is anyway: use as few as possible. You prolly don't need a library for leftpad but that applies to all libraries I even was on the golang Ecosystem for a while predates even the 1.0 dates I even have a book for ~0.7 and there were some libraries that were pretty akward and messy, things evolved but there are still some code around which you shouldn't barly touch and even for http, you prolly don't need a library for most of your stuff and still people use them.
P.S.: Nothing against the compiler slowness but from day-to-day you barly notices only a sbt clean compile could be slow but our app (which is quite big these days only takes a few seconds). Even play! compiles fast on my machine:
Which isn't the compile time its the time the whole command i.e. clean + compile took. And I wouldn't consider that "slow". I mean slower than what? Go, of course. But its the only language that compiles so fast. Also Scala 2.12 will likely bring some improvements (soon tm).[+] [-] cheshire_cat|9 years ago|reply
[+] [-] sportanova|9 years ago|reply
[+] [-] idobai|9 years ago|reply
[deleted]
[+] [-] rvense|9 years ago|reply
The language has well-documented warts. I don't like all parts of the Play framework that we use. It's slow to compile and sometimes the error messages are weird. If you miss a close-curly brace you'll sometimes just get a completely impenetrable type error, things like that.
But honestly, all that I can live with. Case classes, sealed traits, function types, generics, monadic error handling... So much application logic can be expressed at the type level where it gets mechanically checked. The only errors that get past the compiler are in JSON parsing and database interaction. Everything else just works after it compiles. I've refactored and redone abstractions that touch all other components of the code, and I'll do it and deploy on a friday afternoon and go home without worrying. I trust the code, even after changing it. I have integrations tests that spin up the backend with a real database and send it HTTP requests, but nothing like complete test coverage. I'd like to add that out of principle, but it doesn't feel necessary.
Scala has warts. But it works well and it has static types without the verbosity of Java. I can't imagine going back to an untyped language plus tests again.
[+] [-] kev009|9 years ago|reply
If you are a one language trick, you might have a bad time, but if you have been exposed to multiple languages (like a typical CS education) it shouldn't be too hard to be productive and even fairly idiomatic code in a couple months.
Overwhelming pros:
* Type system is awesome, massive time saver once a project is underway
* Operator overloading very well done. Infix, postfix, prefix operators can allow for very readable, concise DSLs. Apache Spark being a great example but also many DB libs.
* Excellent frameworks like Playframework, Apache Spark to build on top of
* Being stacked on the JVM - you have access to tons of production worthy libs for just about anything
* ScalaJS.. really awesome if still young project to unify web development in a much more reliable way than weak JS and $backend.
Overwhelming cons:
* Compile time is quite bad
* Operator overloading can cause some really bizarre syntaxes like SBT. SBT is probably better than the mainstream Java build systems, but it's often a head scratcher.
* Being stacked on the JVM - you soon desire native Scala libs for everything
In 2016 I would also heavily consider Java 8 for the same team usage vs when I started using Scala in 2011. I think Java 8 really slowed the adoption of Scala down which may be worrisome for long term market share.
[+] [-] Roboprog|9 years ago|reply
I didn't even realize Scala had it, until a few months ago when somebody was doing a demo that involved some SBT. It was quite frightening. (Did we learn NOTHING from the C++ debacle???)
Come to think of it, I've come to dislike "operators" in general (as opposed to function calls). Memorize these operator precedence rules? No thanks, just do the inside parens first, now you're trained.
C might be a good step up from assembler (though it, and its spawn need to go away as app dev languages), but I think Lisp got this aspect (no special, jacked up, operator syntax) right, in a "less is more" kind of way.
[+] [-] Roboprog|9 years ago|reply
Curse the fool who invented "Ant", rather than figuring out how to parse a Makefile and provide a few rules or pre-set-variables to support DOS/Windows, Java compilation and such (e.g. - in a Java program to interpret a Makefile and avoid running external processes for steps that were defined as doable in the JVM). Now we have a generation raised on XML who thinks that extending a build requires creation of "Ant tasks", "Maven plugins" or similar rigor-morale.
[+] [-] dwc|9 years ago|reply
Out of curiosity, would Clojure be up for consideration? Why? Why not?
[+] [-] ryanobjc|9 years ago|reply
I think that for "programming in the large" that Scala is not going to be a winner here. I'm talking about a single code base with hundreds of engineers with a big eye towards maintainability. Because lets face it, for a 1 person small project, it doesn't matter what language you use as long as it provides single developer productivity. But once you talk about large team projects, things get very difficult. Scala only compounds this imo.
[+] [-] Maascamp|9 years ago|reply
[+] [-] saryant|9 years ago|reply
[+] [-] angryasian|9 years ago|reply
[+] [-] runT1ME|9 years ago|reply
We use it exclusively on the server side at Verizon Labs, and it's quite beloved by all. We lean hard on the functional side of things and make heavy use of what some people call 'advanced features', but because of our micro services infrastructure even the teams new to Scala can be productive in a less functional style, and refactor later to be more idiomatic.
I do think large teams need to have enough language experts to help from making some bad design decisions, but I have plenty of productive coworkers who are new to the language and learning as they go.
I really don't agree about the 'maintainability fears' or 'write only' language criticisms. 'Bad' Scala is still so much better than bad java, and good scala is phenomenal to work with. Because of the type system, I have a high level of confidence when working with unfamiliar code and making minor changes.
Smart folks with no exposure to functional programming are picking up the 'advanced' features very quickly with the right training and guidance. I would not recommend it to a team who has on one with any experience in the language, but if a team can hire those who have experience with the language, even if it's just a fraction of the overall team, I'd be confident they could succeed.
There are real downsides:
* slow compile times
* IDEs can struggle with advanced libraries (Scalaz)
* some language features are 'sharp' (implicit conversions)
* finding developers who know scala
We're overcoming the first one by the fact that we're already a microservices shop.
The IDE issue doesn't affect me, I'm on Vim, many coworkers on Sublime/Ecmacs.
If you go crazy with implicit conversions it can cause issues, but again we try to mitigate this with some training and having enough advanced users of the language/code reviews to show everyone how to relegate using conversions for syntactic sugar or typeclass conversions.
[+] [-] hocuspocus|9 years ago|reply
There's a good side to it though. I took my current job because I wanted to use Scala more and my manager admitted (after the fact, sneaky bastard :) that hiring Java+Scala developers helped him filter/attract curious and talented people.
[+] [-] photon_off|9 years ago|reply
If you want to write Scala to actually get things done, you will find that it's a miserable language to learn and that you will need to invest significant amounts of time, energy, and sanity to learn it. Furthermore, there are no shortages of Scala apologists who are so utterly enamored with the cleverness of the language that they will not concede how much of a pain in the ass it is to learn. They will claim it is easy, and then they will have no empathy for your plight. It is actually quite shameful.
The attitude in Scala-land is that you are the problem, and not Scala. When you do encounter a roadblock to a seemingly simple problem, which will be quite often, you're lucky if you find a 20 paragraph explanation on StackOverflow. Otherwise, you can hopefully find a lengthy blog post about something closely related. In either case, the attitude is that it is _not_ Scala's fault that solving problem XYZ requires you to understand several chapters of advanced concepts -- it's _your_ fault for not already knowing it.
[+] [-] idobai|9 years ago|reply
[deleted]
[+] [-] 0xfaded|9 years ago|reply
But it's difficult to master and therefore difficult to sell to others without a scala background. You're also competing with the finance industry and salaries for decent practitioners easily top 200k.
So my verdict is good for an individual contributor, bad if you need to convince others to use it.
Also, scalajs is awesome and just works, with the exception of some reflective calls. Otherwise normal scala compiles to good JavaScript, and interop is as good as coffeescript (i.e. perfect).
[+] [-] aaron-santos|9 years ago|reply
My initial impressions of Scala:
1. There is an unavoidable learning curve when onboarding. My personal experience with Clojure lowered the curve a noticeable amount. While I was tackling learning a new syntax, my team mates were struggling with syntax + functional concepts. People with exposure to functional concepts will have an easier time.
2. Our experience was made more difficult in that there were no in-house Scala experts/mentors to whom we could ask questions and get answers. Bootstrapping Scala knowledge takes some time and I admit that while I'm productive writing Scala, I know I'm not at the level where I can analyse design trade-offs, extol best practices, or use my language knowledge to pre-empt and avoid problems like I can in Java. We had a good experience with a consultant + videos + books + online articles, but it isn't the same as having a mentor colleague.
3. I write a LOT less boilerplate. Both my Java work and Scala work involve consuming and producing JSON data. In Java-land I used Jackson to annotate classes and used builders to build that as the data classes themselves were made to be immutable. It was a lot of repetitive code and mind numbing to write. Now you could argue that the code should be generated automatically, and you're not wrong. But it feels like something is broken in the language if this is the best solution.
In Scala, I find myself using case classes and spray-json and typically write two lines of code for a JSON-serializable class definition. (1 for the case class, and one for the implicit JsonFormat definition. Occasionally I have to break out RootJsonFormat and write more code, but it's short and concise and non-boilerplaty. I like writing Scala much more than Java and I'm because I like it I'm more productive.
4. Some of the libraries feel like a force multiplier. Specifically Spark, and to a lesser extent Akka let me do things I wouldn't consider trying in Java. Sure, they can be used outside of Scala, but the way they are presented in Scala is beautiful and makes the programmer feel powerful because when using them, the are.
[+] [-] edko|9 years ago|reply
[+] [-] jacobn|9 years ago|reply
We've created several in house DSLs and used them to great effect.
Compiler is slow, though it has gotten better over the years.
Very much looking forward to DOT (next gen of compiler and language, union types will be awesome).
Use it on four production websites, about to transition a Ruby on Rails site to it soon.
[+] [-] pnathan|9 years ago|reply
Disclaimer: I spent some time December 2014 over a Christmas break whacking away at a small Play app. I've not been back since due to a number of "hygiene" factors.
* I loved having type-safe templates.
* I found that object and class distinctions were weird and the multiple namespaces (iirc) didn't make a great deal of sense.
* The language felt very grab bag: things didn't seem to "fit" logically together well.
* Scala still has null.
* The tooling is slow. The tooling is fat. The tooling didn't run on my (few years old) laptop with 4Gigs of ram. More on this below.
* High-class documentation about the language is hard to find. The Java (and scala) ecosystem is filled with really ignorant people and really low-level docs.
* And implicits were stabbing me in the face because they are unusual and technical descriptions of what they are were hard to find.
* The compiler error messages are hard to scrute. This is definitely less of a problem than above. (I've used C++ templates, so after that, it's hard to complain too much).
Regarding the bloat.
I have Haskell, OCaml, Lisp, Java, Clojure, Python, Ruby, Rust, and ... others on my machine. Of these, exactly one has ever had a problem for my home machines: Rust, years ago, when self-compiling would alloc more than 3 gigs of ram - and my 3 gig machine would reap the process. Only Scala has presented the memory and speed issues I encountered. Given that its ecosystem is kind of designed to use an IDE, this is terrible.
My takeaway from building this (small) web app well over a year ago is that Scala probably works well in a team with the funding to buy hefty machines and the ability to maintain an operative knowledge of the Scala Lore. If you need the JVM, and you need advanced type systems, it's the only choice. Otherwise Java 8 is probably adequate.
Eating my own dogfood - I'm working on another well-typed smaller web app at home, and my ordered preference list from top to bottom looks something like this: [OCaml, Java 8 (9?), Rust, Haskell, Scala].
[+] [-] airless_bar|9 years ago|reply
[+] [-] mindcrash|9 years ago|reply
A great contender to Scala is starting to rise though, in the form of Clojure and ClojureScript. Clojure is starting to become pretty great for backend work and once you start using ClojureScript and topple it off with a framework such as Om or Reagent for building React based reactive UIs you will never look back.
[+] [-] edko|9 years ago|reply
I think the biggest potential competitor to Scala may be Swift, now that it is open source. If it becomes as multi-platform as Scala is, and good back-end libraries become available, then Apple's support may be very hard to compete against. There were even rumours that Google was considering using it for Android.
It is nice to see that Scala will soon be available for mobile development too. In a short time, there will be a nice overlap of platforms supported and language features, which will provide for interesting competition.
[+] [-] jcadam|9 years ago|reply
Now, I have been able to use Scala along with Akka on some smaller projects at work (usually where I'm working solo), not that I bothered asking for permission or anything :) At home, I've started using Clojure on a side project and I generally find it to be a more pleasant language to use than Scala (but Scala is still vastly superior to Java, of course). But it leans more toward FP than Scala does, so I know if Scala is a no-go at work, Clojure isn't even worth asking about :)
So, yea, if I'm ever in a position to select languages/technology stacks for a new project (hasn't happened yet) I'd definitely lean toward Clojure for a true 'greenfield' project. If I needed to integrate with an existing Java codebase, Scala might be a better choice.
[+] [-] sheepmullet|9 years ago|reply
[+] [-] mafribe|9 years ago|reply
I'd say Scala, used pragmatically (e.g. avoiding advanced stuff like Shapeless or Scalaz), is currently the best mainstream programming language, meaning it offers the best compromise between language power, maturity of implementations and library eco-system.
My main criticism has always been the slow compiler which was eyewateringly terrible in 2011. With SBT's incremental compilation and faster machines the situation has become bearable.
[+] [-] wpietri|9 years ago|reply
I liked the language for its ambition. I think the notion that OO and functional approaches are complementary worked very well for me. There were a lot of interesting ideas in the language and the ecosystem.
However, there were a number of downsides. I came across a couple of bugs that were well known and apparently people were just expected to work around them. As others have said, compile times were terrible, and the tooling wasn't great. And at a one day Scala unconference one of the prominent Scala community members was a flaming asshole to me, which definitely didn't help.
What really put me off, though, was what Bruce Eckels described: "I’ve come to view Scala as a landscape of cliffs – you can start feeling pretty comfortable with the language and think that you have a reasonable grasp of it, then suddenly fall off a cliff that makes you realize that no, you still don’t get it." http://bruceeckel.github.io/2015/08/29/what-i-do/
This was backed up for me by a talk by Paul Phillips, a major contributor to the Scala compiler: https://www.youtube.com/watch?v=4jh94gowim0
So in the end, I'm likely to look elsewhere. The next language I'm trying out is Kotlin:
https://kotlinlang.org/
It's from the IntelliJ IDEA people, who I trust a great deal, and I just got done working through their nice in-browser IDE tutorial:
http://try.kotlinlang.org/
So far it seems to have all of the things I like about Scala plus a number of improvements. E.g., fast compile times were a clear goal, and I didn't come across anything that struck me as language astronautics.
[+] [-] partisan|9 years ago|reply
I am currently giving Kotlin a shot and so far I do like it. I downloaded and installed IntelliJ, then the kotlin-dropwizard github repo and imported it into IntelliJ with no problems. It runs well and the code is clean and legible.
[+] [-] gexla|9 years ago|reply
I would think the answer to the original question would be that if you have to ask then probably it's not the right direction for you. This is especially the case if you are looking for something for your next project. You have a big learning curve before you even get started.
Start at the end and work your way backwards. What's the fastest way you can get from point A to showing off your project? Even better. What's the fastest way to get from point A to making a dollar?
Pick up something that's already on your shelf, throw up a sketch of something finished on your wall and then get to THAT as fast as possible. No project should start with "learn Scala" unless you're being paid to learn it.
[+] [-] bajsejohannes|9 years ago|reply
I'd rather stick a functional language built from ground up without the baggage. Or even straight Java. You can do pretty nice functional stuff with Java 8 streams, but it's not trying to be something it's not.
[+] [-] allengeorge|9 years ago|reply
[+] [-] airless_bar|9 years ago|reply
Which ones?
[+] [-] fishnchips|9 years ago|reply
The only reason I'm not using it is that my professional Java-related tasks tend to be small enough that pulling in an extra dependency is an overhead.
Mind you, I haven't looked at Clojure or Kotlin, both of which offer the same benefits I find attractive in Scala.
[+] [-] trengrj|9 years ago|reply
Pros:
Cons: