This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Re: Re: Is Scala the Next C++

2 replies
Cédric Beust ♔
Joined: 2011-06-17,
User offline. Last seen 42 years 45 weeks ago.
On Thu, Sep 8, 2011 at 5:10 PM, Kevin Wright <kev [dot] lee [dot] wright [at] gmail [dot] com> wrote:
By any *objective* measurement of simplicity, Scala is definitely simpler than Java.

Can you think of any feature that Java has and Scala doesn't?
How about the reverse?
-- Cédric
Kevin Wright 2
Joined: 2010-05-30,
User offline. Last seen 26 weeks 4 days ago.
Re: Re: Is Scala the Next C++


On Sep 9, 2011 1:12 AM, "Cédric Beust ♔" <cedric [at] beust [dot] com> wrote:
>
> On Thu, Sep 8, 2011 at 5:10 PM, Kevin Wright <kev [dot] lee [dot] wright [at] gmail [dot] com> wrote:
>>
>> By any *objective* measurement of simplicity, Scala is definitely simpler than Java.
>
>
> Can you think of any feature that Java has and Scala doesn't?

Yes, easily:
Disjoint constructors
Call-site variance
Interfaces
Switch statements
For loops
The ternary operator
Enums
Checked exceptions
Primitives
Covariant Arrays
...and so on...

>
> How about the reverse?
>

Also yes :)

> -- 
> Cédric
>

Jörg W Mittag
Joined: 2009-12-31,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: Is Scala the Next C++

Cédric Beust ♔ wrote:
> On Thu, Sep 8, 2011 at 5:10 PM, Kevin Wright wrote:
>> By any *objective* measurement of simplicity, Scala is definitely simpler
>> than Java.
> Can you think of any feature that Java has and Scala doesn't?

Array Covariance, Primitives, Statics, Interfaces, Operators,
Wildcards, Fields, Use-Site Variance, Switch Statements, For Loops,
Checked Exceptions are just the first ones that come to mind.

Now, it looks like Java 8/9 might even get a completely separate
*second* (or third, if you count primitives) type system for
structural function types.

> How about the reverse?

Of course, there are features Scala has that Java doesn't. Abstract
types, for example.

However, some of the features Scala has over Java, are *actually*
features that *do* exist in Java, but have some strange restrictions.

For example, in Java some class members can be parametric, some
abstract, some both, some neither. In Scala, everything can be both
abstract and parametric. So, yes, abstract types are a feature that is
in Scala and not in Java, but they are simply a consequence of the
much simpler rules of Scala.

For Scala not to have abstract types, you would need to add a special
case rule to the language specification (instead of "everything can be
abstract" you would have "everything can be abstract except for
types"), thus making the language *more* complex in order to *remove*
a feature.

Complexity is not just about the number of features, it's also about
the number of special cases. Java is full of them.

There are both methods and operators in the language. They do
basically the same thing, but one can be user-defined, the other
can't. For one, I can choose my names (fairly) freely, for the other
not. Both can be overloaded, but only one can be overloaded by the
user.

Variance is user-definable and defined at the use site, except for
arrays, where it is fixed at the declaration site (the spec). Type
constructors can't take primitives as arguments, except for the array
type constructor. Type constructor arguments are erased, except for
the array type constructor. Object types are user-definable, primitive
types aren't.

jwm

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland