6 ms·
A better Java: Scala or Xtend?
- gubatron 14y agomeh, not sure what the "pain" is if you code like a god on eclipse. scala or xtend is java for pussies.
- manmal 14y agoEvery line you don't have to write is a line which can't contain bugs. Lack of semicolons makes for better readability. Pre-included functions like map() enable programmers to use best practices, allowing for even terser code. You might have noticed that as a programmer you spend about 80% of your time reading code (if you are lucky, it's your own), so let's not pretend there is no merit to code readability and shortness.
- ExpiredLink 14y ago"terser code" is not an end in itself. It is neither a sign nor a goal of well written programs.
- wonderzombie 14y agoNo, but all else being equal, code which is shorter and clearer is better than code which is longer. The latter is far more likely to contain bugs. It's the difference between composing a map/filter/reduce pipeline and writing every single loop out by hand.
- tomjen3 14y agoWhich ever has the best IDE support. Approximately nobody codes in Java, rather we code in Eclipse, Netbeans or other Java. It is great because we can still ship the Java code as it is still Java, so I kinda miss things like lambdas and closures, but most of the pain is gone and a lot of things that are still difficult in other languages, such as finding a specific method or class are really easy. But if you aren't used to program this way, it can take some adjustment.
- benburton 14y agoScala.
- halvsjur 14y agoScala, Clojure, Kotlin, Ceylon, Groovy and now Xtend. Going to be interesting to see what languages win out in what niches on the JVM.
- systems 14y agoWell, recently i started learning clojure, and i am surprised by the size of the community and ecosystem ... its big ... and active i wanted to learn either scala or clojure and decide to pick the language with tighter java libraries integration (the language that makes it easier to use java lib), and according the the reviews i read, clojure won in that area if the level of activity around clojure continues at this rate, i believe it will easily outshine the competition also dont discount jRuby, it has a nice following
- webreac 14y agoPeople on clojure forum were not very nice. I am learning scala with https://class.coursera.org/progfun-2012-001/class/index https://class.coursera.org/progfun-2012-001/class/index. Scala guys are very nice and the language is really awesome.
- jbrechtel 14y agoNothing against Clojure, but I'm curious what you read that made you think Clojure has better Java interop than Scala? Using Java code from Scala is literally the same as using Scala code from Scala. Same thing if you replace Java with Scala and Scala with Java (with the exception of some Scala constructs that aren't present in Java). This is not true of Clojure..
- systems 14y agoa bit late but this is the link where i read it http://codemonkeyism.com/clojure-scala-part-2/ http://codemonkeyism.com/clojure-scala-part-2/ looked trust worthy to me!
- Ygg2 14y agoJust to add more to that list, there is also Fantom (my choice of a better Java) and haXe which also deserves a mention, for managing to hit five or six different platforms.
- maxs 14y agoI'd like to use any of the alternative JVM languages out there.. However, as someone who already has a great deal of code in JARs, it seems like it would increase complexity for little benefit. What I am saying is that I don't like the costs of investing into a whole another ecosystem (say Scala or Clojure), with an unproven future, and a smaller market (compared to pure Java). Of course, you can call any JAR from Scala and Clojure, but it seems to me that a Scala/Clojure JARs are not equally callable from Java (or other JVM languages). You start getting into runtime JARs and the basic "impedance-mismatch" of different language abstractions. (For example, for languages with traits, what do those correspond to in Java -- interfaces, abstract classes?) Ideally, I would like to have a language that can compile a Java class that seamlessly interacts with other Java stuff. The problem is that it seems to me you don't get any of the benefits of Scala, Clojure, in that setup, because the runtime adds a lot of value. Most that you could get are nice syntax for lambdas (which are a bit verbose in Java, but not really a problem for me), but those are anyways coming in JDK 8. Have people on HN thought about this? People who use alt JVM languages, I am curious about your opinions. Honest question, I am not interested in language flamewars.
- cynicalkane 14y agoClojure has a fully optional, very grokkable and well-defined map from Clojure to Java, in the form of protocols and gen-class. Protocols are a natural part of the language, and if you need a concrete gen-class, because Clojure is functional it's easy to plug whatever Clojure functionality into a Java interface.
- sebabenz 14y agoI think this is the main advantage of Xtend. Xtend compiles to plain Java classes and uses the same typesystem as Java. This way you get excellent Java interoperability, as Xtend classes can be used seamlessly from Java and vice versa. This goes so far that I usually mix in my projects Java and Xtend code. I recently wrote a blog post about this topic, as well [1]. [1] http://sebastianbenz.de/5-Things-that-make-Xtend-a-great-Language-for-Java-developers http://sebastianbenz.de/5-Things-that-make-Xtend-a-great-Lan...
- deliminator 14y ago
- pacala 14y agoJava + lambdas
- elehack 14y agoI think it depends a lot on what you're wanting out of the language. If your primary goal is Java sans pain, then Xtend, Kotlin, or perhaps Groovy should fit reasonably well and have a gentle-ish learning curve. Both Xtend and Kotlin seem to be designed particularly for this niche, with a dash of Scala-is-too-complex mixed in to their marketing materials. If you're wanting an interesting new language that goes beyond traditional Java thought patterns, however, Scala (or Clojure) seems like a much better option. Both Scala's type system and its deep and insightful fusion of OO and functional thought make it a far more interesting language to think about and work with. IMO, YMMV, etc. of course.
- cynicalkane 14y agoScala to me feels like the C++ of Java. There's a billion language features and each time I try to learn a new one, I run into gotchas and inconveniences. I'm not convinced an average or even above-average programmer can keep all that stuff straight in his head, cognitive energy that's better spent on actual programming. For instance, what the heck is the method GenTraversableLike.++[B >: A, That](that: GenTraversableOnce[B])(implicit bf: CanBuildFrom[List[A], B, That]): That ? That is all one method definition. Famous Java-isms like Enum<E Extend Enum<E>> are tame in comparison. Things like this are the #1 reason I haven't embraced Scala, despite this constant itch I have to learn strongly typed functional programming. And who knows if they might capriciously change Scala tomorrow, like the time they decide to break binary compatibility of type signatures in compiled Scala classes, after which I spent an hour trying to figure out why the heck my IDE was reporting type errors everywhere.
- yummyfajitas 14y agoThe method ++ adds one collection to another. The specific type signature you are looking at is for the most general possible parallel collection. Obviously in that case the type signature will be complex - it needs to enable the compiler to determine the type of (Set(Superclass()).par ++ List(Subclass(), Subclass2())). In practice, type signatures written in application code rarely look like that. Don't get me wrong - Scala is complex. If you don't need the JVM, Haskell is far simpler and cleaner. But you are exaggerating the complexity of it.
- achacha 14y agoStick with Java, more job security, bigger support base, better tooling and Java is likely to go obsolete as I predict Xtend will very soon and Scala will soon after when people realize how much of a minefield that language is (I think they keep all those 'special' cases there to see if you were paying attention in class, no idea). Java for the few oddities is quite a solid language and one that will make you marketable in the industry for many years. For personal projects... pick one that has the most verbose structure because 6 months from now you won't remember why you did something and having to figure out the language and logic is a bit annoying.
- mark_l_watson 14y agoI am a polyglot programmer even though I try to concentrate on languages that I need to get stuff done. I am really enjoying Martin's Scala class https://www.coursera.org/course/progfun https://www.coursera.org/course/progfun, I use Clojure a lot on customer and my own projects, and (J)Ruby is so often my go-to language. And, I use Java a lot, but less than these other JVM languages. That said, I was having a quiet think while walking in the wilderness recently (I live in the mountains) and I asked myself the tough question: would I have accomplished more in my professional life in the last ten years if I simply always used Java? I honestly don't know the answer but I suspect that the answer is that in some absolute metric of both money earned and productive work for society, just sticking with Java would have been the better call. In the past I have had the same quiet think about just using (J)Ruby. The big win of being a polyglot programmer is reshaping one's mind to think about problems in different ways, and I don't know if it is worth it.
- kaffiene 14y agoThat's a really thought-provoking post. Thanks for that. Regarding being a polyglot programmer I think that it's important to know how to approach a problem from different angles, as you say. Knowing imperative, functional and OO approaches is in itself a useful thing. But I don't think it's just that - it's also useful to know that you could do a particular task in another language where it's idioms or libraries or performance characteristics are more appropriate. I don't use Lisp a lot these days, but I'm always grateful that I learned it, because it increased my toolkit of possible solutions. I think people that think "there's only one way to do it" sometimes produce bad solutions. But not always! I think pretty much everyone hates VBasic, but one of the people I work with created a great product in VB because that was what he knew. I wouldn't take the language-bigot approach of calling him a 'blub programmer'. Just because he used a poor language, it doesn't mean he's an idiot. tl;dr - knowing more languages increases your toolset which is good, but it doesn't in itself make you a superior programmer