Index: doc/next-migration.html =================================================================== diff -u -re3a84e351aaf79c02a63cc0741dde7b9bd550849 -rb3018d3be0f1524a3f1709edc0e2ddb5d8bc4c0b --- doc/next-migration.html (.../next-migration.html) (revision e3a84e351aaf79c02a63cc0741dde7b9bd550849) +++ doc/next-migration.html (.../next-migration.html) (revision b3018d3be0f1524a3f1709edc0e2ddb5d8bc4c0b) @@ -534,8 +534,8 @@

Migration Guide for the the Next Scripting Language

Gustaf Neumann
<neumann@wu-wien.ac.at>
-version 2.0, -December 2010 +version 2.1, +March 2011
Written for the Initial Release of the Next Scripting Framework.
Table of Contents
@@ -608,20 +608,19 @@
  • -The encapsulation of Next Scripting is stronger than in XOTcl but - 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 encapsulation of NX is stronger than in XOTcl but still weak + compared to languages like C++; a developer can still access other + objects' variables via some idioms, but NX makes accesses to other + objects variables explicit. The requiredness to make these + accesses explicit should encourage developer to implement well + defined interfaces to provide access to instance variables.

  • The Next Scripting Language provides means of method - protection. Therefore developers have to define interfaces in order - to use methods from other objects. + protection. Therefore developers have to define interfaces in + order to use methods from other objects.

  • @@ -649,121 +648,65 @@
  • -The Next Scripting Language has a much smaller interface (less - predefined methods) than XOTcl: +The naming of the methods in the Next Scripting Language is much more + in line with the mainstream naming conventions in OO languages.

    -
      +
    • -NX: +The Next Scripting Language has a much smaller interface (less + predefined methods) than XOTcl (see Table 1), allthough the + expressability was increased in NX.

      -
      + + +
      +
      + ++++ - - + + + + + - - + + + + + - - + + + - - + + + -
      Table 1. Comparison of the Number of Methods in NX and XOTcl
      -Methods for Objects: -
      -
      -

      -18 -

      -
      NXXOTcl
      -Methods for Classes: -
      -
      -

      -7 -

      -

      Total

      41

      125

      -Info methods for Objects: -
      -
      -

      -14 -

      -

      Methods for Objects

      17

      52

      -Info method for Classes: -
      -
      -

      -6 -

      -

      Methods for Classes

      4

      24

      -
    • -
    • -

      -XOTcl: -

      -
      - - + + + - - + + + - - - - - - - - -
      -Methods for Objects: -
      -
      -

      -52 -

      -

      Info-methods for Objects

      14

      25

      -Methods for Classes: -
      -
      -

      -24 -

      -

      Info-methods for Classes

      6

      24

      -Info methods for Objects: -
      -
      -

      -25 -

      -
      -Info method for Classes: -
      -
      -

      -24 -

      -
      -
    • -
    -
  • -
  • -

    -The naming of the methods in the The Next Scripting Language is much more - in line with the mainstream naming conventions in OO languages. -

    -
  • -
    + + +

    Below is a small, introductory example showing an implementation of a class Stack in NX and XOTcl. NX supports a block syntax, where the methods are defined during the creation of the class. The XOTcl syntax @@ -845,7 +788,7 @@ set things "" } -Stack instproc push {thing} { +Stack instproc push {thing} { my instvar things set things [linsert $things 0 $thing] return $thing @@ -911,21 +854,14 @@ package require XOTcl 2.0 - # Import XOTcl into the current namespace - namespace import -force ::xotcl::* - - # Define a class using XOTcl - Class C1 + # Define a class using XOTcl + xotcl::Class C1 C1 instproc foo {} {puts "hello world"} package require nx - # Import NX into the current namespace; - # "Class" will be after the command "::nx::Class" - namespace import -force ::nx::* - - # Define a class using NX - Class create C2 { + # Define a class using NX + nx::Class create C2 { :public method foo {} {puts "hello world"} } }

    @@ -1042,8 +978,8 @@ object-specific methods. When the term (e.g. method) is used on a class, the method will be inherited (applicable to the instances of the class). When the term is used on an object, an object-specific -method is defined. NX uses the method modifier class-object to -defined a class-method (method for the class-object).

    +method is defined. NX uses the method modifier class to +define a class-specific method (method for the class object).

    Furthermore, both XOTcl and NX distinguish between scripted methods (section 3.2.1) and C-defined methods (section 3.2.2). Section 3.2.3 introduces method protection, which is only supported by NX.

    @@ -1078,7 +1014,7 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
    # Define method 'foo' and class-object
    +
    # Define method 'foo' and class
     # method 'bar' for a Class 'C' with separate
     # toplevel commands
     
    @@ -1096,12 +1032,12 @@
     .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;}
     .nx-variable    {color: #AF663F; font-weight: normal; font-style: normal;}
     
    -
    # Define method and class-object method
    +
    # Define method and class method
     # in the init-block of a class
     
     Class create C {
       :method foo args {...}
    -  :class-object method bar args {...}
    +  :class method bar args {...}
     }
    -
    # Define method and class-object method
    +
    # Define method and class method
     # with separate commands
     
     Class create C
     C method foo args {...}
    -C class-object method bar args {...}
    +C class method bar args {...}
    @@ -1150,7 +1086,7 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
    # Define class-object method and set
    +
    # Define class method and set
     # instance variable in the init-block of
     # an object
     
    @@ -1169,7 +1105,7 @@
     .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;}
     .nx-variable    {color: #AF663F; font-weight: normal; font-style: normal;}
     
    -
    # Define class-object method and set
    +
    # Define class method and set
     # instance variable with separate
     # commands
     
    @@ -1300,7 +1236,7 @@
     
     Class create C {
       :forward f1 ...
    -  :class-object forward f2 ...
    +  :class forward f2 ...
     }
     
     Object create o {
    @@ -1319,7 +1255,11 @@
     .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;}
     .nx-variable    {color: #AF663F; font-weight: normal; font-style: normal;}
     
    -
    Class C
    +
    # Define setter and getter methods in XOTcl.
    +#
    +# XOTcl provides methods for these.
    +
    +Class C
     C instparametercmd p1
     C parametercmd p2
     
    @@ -1336,7 +1276,12 @@
     .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;}
     .nx-variable    {color: #AF663F; font-weight: normal; font-style: normal;}
     
    -
    # Define setter and getter methods
    +
    # Define setter and getter methods in NX.
    +#
    +# NX does not provide own methods, but uses
    +# the low level framework commands, since
    +# application developer will only seldomly
    +# need it.
     
     Class create C
     ::nsf::method::setter C p1
    @@ -1397,7 +1342,7 @@
     
     Class create C {
       :alias a1 ...
    -  :class-object alias a2 ...
    +  :class alias a2 ...
     }
     
     Object create o {
    @@ -1410,10 +1355,10 @@
     

    3.2.3. Method Modifiers and Method Protection

    -

    NX supports the three method modifiers class-object, public and +

    NX supports the three method modifiers class, public and protected. All method modifiers can be written in front of every method -defining command. The method modifier class-object is used to denote -class-object specific methods (see above). The concept of method +defining command. The method modifier class is used to denote +class-specific methods (see above). The concept of method protection is new in NX.

    # Method modifiers
     #
    -#   "class-object",
    +#   "class",
     #   "public", and
     #   "protected"
     #
    @@ -1459,31 +1404,37 @@
     .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;}
     .nx-variable    {color: #AF663F; font-weight: normal; font-style: normal;}
     
    -
    # Method modifiers orthogonal over all kinds of methods
    +
    # Method modifiers
     #
    -# Method-definition-methods:
    +#   "class",
    +#   "public", and
    +#   "protected"
    +#
    +# are applicable for all kinds of method
    +# defining methods:
    +#
     #    method, forward, alias, attribute
     
     Class create C {
       :/method-definiton-method/ ...
       :public /method-definiton-method/ ...
       :protected /method-definiton-method/ ...
    -  :class-object /method-definiton-method/ ...
    -  :protected class-object /method-definiton-method/ ...
    -  :public class-object /method-definiton-method/ ...
    +  :class /method-definiton-method/ ...
    +  :protected class /method-definiton-method/ ...
    +  :public class /method-definiton-method/ ...
     }
    -

    While XOTcl does not provide method protection, in NX, all methods are -defined per default as protected.

    -

    NX allows to configure the default call protection in various -ways. The command ::nx::configure defaultMethodCallProtection -true|false can be used to set the default call protection for -scripted methods, forwarder and aliases, while ::nx::configure -defaultAttributeCallProtection true|false can set the default -protection for attributes.

    +

    XOTcl does not provide method protection. In NX, all methods are +defined per default as protected. These defaults can be changed by the +application developer in various ways. The command ::nx::configure +defaultMethodCallProtection true|false can be used to set the default +call protection for scripted methods, forwarder and aliases, while +::nx::configure defaultAttributeCallProtection true|false can set +the default protection for attributes. The defaults can be overwritten +also e.g. on a class level.

    @@ -1557,7 +1508,7 @@ } } Object create o { - :method baz {} {...} + :public method baz {} {...} }
    @@ -2190,7 +2141,7 @@ Class create C { :attribute x :attribute {y 1} - :class-object attribute oa1 + :class attribute oa1 } Object create o { @@ -2568,7 +2519,10 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
    # n.a.
    +
    # Only leading non-positional parameters
    +# are available; no optional positional
    +# parameters, no value constraints on
    +# positional parameters, no multiplicity, ...
    -
    # n.a.
    +
    # No return value checking available
    /cls/ instmixin ...
    -/cls/ instmixinguard mixin /condition/
    +/cls/ instmixinguard /mixin/ ?condition?
    /cls/ mixin ...
    -/cls/ mixin guard mixin /condition/
    +/cls/ mixin guard /mixin/ ?condition?
    /obj/ mixin ...
    -/obj/ mixinguard mixin /condition/
    +/obj/ mixinguard /mixin/ ?condition?
    /cls/ instfilter ...
    -/cls/ instfilterguard filter /condition/
    +/cls/ instfilterguard /filter/ ?condition?
    /obj/ filter ...
    -/obj/ filterguard filter /condition/
    +/obj/ filterguard /filter/ ?condition?
    -
    /cls/ class-object info methods ?pattern?
    +
    /cls/ class info methods ?pattern?
    @@ -3427,7 +3384,7 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
    /cls/ class-object info methods -methodtype setter ?pattern?
    +
    /cls/ class info methods -methodtype setter ?pattern?
    @@ -3453,7 +3410,7 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
    /cls/ class-object info methods -methodtype scripted ?pattern?
    +
    /cls/ class info methods -methodtype scripted ?pattern?
    @@ -3479,7 +3436,7 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
    /cls/ class-object info methods -methodtype alias ?pattern?
    +
    /cls/ class info methods -methodtype alias ?pattern?
    @@ -3505,7 +3462,7 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
    /cls/ class-object info methods -methodtype forwarder ?pattern?
    +
    /cls/ class info methods -methodtype forwarder ?pattern?
    @@ -3531,7 +3488,7 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
    /cls/ class-object info methods -methodtype object ?pattern?
    +
    /cls/ class info methods -methodtype object ?pattern?
    @@ -3557,7 +3514,7 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
    /cls/ class-object info methods \
    +
    /cls/ class info methods \
        -callprotection public|protected ...
    @@ -3638,8 +3595,8 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
    /cls/ ?class-object? info method exists /methodName/
    -/cls/ ?class-object? info methods /methodName/
    +
    /cls/ ?class? info method exists /methodName/
    +/cls/ ?class? info methods /methodName/
    @@ -4337,7 +4294,7 @@

    For definition of class object specific methods, use the modifier -class-object as shown in examples above.

    +class as shown in examples above.

    3.6.9. List Filter or Mixins

    @@ -4440,7 +4397,7 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
    /cls/ class-object info filter methods \
    +
    /cls/ class info filter methods \
        ?-guards? ?-order? ?pattern?
    @@ -4467,7 +4424,7 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
    /cls/ class-object info filter guard /name/
    +
    /cls/ class info filter guard /name/
    @@ -4600,7 +4557,7 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
    /cls/ class-object info mixin classes \
    +
    /cls/ class info mixin classes \
        ?-guards? ?-order? ?pattern?
    @@ -4627,7 +4584,7 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
    /cls/ class-object info mixin guard /name/
    +
    /cls/ class info mixin guard /name/
    @@ -4689,7 +4646,7 @@

    3.6.10. List definition of methods defined by aliases, setters or forwarders

    -

    As mentioned earlier, +info method definition" can be used on every +

    As mentioned earlier, info method definition can be used on every kind of method.

    -
    /cls/ ?class-object? info method handle /methodName/
    +
    /cls/ ?class? info method handle /methodName/
    @@ -4905,7 +4862,7 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
    /cls/ ?class-object? info method type /methodName/
    +
    /cls/ ?class? info method type /methodName/
    @@ -5923,7 +5880,7 @@

    4.2.1. Parameter usage without a value

    In XOTcl 1, it was possible to call a parameter method during object -creation via the -param without a value (in the example below -x.

    +creation via the dash-interface without a value (in the example below -x).

    -
    Class Foo -parameter {x y}
    +
    # XOTcl example
    +
    +Class Foo -parameter {x y}
     Foo f1 -x -y 1

    Such cases are most likely mistakes. All parameter configurations in XOTcl 2 require an argument.

    @@ -5957,11 +5916,36 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -
    Class Foo -parameter {{x 1}}
    +
    # XOTcl example
    +
    +Class Foo -parameter {{x 1}}
     Class Bar -superclass Foo -parameter x
     Bar b1
    +
    +

    4.2.3. Ignored Parameter definitions

    +

    NX does not define the methods class and superclass but allows to +alter the class/superclass via configure. The class and superclass +can be certainly queried in all variants with info class or info superclass.

    +
    +
    +
    # NX example
    +
    +nx::Class create Foo
    +Foo create f1
    +# now oalter the class of object f1
    +f1 configure -class nx::Object
    +

    4.3. Calling Objects via Method Interface

    Since the Next Scripting Framework supports the so-called ensemble @@ -5980,7 +5964,9 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

    Foo::slot::ints foo ...
    +
    # XOTcl example
    +
    +Foo::slot::ints foo ...
     Foo slot ints foo ...

    In the Next Scripting Framework, only the first form has the same semantic as before. In the second form (invocation of objects via @@ -6022,16 +6008,17 @@ .nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;} .nx-variable {color: #AF663F; font-weight: normal; font-style: normal;} -

    ::nsf::exithandler set|get|unset ?arg?
    +
    # NX example
    +::nsf::exithandler set|get|unset ?arg?