View · Search · Index
No registered users in community xowiki
in last 10 minutes

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

From: Artur Trzewik <mail_at_xdobry.de>
Date: Tue, 03 Jul 2007 21:56:16 +0100

> 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