Nice TWiki > Doc > LanguageComparisons > NiceVersusPizza (r1.2) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }
This page is an attempt to summarize the differences between Nice and Pizza.

Comparison of common features

Type systems

Both languages have type parameters. The precise type-systems differ: Pizza uses F-bounded polymorphism, Nice uses Polymorphic constrained types. I believe they are incomparable in theory (not one is more expressive than the other). In practice I found several pains with Pizza types:

  1. Subclasses cannot change the parameter or return types of methods present in super class. I Nice the same behaviour is possible using multi-methods.
  2. It is possible in Nice but not in Pizza to instantiate a new array with a type variable component type. That is one can write new T[] in a polymorphic function. This is usefull to write the map function of arrays for instance.
  3. Nice has the unique feature that types keep track of the possibility for the values to be null or not: String is the type of non-null strings, while ?String is the type of possibly null strings. This is good for making the interface of methods explicit (does it accept null arguments?) and ensures that no NullPointerException occurs at runtime.
  4. In Pizza it is necessary to cast values of a type parameter to Object when calling some functions. So this example in Pizza's tutorial:
      public boolean contains(A x)
      {
        return ((Object)elem).equals((Object)x) ||
          rest.contains(x);
      }

is written in Nice

      boolean contains(A x)
      {
        return elem.equals(x) || rest.contains(x);
      }

or even, still in Nice

      boolean contains(A x) = elem.equals(x) || rest.contains(x);

Anonymous functions

Both languages introduce anonymous functions, in a very similar way. Nice is a bit more powerful because it is not necessary to give the return type of the function, it is computed by the compiler. Also one can declare local functions inside a method or another function.

Pizza features absent from Nice

Algebraic types

This is unique to Pizza, and allows to declare concisely a set of classes being cases of the same abstract parent, and to do pattern matching on them. See AlgebraicDatatype for a discussion about a better alternative in Nice, using multi-methods.

Embedability

In Pizza embeddable means that you can feed the pizzacompiler with source (.java or .pizza) files out of the application through an InputStream. You can also tell the compiler to write the bytecode or the pizza->java code in an OutputStream. So the compiler is not strictly file oriented and the Application that embeds the pizzcompiler does not need the use the filesystem. You give Pizza a Collection of InputStream and you get a Collection of OutputStream containing the bytecode.

Nice features absent from Pizza

Tuples

Tuples are a certain number of values grouped together. They allow for instance a method to return several values. Pizza only has a Pair class, with several drawbacks: supports only two values, is not covariant (a pair of integers cannot be used where a pair of longs is expected), is much more verbose to write. One can have more values by nesting pairs, but that's a lot more of verbosity.

Optional parameters

Some parameters of amethod can have a default value that is used when the parameter is not present.

Multi-methods

They allow methods to be defined outside classes. This means that new methods can be defined on classes that belong to a different package (even in java.*). Multi-methods alse extend usual methods with the possibility to dispatch on every argument, instead of only the receiver class. Using multi-methods is preferable to applying the Visitor pattern.

Design by contract

Nice supports design by contract. Methods can have pre- and post-conditions.

Automatic recompilation

The nicec compiler find and recompiles automatically any package if it is needed. It looks for packages in the current directory and in the sourcepath. Pizza needs every source to be present on the command line.

Conclusion

It seems to me that the only reason to prefer Pizza is the presence of Algebraic Classes. See AlgebraicDatatypes for a discussion on how this can be better expressed in Nice. Nice has many other features that ensure more expressivity, modularity and safety.

-- DanielBonniot - 11 Feb 2003

Topic NiceVersusPizza . { Edit | Attach | Ref-By | Printable | Diffs | r1.3 | > | r1.2 | > | r1.1 | More }
Revision r1.2 - 05 Mar 2003 - 15:20 GMT - DanielBonniot
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.