1. Differences Between XOTcl and NX
In general, the Next Scripting Language (NX) differs from XOTcl in the following respects:
-
The Next Scripting Language favors a stronger form of encapsulation than XOTcl. Calling the own methods or accessing the own instance variables is typographically easier and computationally faster than these operations on other objects. This behavior is achieved via resolvers an makes the definition of methods necessary in XOTcl obsolete. On the other hand, XOTcl is complete symmetrical in this respect.
-
The encapsulation of Next Scripting is still weak compared to languages like C++; a developer can still access e.g. other variables via some idioms, but this makes accesses to other objects variables explicit and requires more typing effort. Through the weak encapsulation a programmer should be encouraged to implement methods to provide access to instance variables.
-
The Next Scripting Language provides means of method protection.
-
The Next Scripting Language provides scripted init blocks for objects and classes (replacement for the somewhat dangerous dash "-" mechanism in XOTcl that allows to set variables and invoke methods upon object creation).
-
The Next Scripting Language provides much more orthogonal means to define, reuse and introspect scripted and C-implemented methods.
-
The Next Scripting Language provides an orthogonal framework for parametrization of methods and objects. While XOTcl 1 provided only value-checkers for non-positional arguments for methods, the Next Scripting Framework provides the same value checkers for positional argument of methods, as well as for object parameters (-parameter in XOTcl 1).
-
The Next Scripting Language has a much smaller interface (less predefined methods) than XOTcl:
-
NX:
Methods for Objects:
20
Methods for Classes:
7
Info methods for Objects:
14
Info method for Classes:
6
-
XOTcl:
Methods for Objects:
52
Methods for Classes:
24
Info methods for Objects:
25
Info method for Classes:
24
-
Below is a small, introductory example showing an implementation of a stack in NX and XOTcl.
Stack example in NX | Stack example in XOTcl |
---|---|
Class create Stack { # # Stack of Things # :method init {} { set :things "" } :public method push {thing} { set :things [linsert ${:things} 0 $thing] return $thing } :public method pop {} { set top [lindex ${:things} 0] set :things [lrange ${:things} 1 end] return $top } } |
# # Stack of Things # Class Stack Stack instproc init {} { my instvar things set things "" } Stack instproc push {thing} { my instvar things set things [linsert $things 0 $thing] return $thing } Stack instproc pop {} { my instvar things set top [lindex $things 0] set things [lrange $things 1 end] |