Showing posts with label class. Show all posts
Showing posts with label class. Show all posts

Thursday, May 30, 2013

Nothing in OOP is obvious


Is nothing in OOP obvious to the neophyte?

Here is comment from a class named Observable declared as follows :


   public abstract shared Observable


The documentation for the class contains the following method comment  :

public add-observer

Add an observer to this object's list of observers to be notified. Typically this is only called from the Observer's observe method.


For this to make sense to a neophyte, wouldn't we need TWO variants of PUBLIC, e.g.,

  • MY-PUBLIC-FACE
  • YOUR-PUBLIC-VIEW-OF-ME

corresponding to

  • obj-public (intended for me to call against myself)
  • consumers-public (available as your message sent to me)

??

BTW, that add-observer method is declared as follows :

public  
{Observable.add-observer
    o:Observer,
    error-if-present?:bool = false
}:void


Is the issue the method name ?  Should it be 

   all-ya-all-add-observer-to-me

??

Consider :

   receive-observer

But what in a name prevents a hack ?  One idea : object procedures and functions versus messages.  In such a language, an object never sends itself a message.  If you have a local copy of an object, you can use its public procedures and functions.  If you have a pointer to an object - an object reference - you send only messages.

And what did the documenting author mean by "typically" ?



Saturday, September 4, 2010

A default O-O package for Tcl 8.6: TclOO

 
While the link for O-O Tcl looks to be dated, the page for Tcl 8.6 releases is current.

I have a bias for XOTcl, but I will try to be open-minded when 8.6 gets out of beta.

TclOO is intended to offer classes and objects as a Tcl package rather than as an ad hoc extension to Tcl and Tk.  Some "patterns" folks will like the hiding of new in class in favour of create as the class declaration idiom - but instances are created via a command block substitution with the new word as in
set obj [MyClass new]
A google of TclOO and Tcl failed to get me past beta1 links to Tcl8.6b2 links.

But the link to the PDF on the new engine looked interesting.

This link at tcl.tk may be the final URL for core TclOO.

Over at activestate.com Tcl remains at 8.5.8 with a release number of 8.5.8.2 as of today.

Tcl 8.5.9 added the ttk::spinbox command.

A google on "Tcl 8.6" gives some useful links such as that to Mark Roseman's 8.6 page (he is the author of the tutorial for Ttk or Tile/Themed Tk.)

Sunday, October 26, 2008

How to improve Curl

One terrific thing about Curl as a language is that the compiler directives are able to help ensure coding standards as code evolves to production quality.

One vexing thing in Curl code is to find {field } expressions occurring willy-nilly within a {define-class }.

I propose an option for {define-class } such that the expression {attributes } is the one-and-only set of fields declared as follows:
{attributes
my-i-attr1:int
my-f-attr2:float
|| etc
}
In such a class definition the {field } expression may not occur when compiler-directives include
rational? = true ||humor

I would further propose the declaration grouping
{class
}
to replace and preclude the use of
{define-proc }
within a class declaration.

For the instance-side of a class, I would propose the use of the method grouping expressions
{public
and
{private
and
{protected
and that where such expressions occur, that no
{method
be permitted to be free-standing within that class definition when rational? = true and that only one occurrence of each grouping be permitted. A further restriction might require that public precede protected which must precede private.

The {class } expression would also permit some class-side procedures to be declared as final, sealed or open.

The compiler-directive rational? = true would be stronger than stringent?, i.e., classes compiled in a rational? package would be thereby also stringent?

To take a page from another language, within these method groupings, a blank line would separate method declarations and only method declarations.

One further option is to have {i-attributes } and {d-attributes}. No default values are declared for the former as they must be initialized in a factory/constructor method whereas the latter need not.

Clean code is readable code and readable code may be maintainable code.