TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The myth of using Scala as a better Java

298 pointsby bontoJRabout 8 years ago

39 comments

k__about 8 years ago
2009 I sucked it up too.<p>&quot;Hey Java is pretty much shit and here is this new better language called Scala, which you can use with your Java ecosystem!&quot;<p>And I was hyped!<p>But, well then I saw the actual Java ecosystem...<p>Java itself is a pretty clunky language, especially for people like me, who did scripting language programming all the time and are probably not considered Real-Developers-TM to the Java folk. So the ideas of Scala resonated with me pretty much.<p>Anyway, after trying to configure stuff like Kafka, Zookeeper and Maven and setting up a SOAP API, I saw that the problem with Java isn&#x27;t the language. Yes it&#x27;s ugly, but JavaScript is ugly too, well even Python has its ugly parts. The problem also isn&#x27;t performance, like so many C devs cry about daily. The problem seems to be that Java devs like to create things more complex than they need to be. Conglomerates of XML files, layers on layers on layers... I just don&#x27;t know anymore.<p>I didn&#x27;t use Scala for long and it wasn&#x27;t because it failed me, it did, it brought its own complexity with implicit conversions and overloaded operators etc. but that wasn&#x27;t the reason, it was the ecosystem which usage Scala enabled, the ecosystem that felt like it was still stuck in pre 2000. :\
评论 #13774844 未加载
评论 #13773739 未加载
评论 #13773706 未加载
评论 #13773940 未加载
评论 #13774668 未加载
评论 #13776468 未加载
评论 #13773712 未加载
评论 #13776988 未加载
评论 #13774705 未加载
评论 #13774981 未加载
评论 #13774272 未加载
评论 #13773970 未加载
评论 #13774003 未加载
评论 #13774706 未加载
laichzeit0about 8 years ago
After doing this shit professionally for more years than I could care for anymore, when I see programming language or framework comparisons I immediately think of something like[1]:<p>&quot;Why Klein Cushion Grip screwdrivers are better than Wera Kraftform screwdrivers&quot;, or in this case &quot;The myth of using Kraftform as a better screwdriver&quot;.<p>And then I imagine myself going back to using my shitty old Phillips screwdriver set to screw in a few screws in a non-optimal fashion and someone might say &quot;Wow, thanks for hanging my door!&quot; and I imagine the surprise on my face as I realize that people want functioning doors and are not too bothered about which brand of screwdriver was used to achieve that.<p>[1] <a href="http:&#x2F;&#x2F;blog.cnccookbook.com&#x2F;2015&#x2F;08&#x2F;19&#x2F;8-brands-to-consider-for-the-worlds-best-screwdriver&#x2F;" rel="nofollow">http:&#x2F;&#x2F;blog.cnccookbook.com&#x2F;2015&#x2F;08&#x2F;19&#x2F;8-brands-to-consider-...</a>
评论 #13772390 未加载
评论 #13772692 未加载
评论 #13772179 未加载
评论 #13774120 未加载
评论 #13774059 未加载
评论 #13774594 未加载
评论 #13772753 未加载
评论 #13773035 未加载
评论 #13772254 未加载
评论 #13783057 未加载
评论 #13772555 未加载
评论 #13773864 未加载
评论 #13772894 未加载
评论 #13776713 未加载
评论 #13773055 未加载
itayskabout 8 years ago
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&#x27;s just too much to learn. I couldn&#x27;t just read someone&#x27;s code without stumbling on some special syntax or language feature that handles a once in a lifetime use case that I didn&#x27;t know about. Eventually I gave up on Scala.
评论 #13772728 未加载
评论 #13773760 未加载
评论 #13773087 未加载
评论 #13772113 未加载
评论 #13772496 未加载
评论 #13772734 未加载
评论 #13777115 未加载
评论 #13773685 未加载
评论 #13772348 未加载
scalatohaskellabout 8 years ago
Ive used Scala as both &quot;better java&quot; and as &quot;worse-haskell&quot; in two different teams. Both times it was much more pleasant than doing Java.
评论 #13771875 未加载
sandGorgonabout 8 years ago
Kotlin 1.1 + Reactor (<a href="http:&#x2F;&#x2F;projectreactor.io&#x2F;" rel="nofollow">http:&#x2F;&#x2F;projectreactor.io&#x2F;</a>) has erlang style messaging passing paradigms, world class tooling and is gradually replaceable (class-by-class) for Java.<p>It&#x27;s going to be interesting comparing the adoption curves of both these languages especially after Java 9 and most importantly Graal (<a href="http:&#x2F;&#x2F;openjdk.java.net&#x2F;projects&#x2F;graal&#x2F;" rel="nofollow">http:&#x2F;&#x2F;openjdk.java.net&#x2F;projects&#x2F;graal&#x2F;</a>) .
评论 #13773704 未加载
评论 #13773990 未加载
cdegrootabout 8 years ago
I once drank the Scala cool-aid as well. Even wrote an enthusiastic article about it [1]. Since then, my enthusiasm has been replaced by disappointment: the JVM interop is a lie, as Java libraries often are a bad fit, people won&#x27;t have time to write the extensive wrapper code needed to hide it, and as a result ugliness starts permeating your codebase - yes, bad, but that&#x27;s how teams under time pressure work; the multi-paradigm-and-widening (back in 2009, Scala was a smaller language) is one big headache - everyone has an opinion of how you should write code in Scala, so inevitably you spend a lot of time debating features you should or shouldn&#x27;t use in your teams (instead of writing code. In Elixir, we never have to debate paradigms, we write code); sbt is a sorry mess - no-one understands it and it&#x27;s slow.<p>I still think it&#x27;s a very well designed language, the choice of the JVM+Java ecosystem as the target just has bogged it down with legacy crap like everything else on that environment and the designers should start to make some choices instead of offloading that on every single development team in the world. I think that &quot;single-paradigm&quot; is one of the reason that simple languages that get shit done, like Golang and Elixir, are so successful these days.<p>Were I bound to the JVM, I&#x27;d still give it a good look (not sold on Clojure or Kotlin yet and it _is_ nicer and less frustrating than Maven+Java if you keep it simple); I&#x27;m just not married to the JVM so can freely consider other options.<p>[1] <a href="http:&#x2F;&#x2F;www.artima.com&#x2F;weblogs&#x2F;viewpost.jsp?thread=260478" rel="nofollow">http:&#x2F;&#x2F;www.artima.com&#x2F;weblogs&#x2F;viewpost.jsp?thread=260478</a>
评论 #13775077 未加载
srequeabout 8 years ago
As someone who is currently having to deal with a monolithic Java app built on spring, hibernate, aspect weaving, code drenched in null checks, and other questionable architecture choices, this article makes me want to switch to Scala, and the reasons are mainly community, not programming language.<p>I think you could do a lot of the above In Java although the code would be a little boiler-platey. But why do people care about boiler plate so much? Hasn&#x27;t GoLang shown us that boilerplate is not our greatest enemy?
评论 #13773884 未加载
评论 #13773861 未加载
partycoderabout 8 years ago
What appeals to me about Scala is that is expressive and concise. It also encourages some healthy patterns like such as making distinctions between mutable and immutable containers, using futures&#x2F;promises for asynchronous functions, using option types to prevent null pointer exceptions and many many others.<p>It influenced my programming style a lot and I try to prefer those patterns when I use other languages as well.<p>Some people like more advanced aspects of Scala, and like to flirt with category theory and hardcore functional stuff. Personally I find it hard to express myself in terms of higher order kinds, monoids, functors, semigroups and such. You can learn them but it&#x27;s a bit like switching from qwerty to dvorak... if you have to look at the keyboard each time it doesn&#x27;t make things simpler for you.
pents90about 8 years ago
Scala appeals to those who love programming languages. Java and a few other languages appeal to those who love making software, something that Scala is terrible at.
评论 #13772307 未加载
评论 #13772536 未加载
评论 #13772350 未加载
评论 #13777163 未加载
评论 #13777146 未加载
评论 #13773710 未加载
huulaabout 8 years ago
I have used Scala to build the backend of <a href="https:&#x2F;&#x2F;huu.la" rel="nofollow">https:&#x2F;&#x2F;huu.la</a> for years, which is not a small codebase anymore, I love the language itself, it&#x27;s fast, typesafe, productive, and gives access to the rich Java ecosystem. The only thing I dislike is the tooling, especially whenever I open eclipse, the fan just screams to hell and it&#x27;s still slow as a snail.
评论 #13772786 未加载
评论 #13772219 未加载
评论 #13772220 未加载
preordainedabout 8 years ago
So much Java hate in here. I understand most people think Java devs live in caves, toiling away thinking Java and XML are the only technologies in the world. Still, this Java dev has used Haskell, Prolog, Ruby, Python...etc. I have left the cave. I&#x27;ve seen the world. It&#x27;s nice, but Java still provides a ton of support and tooling to get things done. People have done bad things in the name of Java, and they have done fine work, too. Most of your practices from the bad old days of 90s to early 2000s Java are in rapid decline.<p>It&#x27;s not my favorite language (I heart Ruby), but a practical choice for many projects. Don&#x27;t kid yourself; once you leave &quot;Hello World&quot; land, and have to deal with a variety of features, platforms, technologies, you can&#x27;t hope to roll your own salvation--no matter how expressive your favorite language. And you don&#x27;t want Johnny&#x27;s 3 star github project solution, sorry. You want a battle tested beast, with the scars to show for it. That&#x27;s Java for you.
评论 #13783222 未加载
creyerabout 8 years ago
What &quot;better java&quot; means? It means I can build the same stuff but in a better way. Easier to read, to maintain, and at least with the same performance. Scala has a big plus on asynchronicity, but the article doesn&#x27;t even try to go there. Libraries like Akka, FS2, Monix, ScalaZ etc are not mentioned either. In Scala I can use everything from Java and much more, and this is why is better.<p>I&#x27;m sure by tomorrow someone with more time than I have will write an extensive article explaining in more detail why is better.
评论 #13773681 未加载
评论 #13772963 未加载
mk89about 8 years ago
Regarding json serialisation, at the time I was using scala, I found quite &quot;unusual&quot; that the play library could not deserialize a json with more than 26 fields (or something like that). I hope they fixed it in the newer versions, but still I don&#x27;t get why to rewrite all the libs from scratch, when java has good ones available.
评论 #13772495 未加载
评论 #13772461 未加载
paulddraperabout 8 years ago
I wouldn&#x27;t characterize Scala as a better Java any more than I would Python as a better C.<p>Kotlin is a better Java.<p>Groovy is a scriptable Java.<p>Scala is a &quot;worse Haskell&quot; or an &quot;extensible Swift&quot;, with close Java interoperability (that last part leading to the warts).
评论 #13773867 未加载
评论 #13781674 未加载
评论 #13778451 未加载
kuschkuabout 8 years ago
This post contains several wrong statements.<p>First, Java does support macros – you can use Annotation Processors normally (as Butterknife, Dagger, and other projects do), or you can use Annotation Processors to actually get the AST and modify it (not supported officially, but used by projects like Lombok).<p>Second, Java has no type classes – this is technically true, but not exactly. The mentioned example can also be handled with Java 8’s interfaces, as they support default methods and private or protected methods.<p>Due to that, you can define a method instead of the writes() field, and then use an interface-defined default method to handle actual serialization.<p>If combined with Annotation Processing, this allows easy, simple, compile-time generation of JSON serialization (and yes, I’ve written stuff like this before, so I know it’s actually usable, and not too complicated).
Fiahilabout 8 years ago
Yeah, Scala is not a better Java. And Scala is still a very young language. With a lot of interesting features, yes, but also a _LOT_ of backward and broken things.<p>Have you tried to serialize something to JSON ? Yes ? Which one of the _TWELVE_ libraries did you use ? Need to compile something ? You can take a coffee break. You defined a `unary_-` function ? I&#x27;m sorry you can&#x27;t search your code to locate the calls.
评论 #13773822 未加载
keypusherabout 8 years ago
Kotlin is a better Java. Scala is just something else.
jankotekabout 8 years ago
It is also about tooling and libraries. I find Scala ecosystem to be behind Java ecosystem couple of years (SBT versus Maven&#x2F;Ant&#x2F;Gradle, collection libraries...).<p>And Kotlin makes this debate irrelevant anyway.
评论 #13771990 未加载
评论 #13772408 未加载
评论 #13776860 未加载
yousryabout 8 years ago
My follow-up question would be: Is Scala still competitive to modern languages like Swift and Rust?<p>I experienced several drawback according to library quality and code-safety. There are too many small details that left me with an unpleasant feeling (I would take ScalaNLP&#x2F;Breeze for example).<p>But my central issue is the VM&#x2F;GC dependency. In times of GPU computing, native interface programming becomes a burden. The knowledge of object ownership improves code readability. I feel uncomfortable leaving object lifetime to a background process.
评论 #13772524 未加载
评论 #13772337 未加载
评论 #13772563 未加载
throwawayishabout 8 years ago
Not a myth: Kotlin is the better Java<p>Although Kotlin does have a lot of stuff that technically allows to write weird code, most of that (eg. extensions) is around for better interfacing with Java, and normally not used in pure K code.
rco8786about 8 years ago
Admittedly biased but can&#x27;t help but think this article reads like something stating that Scala is indeed a &quot;better Java&quot;.<p>Well, perhaps not &quot;a better Java&quot; but at least &quot;better than Java&quot;.
评论 #13771628 未加载
hintingonwhoiamabout 8 years ago
Though correct this author makes a key assumption I dispute. &quot;Scala as a better Java&quot; === &quot;people code in the same way in Scala &amp; Java&quot;. This assumption leads to the focus on various Libraries and accepted standards.<p>But, at least to me, &quot;Scala as a better Java&quot; === &quot;Scala with better syntax and less boiler plate but access to Java libraries if you need them&quot;.<p>Java is a brilliant language. But nothing can survive without some assumptions being voided over time. Despite that, many institutions relay on the good parts of Java (which there are many). Scala is a middle ground which has that backwards compat but with fixes to invalidated assumptions (syntax that has gotten clunky over time, lack of functional constructs)
divanvisagieabout 8 years ago
Is The Scala Evangelism Task Force back in action? I&#x27;m game.
Zigurdabout 8 years ago
There are at least two things more important than Scala being a cleaner Java:<p>1. The IDE 2. Oracle&#x27;s claims on Java IP<p>A good IDE is more important than Java being verbose, and the only way Scala will displace Java is if Oracle win suits and makes Java expensive to use.
mwcampbellabout 8 years ago
I wonder if standard practices for Kotlin will diverge from Java in the same way. I could guess either way. On the one hand, Kotlin maps between its properties and Java&#x27;s standard bean getters and setters, whereas Scala does not. On the other hand, a desire to share code between the back-end and statically optimizable JavaScript (and Android packages) will hopefully push Kotlin libraries away from reflection and toward build-time code generation (presumably based on annotation processors). Then again, the latter option is also available to plain java (see Dagger 2), if only the broader Java community would embrace it.
thepiwoabout 8 years ago
Scala quicky got my favourite language. I really like handling data using functional and imutable concepts.<p>Great libraries for db access (slick) and json handling (sparay-json) were not mentioned in the article, I wonder why slick is not even mentioned in the comments, it is really nice!<p>Using scala with these and combined with akka and futures feels like a so natural way of programming for me.
julian_1about 8 years ago
Question - can I simply drop scala into an existing java based maven build? Using something like the scala-compiler plugin <a href="https:&#x2F;&#x2F;mvnrepository.com&#x2F;artifact&#x2F;org.scala-lang&#x2F;scala-compiler&#x2F;2.12.1" rel="nofollow">https:&#x2F;&#x2F;mvnrepository.com&#x2F;artifact&#x2F;org.scala-lang&#x2F;scala-comp...</a>
评论 #13772661 未加载
inglorabout 8 years ago
&gt; With compile-time DI, you make service classes accept lower level dependencies as constructor parameters. In Scala, constructor parameters are accessible from regular methods, so most of the time, these services could be completely stateless. This approach is also advocated by several Java (and .NET) experts, but it&#x27;s by no means mainstream. Interestingly, Scala developers have an advantage over Java&#x2F;C# users, because they can significantly simplify the implementation by combining a macro-based library with lazy definitions:<p>Asking for a dependency explicitly is service location not dependency injection. Your code there does not solve anything better than a regular service locator in a constructor would. The point of DI is that it&#x27;s abstracted from the user code and the user doesn&#x27;t have to care about these `wire` calls and can test it &quot;as if dependencies were just passed regularly&quot;.
评论 #13773945 未加载
merbabout 8 years ago
<p><pre><code> Not surprisingly, this approach has become very popular in recent years and made the Play team consider promoting it as the default in the upcoming version of the framework. </code></pre> It&#x27;s not really the default. It&#x27;s just another reasonable choice without adding guice as a dependency. Even the Starter templates include guice: <a href="https:&#x2F;&#x2F;github.com&#x2F;playframework&#x2F;play-scala-starter-example&#x2F;blob&#x2F;SNAPSHOT&#x2F;build.sbt" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;playframework&#x2F;play-scala-starter-example&#x2F;...</a> Play! also does not enforce somebody to the Scala Ecosystem, it doesn&#x27;t come with many functional patterns (but they can be used with it). The overall goal of the last versions was getting a DI approach, so that the testability of an Applikation can be greatly improved and also the testability of Play itself.
mring33621about 8 years ago
I am a long time Java developer and, believe it or not, regularly write important new product features in concise, performant Java 8.<p>I have looked at Scala time and time again and am not sure what to think. It is currently a popular choice for big data munging -- I&#x27;m into Apache Flink and most Flink jobs are way easier to read when written in Scala VS. Java.<p>But I also feel like Scala requires more decisions per line of code than Java, which makes it a more demanding day-to-day language. Also, it seems to have lots of dark corners. But these are really my impressions based on limited experience, so I am likely wrong.<p>Also, my limited experience indicates that IDE support for Scala is quite behind that of Java.<p>But I am still open to it.<p>To get to my point, actually my question: Where should I look to learn quality, ideomatic Scala?<p>My preference would be to focus on small example programs that do one thing well while demonstrating the correct, native use of Scala.<p>Thank you.
评论 #13776128 未加载
misja111about 8 years ago
The very first example is about DI and advocates MacWire to do that in Scala:<p>lazy val userDao = wire[UserDao]<p>I come from Java and when I moved to Scala I wanted to use DI to mock dependencies in my unit tests. The logical choice for DI seemed to be MacWire, however it did not help me with the mocking at all.<p>In Java you have Mockito and annotations such as @InjectMocks that inject all your mocks into your SUT automagically. In Scala, regardless if I used MacWire or not, I had to override my SUT&#x27;s implementation and its dependent fields by myself, or use constructors that take all the dependencies as arguments so I could override them in my tests. Luckily this is much easier in Scala than in Java, but to me MacWire was a disappointment.
评论 #13772843 未加载
评论 #13772797 未加载
cygnedabout 8 years ago
Even though Scala might not be the answer, I still think we need a replacement for Java.<p>All the Java enterprise projects I know suffer from the same problems; incredible complex project structures, a lot of &quot;dead code&quot; (e.g. empty Java interfaces), XML, money being burned for engineers fighting with Tomcat or Glassfish, slow database operations because of an ORM centric development and so on.<p>I am not sure, what&#x27;s going to be the solution but from my perspective Java as a language needs to be replaced.
评论 #13772780 未加载
评论 #13774118 未加载
评论 #13773267 未加载
mcguireabout 8 years ago
&quot;<i>With compile-time DI, you make service classes accept lower level dependencies as constructor parameters. In Scala, constructor parameters are accessible from regular methods, so most of the time, these services could be completely stateless.</i>&quot;<p>Um...the constructor parameters become invisible instance variables. It&#x27;s not stateless.
edemabout 8 years ago
You might want to try Kotlin which is basically just a Turbo Java without the baroque fluff Scala brings to the table.
PaulHouleabout 8 years ago
It&#x27;s not a better Java, it&#x27;s a worse Java.<p>I like the late-time binding in Spring, it is a very complete answer to the problem of &quot;shipping a set of binary components&quot; and &quot;configuring those components endlessly&quot;. Why is that a problem? Because your build is slow and because it&#x27;s dangerous to patch the source code every time you want to tweak the configuration, ...<p>Trouble is: a lot of folks &quot;learn&quot; Spring working on a project somebody else started by cutting and pasting and searching for answers on Google and Stackoverflow.<p>You can learn some things that way, you cannot learn Spring that way. If you read the manual a few times straight through you realize that it makes a lot of sense.
fulafelabout 8 years ago
Did anyone switch to Clojure from Scala? Sounds like an attractive choice given the complaints.
jwatteabout 8 years ago
The only data layer for Scala that matters is Spark and Data frame.
评论 #13771961 未加载
stephen123about 8 years ago
Nice examples!
balamaciabout 8 years ago
&quot;STOP STOP, It&#x27;s already dead&quot;