[Xotcl] parameters vs slots and use of "-initcmd"

Artur Trzewik mail at xdobry.de
Tue Jul 3 22:56:16 CEST 2007


> After spending few weeks in understanding the basic concepts of the
> language, I decided to use it to model one component of the software I'm
> developing as part of my PhD project (basically, configuration of
> complex digital hardware macrocells). I've been attracted by XOTcl due
> to its "aspect oriented" features which are today very common in the
> hardware design industry.
>
> I need some clarifications regarding the use of Class parameters and
> Class slots (I will refer to v.1.5.2 of the XOTcl tutorial).
> Parameters are used throughout the introduction of the tutorial to model
> Class attributes, then slots are introduced in a later section. Are
> slots and parameters actually the same thing? Is there some reason to
> prefer one over the other?
>
>   
In early version of XOTcl perameter are just a clever shortcut for method
Definition
Class A -paramter a

has leaded to method

# setter and getter in one method
# something like this
A instproc a {args} {
        if {[llength $args]==0} {
            my set a
       } else {
             my set a [lindex $args 0]
       }
}

It was pure XOTcl and also visible per info instbody.
Now parameters are C-coded and probably faster.
But it could be better to use old fashioned getter and setter methods, which
are well known from Java and Smalltalk.
(in Smalltalk all instance variables are private.)
Using only method for accessing objects has some advantages (It is more 
OOP method=message).

A instproc getA {
     my set a
}
A instproc setA value {
    my set a $value
}

Methods could be better managed and intercepted per mixins or inheritance.
I use XOTcl parameters almost only for true value objects, where I do not
need any control about accessing them.
Parameters are only syntactic sugar but you do not need to use it.

Artur


More information about the Xotcl mailing list