Nice TWiki > Doc > LanguageComparisons > NiceVersusScala (r1.21) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }


Scala has many things in common with Nice: "Scala is a modern multi-paradigm programming language designed to express common programming patterns in a consise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages".

There are also fundamental differences: Scala has far less in common with Java (Scala targets CLR as-well-as JVM), Scala uses single dispatch, and has a different type system (nuObj).

This at a glance comparison is based on Scala version 1.0.0-b6 and Nice version 0.9.8


  Unified Types Traits Mixins External Methods Inner classes Abstract Interfaces
Nice Yes NA NA Yes No Yes
Scala Yes Yes Yes No Yes No

Nice and Scala move forward OO programming in different ways. Nice addresses the problems of adding functionality to existing classes and binary methods with Multi Methods; Scala addresses the problem of implementation reuse with Traits and Mixins.


  Anonymous Functions Higher-Order Functions Currying Dynamic Dispatch Nested Functions
Nice Yes Yes Not yet (at call site) Multiple Dispatch Yes
Scala Yes Yes Yes (at definition) Single Dispatch Yes

Type Parameters

  Generic Classes Generic Methods Variant Class Type Parameters Upper Type Bounds Lower Type Bounds Multiple Bounds
Nice Yes Yes Not yet completed Yes Yes Yes
Scala Yes Yes Yes Yes Yes Yes

Someone with a better understanding of type systems could comment here

Java Commonality

  Use Java classes Parameterize Java classes Subclass Java classes Subclass in Java Java Statements/Operators
Nice Yes Yes Yes Yes Yes
Scala Yes No Yes Yes No

Although Scala can use Java classes (and in the future .Net classes) there's no intent to make the language familiar to Java programmers; Nice looks a little more like a Java 2.0 than an entirely new language.

Some of these differences can be seen in the following example. In Scala we use a HashMap defined in a Scala library; in Nice we use local type inference with the Java HashMap. In Scala we use a sequence comprehension; in Nice an extended for statement, or a Java for statement.

Scala Nice
import scala.collection.mutable.HashMap;

object hash {
  def main(args: Array[String]) = {
    val n = toPositiveInt(args);
    var count = 0;
    val table = new HashMap[String,Int]();

    for (val i <- Iterator.range(1,n+1)) 
      table(Integer.toString(i, 16)) = i;

    for (val i <- Iterator.range(1,n+1)) 
      if (table contains Integer.toString(i, 10)) 
        count = count + 1;


  private def toPositiveInt(s: Array[String]) = {
    val i = 
      try { Integer.parseInt(s(0)); } 
      catch { case e: Exception => 1 }

   if (i>0) i else 1;


void main(String[] args){
  let n = toPositiveInt(args);
  var count = 0;
  let table = new HashMap();

  for (int i : 1..n)
    table[ Integer.toString(i, 16) ] = i;

  for (int i = 1; i <= n; i++) 
    if (table.containsKey(Integer.toString(i, 10))) 


private int toPositiveInt(String[] s){
  int i;
  try { i = Integer.parseInt(s[0]); }
  catch (Exception e){ i = 1; } 

  if (i>0) return i; else return 1;


Methods Pattern Matching Local Type Inference Comprehensions Option Types User Defined Coercions Tuples
Nice Enum Classes & Multi Methods Monomorphic (at present) No String & ?String No Yes
Scala Case classes Monomorphic, Polymorphic, Non-Recursive Functions Yes Some(String) & None Yes Library

Of course, both Scala and Nice have other interesting features.


Nice Option Types seem to have found a middle course, allowing non-null types to be distinguished without making them harder to use when a value may be null.

Every Scala expression has a value, so there are fewer explicit return statements - I'm familiar with that from Smalltalk, so it's difficult to judge if I just like it because it's familiar. In some cases Scala syntax seems more consistent; Nice seems to extend Java and so add syntax. For example, def square(x: Int) = { var y=x; y*y } and def square(x: Int) = x*x; whereas Nice has int square(int x){ var y=x; return y*y; } and a shorthand form int square(int x) = x*x;

Paradoxically, Nice's syntax is closer to Java, and Nice more effectively reuses Java libraries, but in a fundamental way Scala is more like Java - it's based around classes.

-- IsaacGouy - 26 Jan 2004 (thanks Arjan)

Topic NiceVersusScala . { Edit | Attach | Ref-By | Printable | Diffs | r1.22 | > | r1.21 | > | r1.20 | More }
Revision r1.21 - 03 Apr 2005 - 10:41 GMT - TWikiGuest
Parents: WebHome > LanguageComparisons
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.