Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala advantages after Java having closures [closed]

Tags:

With closures being added to Java, what is Scala's advantage over Java as a language choice?

Can someone elaborate on any advantages?

like image 313
chen Avatar asked Oct 02 '10 07:10

chen


2 Answers

Apart from closures (which Java doesn't appear all that close to having), here's a list of features in Scala that are missing from Java. I'll omit libraries here and concentrate on the features of the language itself. This is not comprehensive by any means, but I think it contains the big ticket items.

  • Implicit parameters / conversions
  • Pattern matching, case classes
  • Type inferencing (some)
  • Higher-kinded types (abstraction over type constructors)
  • Monadic for comprehensions
  • Variance annotations
  • Interfaces with behavior (traits)
  • Default and named arguments
  • Unified methods and operators (methods can be used as infix operators, operators can be overloaded because they're just methods)
  • Unified type hierarchy; no primitive types
  • Properties rather than getters and setters
  • Abstract values
  • First-class immutable references (vals are as easy to declare as vars)
  • By-name (lazy) terms (maybe Java closures would make this reasonably easy to express)
  • Some tail-call recursion optimization
  • Abstract types
  • Type aliasing
  • Self types
  • Path-dependent types
  • Structural types
  • Type ascription, as distinguished from type casting
  • Renaming imports
  • First-class modules (objects)
  • First-class packages
  • Reified generics (manifests)
  • Delimited continuations

Some cool secondary constructs that these building blocks enable:

  • Type classes (via implicit parameters and higher-kinded types)
  • The "Pimp My Library" pattern (via implicit conversions)
  • Internal DSLs (via operator overloading and infix methods)
  • Parser combinators (enabled by higher-order functions and made pretty by infix methods)
  • Generators, coroutines, custom control structures (via delimited continuations)
  • Type-level programming (via higher-kinded and abstract types)
  • Obsolescence of dependency injection frameworks (via the Cake Pattern)

Lastly, I'll mention that Scala has a REPL (read-evaluate-print-loop)--not really a feature of the language itself, but it's very nice to have!

like image 51
24 revs, 3 users 89% Avatar answered Oct 11 '22 23:10

24 revs, 3 users 89%


Even if Java 7 [8,..] will have first-class functions one day, it still lacks for implicits, type inference, powerful Collections library, pattern matching, traits and lots of other things boosting productivity. Not talking about various Actor libraries, rich capabilities of building DSLs,...

like image 21
Vasil Remeniuk Avatar answered Oct 12 '22 00:10

Vasil Remeniuk