Nice TWiki > Doc > LanguageComparisons > NiceVersusJython (r1.1) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }
[Feel free to improve things, I'm no expert, especially on Nice, but I thought this page would be nice to have. MichaelChermside - 19 Aug 2003]

Jython is an implementation of the language Python (see http://www.python.org) in Java. It runs on the JVM, and can compile to java bytecodes (like Nice). Python is a very dynamic language, with many of the same good language features of Nice.

In order of the Nice manual:

Philosophy:

* Nice's philosophy is Safety / Modularity / Expressivity. * Jython has far LESS emphasis on Safety -- it is more inclined toward letting the programmer do as she pleases if she intentionally steps into "black magic" land. * Jython's approach to Modularity is similar to Nice's. * Jython has at LEAST as much emphasis on expressivity as Nice, perhaps more.

Packages

* Jython's "modules" are pretty much equivalent to Nice's "packages". Both can contain classes AND functions/methods AND miscellaneous variables/constants. Unlike Nice, Jython allows importing an entire module OR a single class/function/whatever from a module.

Classes

Fields

* Nice's classes have a fixed set of fields, while methods are actually separate (but via multi-dispatch, can be associated with a class). * Jython's classes are more like a bare namespace -- the fields can be initialized, but additional fields can be added (or removed) at runtime. Methods ARE actually associated with a class, in fact, they are simply fields, whose type is "function"[*].

[*] Not strictly true, but close enough. See "bound methods" below.

Constructors

* Jython, like Nice, has a single constructor for each class (Jython allows but does not require the use of keyword arguments). * Unlike Nice, Jython requires the programmer to write out the constructor. * Like Nice, Jython encourages the use of factory functions if multiple construction mechanisms are required.

Parametric Classes

* Jython does not have this feature, nor is it needed. The reason is a very fundamental difference between Nice and Jython: dynamic typing. Jython (like Nice) is "strongly typed" -- objects have a type with specific capabilities, so you can't take a String an use it like a pointer or a number (C, for example, is "weakly typed" and DOES allow this). However, Jython is "dynamically typed" (unlike Nice, which is "staticly typed"). This means that individual variables or items in a container do NOT have well-specified types. In Nice, a variable x is declared to be int, or String, or ?MyOwnClass, and may only contain those values; Python does not have a similar restriction. Some people prefer static languages (more errors caught at compiletime instead of runtime), others prefer dynamic (no need to declare variable types, sometimes more flexibility).

Functions and Methods

* Functions and methods are first-class objects in BOTH Jython and Nice. * Jython does NOT support multi-dispatch, only single-dispatch. * Nice distinguishes between "functions" and "methods" (the latter can be specialized for multi-dispatch). * "Functions" and "methods" are the same in Jython, except that there exists something called a "bound method". If "fido" is an instance of the class "Dog" with the method "bark(timesToBark)", then Dog.bark is an ordinary function taking two arguments, a Dog and an integer, while fido.bark is a "bound method" taking ONE argument (an integer), and performing a call to Dog.bark with the first parameter automatically set to fido.

TO BE CONTINUED...

Topic NiceVersusJython . { Edit | Attach | Ref-By | Printable | Diffs | r1.5 | > | r1.4 | > | r1.3 | More }
Revision r1.1 - 19 Aug 2003 - 12:36 GMT - MichaelChermside
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.