Slashdot Mirror


Ask Slashdot: Should I Move From Java To Scala?

"Scala is one of the JVM languages that manages to maintain a hip and professional vibe at the same time," writes long-time Slashdot reader Qbertino -- building up to a big question: One reason for this probably being that Scala was built by people who knew what they were doing. It has been around for a few years now in a mature form and I got curious about it a few years back. My question to the Slashdot community: Is getting into Scala worthwhile from a practical/industry standpoint or is it better to just stick with Java? Have you done larger, continuous multi-year, multi-man and mission-critical applications in Scala and what are your experiences?
The original submission asks two related questions. First, "Do you have to be a CS/math genius to make sense of Scala and use it correctly?" But more importantly, "Is Scala there to stay wherever it is deployed and used in real-world scenarios, or are there pitfalls and cracks showing up that would deter you from using Scala once again?" So share your experiences and answers in the comments. Would you recommend moving from Java to Scala?

26 of 245 comments (clear)

  1. Twitter and Scala by ebrandsberg · · Score: 5, Informative

    https://www.quora.com/Is-Twitter-getting-rid-of-Scala

    Quote "I can't answer that, but I did attend lately a session by Raffi Krikorian, who was VP Platform Engineering at Twitter and one of the people responsible for introducing scala at Twitter.

    He was asked about scala, and said that if he would have to choose again today, he's not sure he would go with scala.

    The argument was that scala introduces a big learning curve for new developers. Because of its complicated language features it can become hard to read. So at Twitter they are trying to not overuse the complexities of the language, so the main benefit they get from it are lambdas. Which is now basically available with Java 8. So the overhead of developer training might not be worth the benefit."

    1. Re: Twitter and Scala by 1+a+bee · · Score: 3, Insightful

      Agree. Coded in Scala. A large language -- makes C++ look tame, by comparison. Which in turn makes many 3rd party libs harder to read. Java 8 (look at Streams) offers many similar features in a smaller language that's easier to communicate. Learn Scala? Of course. But don't dive into its depths. We must all budget our time.

    2. Re:Twitter and Scala by audi100quattro · · Score: 2

      This isn't necessarily an argument against Scala, using it well will have it's challenges, but this is true for most languages. Linkedin went through the same.
      Some of the tradeoff's Twitter has had to make have changed. They moved away from Ruby, and for Ruby developers, Scala might actually have been easier to pickup than someone who has been doing Java since 1.4. You have to unlearn more OO practices to use Scala well, but you can write very rubyish or pythonic code in Scala. If I look at a project like finagle now from twitter (compared with gRPC from google), I can sort of see Krikorian's point, but finagle is still one of the best or the best RPC libraries out there if you know Scala. As far as language features, pattern matching, expressive types with inference, var/val immutability are all huge helps to write more concise programs. There are more CS-y features like tail recursion, laziness, um.. monads (any typelevel library), which can hurt or help the complexities in your program. As the Scala community has matured, developers and the language has gotten better at using/refining these features (specializations come to mind) and a few of the good and safe features have become more widespread (swift, rust, jave 8 lambdas)

      The learning curve is steep for an OO developer to use the language well, but I like what this article says about the challenges:
      https://www.infoq.com/articles...
      "As explained in this article all these features are already available in Scala. Developers who want to try them out can explore early builds of Java 8 on most platforms. Alternatively, we recommend taking a look at Scala as a way of preparing for the paradigm shifts to come."

    3. Re: Twitter and Scala by swilver · · Score: 2

      Sure, happy sewing with that sword.

      Scala is like a hammer that also can be used to saw, drill, screw and paint! But only if you're an expert and even then only very carefully or you'll cut of your foot.

    4. Re:Twitter and Scala by atrizzah · · Score: 4, Informative

      And yet, read the other answer on that same Quora page.

      I would also add that the opinion of an Engineering VP at Twitter might take into account a whole bunch of things that aren't applicable to the dev who is trying to decide whether learning a language is worthwhile to them. Those are two very different points of view, with very different considerations. I love working in Scala, but if I were building a team of probably over 100 engineers, I might think twice.

      Also keep in mind that Twitter was one of the very early adopters of Scala. They lived through growing pains in the ecosystem that newcomers to the language will never have to encounter.

      Scala has a learning curve, no doubt about it. Its design tends to emphasize features that are very general. You put in some extra effort upfront, but you get more mileage in the long run. Scala also has a very rich ecosystem of libraries that may approach the same problems with different philosophies. Some find the amount of choice paralyzing. It's a bit reminiscent of the React ecosystem. But I think I speak for many Scala fans when I say that it feels very rewarding and empowering as a programmer to work with.

      Intellectual benefits aside, I've also found it to be a language for getting things done. My small team launched a mission-critical distributed system in 6 months, with me as the only veteran Scala programmer. I give a lot of credit to the extremely robust ecosystem of libraries around Scala -- especially Lightbend's Akka and Slick. A lot of ready-made tech mapped very nicely to our problem domain, and we were off to the races. The documentation is great and there's lots of support available.

      My advice for the OP: take the Coursera course and/or give the Red Book a spin. You'll likely be challenged but also you may find it to be very intellectually stimulating.

    5. Re: Twitter and Scala by atrizzah · · Score: 2

      My impression is that Scala is good for quickly prototyping simple tasks. Leaving aside the meaningless "mission-critical" bit, it looks like you set up a simple web server that could run some jobs in the background on a cluster.

      Well, not really, since we want to know ASAP when these processes terminate. Sure, there's nothing about Scala that is uniquely capable of meeting our requirements. In fact, since Akka supports Java on an equal standing, we could have kept much of the same underlying technology. However, the actual domain logic would have been far more verbose and awkward to model in Java, in my experience.

      On the other hand, if you have a large complex software project spanning many years where you need to use a lot of third party Java libraries and where you want to avoid obscure bugs (everything clean and simple and easy to understand) then Scala is really not the best choice.

      You provide no argument for why the Scala option would have these obscure bugs the Java approach supposedly would lack. Nor why Scala would be any less capable of supporting a "large complex software project". I would assert that Scala's direct support for functional programming makes it better for writing the every - day domain code. This used to be a much more controversial proposition, but at this point, most of the people I know even in the Ruby and JS ecosystems are sold on this sort of "tactical FP" as a way of writing maintainable and resilient code.

  2. Just look at it and program in it a bit by cheesybagel · · Score: 3, Insightful

    Then figure out for yourself if you like it or not. If you're going at this from a PHB perspective just stick with Java.

  3. Re:A lot of my coworkers dont give a fuck by 110010001000 · · Score: 2

    Some people have real lives that don't revolve around work. There is nothing wrong with just working for money. If you want to care about something, contribute to Open Source. That is something which benefits us all.

  4. Rust by 110010001000 · · Score: 3, Insightful

    You should switch to Rust. No wait, Swift, er no, Ruby, er no. Don't worry about the flavor of the year language.

  5. Yes. by Just+Some+Guy · · Score: 2, Informative

    I don't have a strong opinion about Scala, but the answer to questions in the form of "should I Move from Java to _____?" is almost always "yes" (for values of _____ not including PHP, VB*, or other asininities).

    --
    Dewey, what part of this looks like authorities should be involved?
  6. Location, Location, Location by NEDHead · · Score: 5, Funny

    I don't know where Scala is, but Java sounds like a nice place to live.

    1. Re:Location, Location, Location by Stephan+Schulz · · Score: 4, Informative

      I don't know where Scala is, but Java sounds like a nice place to live.

      It's in Milan, Italy. See La Scala. Also a nive place to live.

      --

      Stephan

  7. Difficult, enjoyable, productivity, consequences by Anonymous Coward · · Score: 4, Insightful

    I have a PhD in CS and have coded in many many languages.

    Difficult: Yes, I find that is the most difficult language I've ever coded in, but I really enjoy it. The difficulty mainly has to do with the type system, the compiler, and what I call Shiny thing syndrome (STS). When first learning I found occasional surprised in assignments because I had the same types on the left and right hand side, but did not. When examining the types, one would observe a page describing it. This can cause frustration for the novice. The compiler messages and the documentation have both improved immensely in recent years, so this is not as bad a problem as it once was, but still, the documentation is not a gentle guide for the initiate to understand the language. Finally, STS. There are some aspects of the language that seemed to have been simply shoe-horned in, often syntactically. That is, there are many multiple ways to do the exact same thing and all where shoved in because they exist that way and were a shiny thing in some other language. This hurts the language in my opinion.

    Enjoyment. I find that when I am coding in Java or other languages I miss features of scala. I have grown to prefer scala over java, which I didn't initially think that I would. I find that I can write a lot of code for 30 minutes in Java or I can sit on my hands looking at the screen for 25 minutes and write for 5 minutes a beautiful piece of code that does the same thing with Scala. The code has an elegance and beauty to it. Actually I don't think I stair at the screen all that long anymore but switching to functional was initially quite the paradigm shift for this old fart.

    Consequences ( Scala is not without its issues):
    1) The difficulty of the language makes it very difficult to be productive with novice coders on your team. Don't do it.
    2) Some aspects of the language: e.g. Macros, implicit parameters, implicit types, can make for elegant code, but can also make your code look like magic that will baffle your (less than stellar) team member. Use with caution.
    3) You will think different after mastering it, that is a good thing. Nothing special about scala, you should learn new languages frequently for this reason.Scala will help you.
    4) Don't do it because it is a hot new language, don't do it because you think it will solve a problem better than another or you'll make more money, do it because you love to code and you want to explore using a new tool set. Do it for the fun. I enjoy coding in Scala much more than java, and the akka actor framework is great. But you will find many analogues to the actor framework (example go routines, rust channels etc)*, but it all addresses the difficulties of multi-threading, which are somewhat cumbersome and error prone in Java.

    *Yes I know they are different, before you pretentiously lecture me on the difference, please realize that I am comparing not contrasting here. They all have the same goal to approach simplifying life in the multi-threaded environment.

    Anyhow, my advise is pursue learning scala with vigor and wild abandon. I'd also recommend go-lang and rust, they are cool also. After you learn them then decide on the tools that you want to work professionally in. You will not be harmed by the effort.

  8. Re:Java is garbage by phantomfive · · Score: 2, Informative

    It exists because in Java, it's easy to work with a team of less-competent enterprise programmers on a multi-year project where new people are coming and going, without your codebase turning into an unworkable pile of garbage. That is the main advantage of Java. It is the COBOL of the modern age, and C# is its twin brother.

    Of course, you can work with a project like that in C (for example), and I've seen it done, but you need to have strong leadership architecting the code and making sure things stay clean. Whereas in Java, you can get by with a mediocre architect and weak oversight and still come out alright (but the C project in that situation will be an unworkable mess. That goes for Python too, and Ruby apparently, if we can judge from Twitter's failure).

    --
    "First they came for the slanderers and i said nothing."
  9. Scala is definitely worth it by iceco2 · · Score: 4, Interesting

    Scala has achieved critical mass, it has shown steady growth over the years and will likely continue. It is entirely possible it will never become as big as Java but that should not be the requirement, it is plenty big enough you can count on it.
    I have been developing large scale projects in Scala for the last 6 years and I can't imagine going back to Java now. Scala makes it easy and fun to write good correct code.
    Scala is boilerplate free, it feels a bit like your favorite scripting languages yet with compile safety a powerful type system and lot's of help from IDE.
    Obviously Scala supports Functional Programming which is essential as everything becomes multi threaded and/or distributed. Scala makes it easy to write functional code and is immutable by default, yet it isn't opinionated and you can use other paradigms when they make things easier/faster.
    It's fun to write, you don't have to be a genius to use it, though with weak members on your team you will want a strict style guide. I found using Scala is a selling point when recruiting top talent, even those who never used it. Those who have used it, especially coming from a Java background are instantly hooked.
    This was verified again in recent Stack Overflow developer surveys where Scala came out to be a very loved language, nearly everyone who tries it falls in love.
    I highly recommend

  10. Long way to go by wonkey_monkey · · Score: 4, Funny

    If you want to schlep all the way from Indonesia to Italy, sure, why not.

    --
    systemd is Roko's Basilisk.
  11. Probably yes by hibiki_r · · Score: 5, Informative

    First, background: I have been using Java at work, at least part time, since 2005. I started getting paid to write scala since 2012. I've definitely ran large, critical applications in Scala: I am running some right now.

    Scala is a far more featureful, complicated language than Java is. A lot of what it gives you is really very high quality syntactic sugar (case classes, lambdas, pattern matching), but the one thing that sets it apart is its type system.

    The trick is that nothing forces you to use Scala as if you were using Haskell instead: You can use it as a more sugary Java, using the extra type system fun sparingly. Restraint is the name of the game here, and also the reason some people have Scala horror stories: A company decides that Scala sounds great, and then hire some hotshot scalaz committer to teach everyone else how it's done. Then your codebase is full of operators that look like line noise, every class extends a base that comes straight from category theory, and half the developers say 'screw this, let's rewrite it all in Go!'

    There is value in the category theory, and using arcane libraries like cats or shapeless, but 99% of the time, you don't need to: Just like back in the 90s you had to stop people from overusing OO design patterns, or their code will end up looking like Spring, Scala shops have to remind people to do the same when it comes to higher kinded types, hlists and concepts out of category theory. You really don't need any of that to use Scala successfully. Just ending up in a world where you typically don't need either a mocking library or any dependency injection nonsense is more than enough to switch. (Curse you Rod Johnson!)

    The one thing where I would make people spend some time studying is in basics of functional programming, the very first of which is to learn to remove side effects from code, and clearly separate code that changes state from computation. Chances are you were doing some of that already in Java if you were hoping for a good unit test suite, but it's more important in Scala

    Career wise, the more is a no brainer IMO: If you write Java, you are one in a very large pool of completely generic candidates that can use Spring and Hibernate to do something super boring. In Sala, you enter a smaller pool that most of the most average Java developers will never try to enter, so, on average, the job will be more interesting, and the pay will be higher.

  12. Hip and professional by PPH · · Score: 2

    Choose one.

    --
    Have gnu, will travel.
  13. Kotlin by Moochman · · Score: 2

    Having used plenty of Java in big-ish teams over the years - and mind you, having never used any other JVM languages beyond simple tutorials or scripts - I can imagine that Scala's learning curve might present a problem. Kotlin, on the other hand (as far as I can tell from my admittedly limited experience) adopts many of the best syntax features of alternatives like Scala and Groovy while keeping things simple enough for pretty much any existing Java developer to use right away. On top of that it does not introduce any new APIs or concepts like actors to get a grip on - as such cross-compatibility with existing Java code is 100% out of the box (this was of course a big factor for the JetBrains folks who are using it to develop the future of their IDE platform). And even though Java 8 is a huge advance in terms of functional programming support, it feels like a more natural fit in Kotlin. Essentially I think Kotlin is something like "Java 2.0", or what Java could be if they were willing to throw backwards compatibility out the window. :) At the same time it's dead simple to learn in its entirety in a short period of time, as opposed to Scala's huge feature set and learning curve. Scala may be the "better" language overall, but Kotlin seems like the more practical choice, especially for teams that have no Scala experience as of yet.

  14. Only If You Plan For Your Code 2 B Incompatible by Foofoobar · · Score: 3, Informative

    With all the Scala hype, people neglect to point out that Scala is NOT compatible with Java; alot of libraries and tools have to be rewritten to work with Scala. This is why LinkedIn dumped Scala, Spring dumped its Scala adaptation and more and more companies are dumping Scala. And for all its hype on 'functional programming', you can do the EXACT same thing in Java and Groovy with 100% compatibility. In fact, every Java class converts 100% to Groovy; take any Java class and change the '.java' extension to '.groovy' and it will compile without issue. The same CANNOT BE SAID OF SCALA! This is because it is not compatible with Java and requires Java rewrites in order to be compatible.

    --
    This is my sig. There are many like it but this one is mine.
    1. Re:Only If You Plan For Your Code 2 B Incompatible by jpablo1 · · Score: 2
      This is very misleading.

      First, Scala's point is not 100% compatibility with Java. You can pretty much use any Java library from Scala but not vice versa (it can be done but you need to take special care).

      Second, Groovy being a dynamic language is in a different league than Scala (or Java for that matter).

      Third, regarding the "hype on functional programming". If you had the slightest notion of what FP is and and how different languages support this paradigm you'd know that you can do a great deal of FP with Scala. Much more than with Java / Groovy.

  15. Re:Why not code in Klingon? by audi100quattro · · Score: 2

    Wait, what? if lambdas are shit programming why did almost every language add them as a features in the last 5-10 years? including c++.

    I think you have mostly missed my point, Scala has research oriented roots, and it you're not ok with that, fine. But if it makes you a more efficient programmer, it might just be worth the effort of picking up.

    Also, this is what I mean by pattern matching:
    http://docs.scala-lang.org/tut...
    https://doc.rust-lang.org/book...
    https://developer.apple.com/li...

  16. Switching from Java to Scala by corporate+zombie · · Score: 2

    1) Do you need a degree or to dive into the math to make effective use of the language? No. Like any programming language you can just learn the patterns and apply them. That said, like any programming language, if you learn the math behind why it works you can make more effective use of the language. (You are probably using monoids, functors, monads, and maybe applicative functors in any large program. Not knowing what those are doesn't mean you aren't using them.)

    2) Would I recommend switching?

    I having been programming professionally for 31 years. I have been programming Scala since 2010. I have taught about a dozen people the language. Much like, "Should I quite my day job to put all my time into my startup?", the answer is probably, "not right now". If you can get the same or better pay, under the same or better conditions, then obviously yes, make the switch. Otherwise if the language interests you (same answer for the startup) then work on it in your spare time with your day job giving you the security you need to expand your horizons. As a programmer learning new languages will make you a better programmer. Learning languages like Scala or Haskell which lean so heavily into functional programming and their higher-kinded type systems will definitely expand your knowledge. Additionally you'll then be able to decide if a switch is worth it FOR YOU rather than relying on getting a useful answer from a infinite number of monkeys banging on an infinite number of keyboards.

    All that said no company would pay the price I would demand to code in Java again.

  17. Scala is great if you use it the right way by wgill · · Score: 2

    No question there's a learning curve, but you don't have to be a genius to learn Scala and use it effectively. Is Scala there to stay? Yes. I've used it successfully at TraceLink, Inc and CiBO Technologies, Inc and am a big fan. Scala is richer and more expressive than Java and eliminates annoyances like checked exceptions. The key is the principal of minimum power (use the smallest hammer that gets the job done) and some consistency in style across the team. If people go meta-nuts with advanced language features, the result can be spectacular failure. If you use the language right, it's wonderful and you can write some great code quickly.

  18. Re:Java is garbage by tigersha · · Score: 2

    I agree. Most of the higher-levels language we use today are usable because the computers and implementation technology got fast enough make them practical. A lot of compiler tech, especially in run-time code optimisation and JIT and VM's, came out of years of experience with Java. Al the higher-order abstractions such as Lambdas, Continuations, Closures and such stuff was known in 1960s and 70s, but the implementation tech was just not up to it. In the end, programmer productivity is what counts, it is cheaper to throw silicon at the problem.

    By modern standard the language is a bit archaic, but so in Pascal, and, for that matter, C. But Java was a very important milestone in the process that got us where we are now.

    --
    The dangers of excessive individualism are nothing compared to the oppressiveness of excessive collectivism
  19. Re: Maybe Kotlin by cmorriss · · Score: 3, Informative

    It's quite stable at this point. JetBrains has released version 1.1 and anything written in 1.0 will work long term. We're using it in production and have had zero issues. I honestly don't see how someone could pick Scala over Kotlin if they've actually looked at Kotlin seriously. This biggest win is that it's syntax is close enough to Java that a new team member can read it and understand the code without even having worked in it at all.

    --
    10 minutes working on a sig. What a waste.