News for hackers. Stuff that matters.
Re:The myth of using Scala as a better Java by itaysk on Thursday March 02, 2017 @01:38AM (#13772028)
I really wanted to love Scala, and for the first few days I did. But it was a never ending story learning this language. It is so complicated and feature rich that there's just too much to learn. I couldn't just read someone's code without stumbling on some special syntax or language feature that handles a once in a lifetime use case that I didn't know about. Eventually I gave up on Scala.
Re:The myth of using Scala as a better Java by TeMPOraL on Thursday March 02, 2017 @04:09AM (#13772728)
My impressions after a month spending working in it were somewhat similar. But it's not that there's much to learn (a necessary thing in a powerful tool) - it's that after that month, the language still felt like a totally inconsistent mix of every feature they could find in other languages (beside maybe sane macros, conditions and call/cc).

I suppose, though, that after spending enough time immersed in a language, even such inconsistency stops being a real obstacle to anything.

Re:The myth of using Scala as a better Java by mafribe on Thursday March 02, 2017 @09:13AM (#13774075)
I echo "oelang"'s request: please explain why you think scala is inconsistent.

As far as I an see Scala has achieved something no other language before did:

1. For the first time, achieves a successful marriage between ML-style functional programming and class-based object-oriented programming (OOP) with subtyping a la Java. Scala achieves this by building functional programming as a special case on top of class-based OOP. Previous attempts at unification (e.g. Ocaml) tried instead to base OOP on top of typed λ-calculus.

2. Scala even improves on ML in that it fuses the language of programs with the language of module systems and brings type-inference to both (albeit partial). It fuses the two without any real compromise on each, indeed one could argue that both were improved since ML's module system doesn't have type inference.

3. Smooth integration of higher-kinded types with OO programming.

4. Having an advanced language running on the stable and well-libraried JVM eco-system. Usually languages with as much novelty as Scala, remain in academic obscurity.

The unity of Scala is witnessed by the fact that it can all be compiled down to a rather simple calculus, namely "dependent object types" (DOT) [1]. I'd say that DOT is to Scala what lambda-calculus is to Haskell. I find it hard to think of another language that combines so much expressive power with being simple and coherent.

[1] T. Rompf, N. Amin, Type Soundness for Dependent Object Types (DOT), http://lampwww.epfl.ch/~amin/drafts/dot_oopsla16.pdf

Re:The myth of using Scala as a better Java by TeMPOraL on Thursday March 02, 2017 @11:59AM (#13775726)
Replying to both you and 'oelang.

I didn't say Scala was inconsistent, only that it felt as such. I've lost access to that codebase since the end of my participation in the project, so I won't provide you with code examples, but the project was using most of the language features available to date (2015). Maybe "inconsistent" is a wrong word. "Messy" would be better. I've been familiar with many of the concepts in Scala from other languages, and here it felt like they were glued together with gratuitous use of syntax and implicit type conversions.

I apologize if my previous comment didn't state it clearly enough, but I'm talking about my impressions of the language here. I'm convinced that after enough time, the whole package starts to make sense and becomes a very powerful tool in one's hands (I have a reverse situation with pre x11 C++ - it was the first programming language I really learned, so all its idiosyncrasies people like to complain about felt completely obvious and justified to me).

One day I hope to immerse myself in type theory deep enough to actually understand the underpinning of Scala better.

Re:The myth of using Scala as a better Java by mafribe on Friday March 03, 2017 @08:24AM (#13782647)
If you found C++ natural, then Scala should be even easier, because C++ is orders of magnitude more complex and messy than Scala (speaking as somebody who's comfortable with both languages and has written both professionally).
Re:The myth of using Scala as a better Java by virtualwhys on Thursday March 02, 2017 @11:25AM (#13775314)
Yeah, the problem is that the theoretical underpinnings of DOT do not represent Scala as we know it; that would be and is a different compiler (Dotty).

If Dotty works out then we will, for the first time, have a fully specified Scala on sound theoretical footing. Along for the ride: much faster compiler, better tooling, streamlined type system, and nice-to-haves like union types and implicit function types, among other useful features.

Re:The myth of using Scala as a better Java by mafribe on Friday March 03, 2017 @08:22AM (#13782633)
It's certainly true that today (3 March 2017) there is still a gap between DOT and the current Scala compiler (version 2.12.1) -- just as there is a gap between Haskell and the lazy lambda calculus. However, as a conceptual guide what Scala is, DOT is quite helpful. With time DOT will become even more helpful

In general, it's OK for there to be a gap between a real programming language, and its theoretical toy model. That's the gap between theory and practise. Why would you care about theory if it was as complex as practise? The ideal case (embodied in the lambda-calculus) is that the theory is much easier, but looses only a modest amount of precision.

Re:The myth of using Scala as a better Java by oelang on Thursday March 02, 2017 @08:04AM (#13773718)
I'm surprised that you found it to be inconsistent. Care to give some examples?
Re:The myth of using Scala as a better Java by gbersac on Thursday March 02, 2017 @08:14AM (#13773760)
I don't really understand all those complaints. I am using it professionally since 8 month and I only had problems the first two month, then I felt good, even if there is always something else to learn.

For the complexity problem, here is how I manage it : the functional programming scala is scala, everything else is garbage included for java compatibility. It works like a charm.

I can't think of a language I could feel better with.

Re:The myth of using Scala as a better Java by the_af on Thursday March 02, 2017 @08:33AM (#13773850)
Mostly agreed.

There are some pains associated with Scala, though. Sometimes self-inflicted by people who want it to be like Java: for example, most ORMs for Scala suck. A team at my office tried to use Hibernate to disastrous effects (Scala and Hibernate's hostile takeover of collections don't play well). Even some DSLs like Scalike tend to also be painful and unwieldy. I also dislike Play and its multitude of quirks and incompatible versions.

It used to also be the case that both Eclipse (ScalaIDE) and IntelliJ IDEA were almost unusable with Scala, in particular constantly resulting in spurious compilation errors. I've no idea if Eclipse got better -- completely got rid of it after decades of using it with Java -- but IntelliJ did get better and mostly works (though it still cannot always compile Scalike DSLs).

But even with all of the above, when I have to work with Java code again I cringe. Even with all the pain, Scala is simply better to work with for new code.

Re:The myth of using Scala as a better Java by cutler on Thursday March 02, 2017 @09:45AM (#13774277)
Ever asked yourself why it's taken so long for Scala IDEs to be minimally useful? The complexity of the language makes it difficult to optimise compilation and the language is still suffering. Paul Phillips left Scala because of this and he said it was impossible to rectify without re-inventing the language. This shaky complexity is why I refuse to build valuable projects with Scala.
Re:The myth of using Scala as a better Java by virtualwhys on Thursday March 02, 2017 @11:09AM (#13775130)
and yet Paul Phillips still, to this day, writes Scala. Think about that, he's one of Scala's biggest critics; still Scala all day, everyday.

There's nothing "shaky" about Scala's complexity, it's quite stable, and not going anywhere until Dotty lands circa 2020.

Despite everything (slow compiler, average tooling, implicit/operator overloaded "magic" code bases, etc.) Scala will draw library creators (like those behind Spark, Kafka, Akka, Play, etc.) which in turn draws developers, resulting in the thriving ecosystem backing the language.

Scala will live on despite itself; the ecosystem is what will carry the language to the Dotty land and beyond.

Re:The myth of using Scala as a better Java by furrydog on Thursday March 02, 2017 @11:25AM (#13775311)
True. Scala jobs growth is still very healthy too: https://www.indeed.com/jobtrends/q-scala.html
Re:The myth of using Scala as a better Java by the_af on Thursday March 02, 2017 @12:49PM (#13776307)
I don't think it was really about Scala's complexity (or it wasn't the main reason, at least), for multiple reasons:

First, IntelliJ is quite decent nowadays. So it's demonstrably possible to build a decent IDE for Scala.

Second, Eclipse itself has imploded in my opinion. Eclipse used to be a usable and reasonably fast IDE. Then, some years ago, there was noticeable increase in bloat and a downgraded performance for Java. I remember reading some major release of Eclipse, which required a refactor of its UI, didn't have any automated tests because the refactor broke them and there was a lack of volunteers willing to fix the tests. Nowadays I've stopped using Eclipse even for Java, because I cannot stand its slowness and random freezing/crashes.

Re:The myth of using Scala as a better Java by SatvikBeri on Thursday March 02, 2017 @11:58AM (#13775718)
Yeah, developing in Scala is great. My whole team (including me) had never used Scala before, we set up a weekly study group, had no problems becoming productive in the language in a few weeks.

I understand that not everyone has this experience, and would love to see more/better tutorials for Scala come out, but I've definitely seen several people pick it up without any problems.

Re:The myth of using Scala as a better Java by mcguire on Thursday March 02, 2017 @11:06AM (#13775094)
Last time I liked at Scala, it's ecosystem seemed to be a large number of embedded DSLs that didn't play well with each other. Has that changed?
Re:The myth of using Scala as a better Java by hnbroseph on Thursday March 02, 2017 @10:57AM (#13774988)
it's always good to pat ourselves on the back!
Re:The myth of using Scala as a better Java by rusk on Thursday March 02, 2017 @05:38AM (#13773087)
To me this seems like much the same malady that C++ suffers from. Is it something that established best practice could be brought to bear on? Scott Meyers' Effective C++ seems to be the bible on this topic for that language, I wonder would something similar for Scala help things a bit?

I guess in Java we are spoiled - though sometimes stifling, the rigid structure and syntax help prevent people doing "bad things". It has struck me once or twice these restrictions may have been derived in part from established C++ best practices ...

Re:The myth of using Scala as a better Java by JPLeRouzic on Thursday March 02, 2017 @06:10AM (#13773243)
More than 10 years ago I was asked to provide some insights about Java and Python for internal use in our lab. Despite IBM involvement in Java at that time, both Java and Python were see as possibibly immature by my boss. My own conclusion was exactly what you wrote. In fact during the Internet bubble there was a recruiting crisis, and Java (Python was not mature enough at that time) was exactly what was needed: A language for undergraduate people that produces good results, was easy to read and maintain, while forbiding "innovative" but often buggy code.
Re:The myth of using Scala as a better Java by rusk on Thursday March 02, 2017 @06:20AM (#13773291)
And these days its also about the tools that a strongly typed well structured language enables. I can refactor many things in IntelliJ in a trice. I've heard Bjarne Stroustroup bemoan the fact that the C++ community "can't have nice things" like this because so much of the community still holds on to legacy kludgy practices like cpp macros.
Re:The myth of using Scala as a better Java by mcguire on Thursday March 02, 2017 @11:11AM (#13775148)
The problem with C++ best practices is that they change with every version of the language. I suspect that Scala may be the same.
Re:The myth of using Scala as a better Java by grzm on Thursday March 02, 2017 @12:58PM (#13776414)
Not knowing C++, what are the types of changes in practices? Which are the most burdensome? I can imagine some accompanying changes in the language (as often best practices are there to cover infelicities in the language that are corrected in future versions). Are these of a scale that require large rewrites? Like, past best practices are now actual flaws (as opposed to just not the peak optimizations)?
Re:The myth of using Scala as a better Java by mcguire on Thursday March 02, 2017 @08:35PM (#13780078)
I first used C++ around 1990, when it didn't have much of a standard library. Then came the Annotated Reference Manual with its crazy talk of templates and namespaces and what not, which weren't implemented by any compiler I had. Somewhere around here is a copy of PJ Plauger's book on the standard library that doesn't mention templates at all. The standards committee pulled a fast one on Plauger: between the publication of his book and the finalization of the draft, the STL took over the world. Then came C++11, with move constructors, anonymous functions, and a couple of new smart pointers (which was good). C++14 introduced type deduction. And there's Boost's smart pointers (and everything else).

Nothing requires a rewrite, but five year old code looks nothing like what people say is "best practices" now.

Re:The myth of using Scala as a better Java by lcw on Thursday March 02, 2017 @02:01AM (#13772113)
I agree it doesn't have strong opinions and every developer has a different flavor of writing it making it difficult to code review without a ton of personal opinion type comments. That said it is a fun language because of how flexible it is too. It just, at times, does not seem practical for projects that have a ton of hands on them compared to other more opinionated languages.
Re:The myth of using Scala as a better Java by jshmrsn on Thursday March 02, 2017 @03:12AM (#13772496)
As others have mentioned in top-level comments, definitely give Kotlin a try, as it is specifically designed in response to your conclusion about Scala. I've been using Kotlin full-time for over a year, and I've really enjoyed it.
Re:The myth of using Scala as a better Java by reacweb on Thursday March 02, 2017 @04:11AM (#13772734)
In 1994, when I started my carrier, the state of computer languages was bad (IMO) and I imagined that one day I would create a new language. I had many ideas. Some of these ideas appeared in java (interfaces). I was very pleased to discovered that almost all my ideas were present in scala (the single exception is a fast compiler). It seems like a perfect language. I have tried to learn it, but failed. It takes too much time (I have 3 childs and a job). I gave up. Maybe it was caused by the complex collections system needed to support immutability. I will try again to learn it when I will have more time (??? ;-))
Re:The myth of using Scala as a better Java by caoilte on Thursday March 02, 2017 @04:32AM (#13772825)
Scala collections are recognised as being unnecessarily complex and are (finally) getting some love this year.

http://www.scala-lang.org/blog/2017/02/28/collections-rework...

Re:The myth of using Scala as a better Java by tutanchamun on Thursday March 02, 2017 @04:38AM (#13772850)
What do you mean with complex collections? Did you want to write your own collection type and thus running into CanBuildFrom?
Re:The myth of using Scala as a better Java by acjohnson55 on Thursday March 02, 2017 @02:03PM (#13777115)
In my opinion, the tough part is that you need to truly understand each feature. Not just one use case.

Although, once you do, you can really get to work composing the features in interesting ways to get really useful effects. Like implicits + higher-kinded types to get ad hoc polymorphism. Or subtyping + pattern matching to achieve incredibly self-descriptive business logic. I would certainly agree that Scala appeals to people who like to be able to experiment and engage with more theoretical concepts while getting things done.

But let's not pretend that most languages don't have this issue. Programming with major Ruby and Python libraries tends to eventually require you to learn what's going on under the hood in the same way. I would argue that once you start digging under the surface, Scala is much more elegantly designed than those languages.

Go is about the only language that seems to say, "forget theory, we're simply about getting things done". Not my thing, but I understand the appeal!

Re:The myth of using Scala as a better Java by pmarreck on Thursday March 02, 2017 @07:58AM (#13773685)
I've been to multilanguage conferences and every time someone throws a slide up with Scala code on it, I look around me and every damn developer has this sourpuss look on their face. (Almost like when anyone brings up Node in casual conversation, but I digress...)

Guys... if only experienced Scala people enjoy reading Scala code, then you kinda have an adoption problem

Re:The myth of using Scala as a better Java by the_af on Thursday March 02, 2017 @08:26AM (#13773825)
Um, Scala "in the small" (for example, in a slide at a conference) is never a problem. It's 100% guaranteed to look cleaner than the equivalent Java snippet, with less boilerplate. I suspect it's snobbery if people get that look in conferences.

Of course, Scala frameworks and its use in large systems might be different things -- though, having used Scala for my day job, I'd also disagree with that.

Re:The myth of using Scala as a better Java by pmarreck on Thursday March 02, 2017 @09:56AM (#13774383)
Fair enough. And to be honest I have not worked with it, and am probably biased by the conventions used in most other popular languages which do not carry over to Scala. It does seem like a disorganized kitchen-sink of ideas, though. And any time you allow mutability in any form (which would pretty much implicate any JVM language), you introduce the possibility of mutation bugs (one of the reasons I went over to functional langs to begin with... I once spent a month tracking down an irreproducible intermittent logout bug which ended up being based on a mutation bug).
Re:The myth of using Scala as a better Java by spiderjerusalem on Thursday March 02, 2017 @01:05PM (#13776508)
> And any time you allow mutability in any form ...

Odersky often says that the mutability should be as 'contained' as possible in what is otherwise a largely immutable codebase. If you can reason cleanly about a black box and are sure that the mutable variables within are not going to 'escape', you get the benefits of both

1. easier to implement, imperative algos which have been around for decades. (the alternative in pure FP is to convert stuff to tail recursion, which is not always the easiest thing to do, let's just say.)

2. easier reasoning about state not leaking to the rest of the system.

I've found following these guidelines to be very helpful.

Re:The myth of using Scala as a better Java by pmarreck on Thursday March 02, 2017 @03:00PM (#13777657)
> Odersky often says that the mutability should be as 'contained' as possible

He's 100% correct (at minimum).

> the alternative in pure FP is to convert stuff to tail recursion

It's a challenge but not THAT difficult, once you get the hang of it. :) I've found conversions fun, actually. Especially when you (of course) have to learn how to trigger TCO. The irony here of course is that at the machine language level, the recursion is converted back to imperative via TCO. But IMHO the resulting recursively functional TCO code is, eh, "more beautiful"

Re:The myth of using Scala as a better Java by the_af on Thursday March 02, 2017 @12:51PM (#13776332)
Agreed about the kitchen-sink of ideas. Also agreed about the mess of mutability and compatibility with JVM. But that's hardly something you'd notice looking at a slide in a conference :)

I also prefer cleaner languages. But, in practice, I must choose between Java and Scala, and I'd choose the latter any day, with my eyes closed!

Re:The myth of using Scala as a better Java by pmarreck on Thursday March 02, 2017 @02:45PM (#13777529)
If those are your choices, then your choice makes absolutely the most sense!
Re:The myth of using Scala as a better Java by gozur88 on Thursday March 02, 2017 @02:43AM (#13772348)
That was exactly my experience. Great hobby language. Not what I want to use on a professional team with a mix of capabilities.