Version 9 of ::oo:: too

Updated 2018-01-16 12:26:46 by jsuntheimer72

An investigatory analysis.

TclOO. Okay, got it.

I'm not much for extraneous syntax, but if you have to have it, ::oo:: is not a bad way to go. Looks cool. Pew pew pew, it's a spaceship. Or a spider. Maybe it's a moose. Maybe it's looking deeply into the eyes of a lover. ::oo:: is pretty cool, as far as syntax goes.

Well, it's been a long stretch in the JavaScript mines, better brush up on my canon.

TO THE WIKI! ALOHA!!

 Commands
 ::oo::class          new in 8.6
 ::oo::copy           new in 8.6
 ::oo::define         new in 8.6
 ::oo::objdefine
 ::oo::object
 info
 info class           provides introspection of classes (many subcommands)
 info object          provides introspection of objects (many subcommands)

 Method Commands      The following commands are only available within the body of a method
 my                   new in 8.6
 next                 new in 8.6 
 self                 new in 8.6

Now, I'm not one of them big city software architects, but I can't help but notice there are some top level tcl commands, and all I know about them right now is that they are brand-spanking new, and they are only available within the body of a method. This feels, subtly, ever so slightly, on the fringes of my spider-sense, like name space pollution. Like, if ever there was a reason to use namespaces, wouldn't it be to prevent commands that can only be used in a specific context from becoming top level commands? I'm just thinking out loud here. We'll see later if perhaps some radical language modification or maybe a complex, streaming build system might come to our rescue on that.

Okay, folks, shows over. That's TclOO, you've seen it, time to get codi..

Wait- I think I've seen that spaceship-spider-moose lover before. Was her name Valerie? No, that's not it...

 noop Sherlock/Mr. Robot-style eidetic memory sequence ensues, consisting mostly of tcl code, sandworms, and Stevie Nicks

Wait, I know! It was in the Tcllib 1.18 documentation! Yeah, it was ::oo::util, and of course, its twin, the other ::oo::util! I knew I saw it before. Wait, not just there, but.. somewhere..

 noop Fragments from Madonna's 1984 video "Borderline" flash in rapid succession

No, it wasn't in the Tcllib 1.18 documentation, it was in the "README of Changes" of Tcllib 1.18! Of course it was, it was there the whole time, and we learned the true TclOO was the friendships we made along the way.

 oodialect       oo::dialect         0.3

 oometa          oo::meta            0.4.1
                 oo::option          0.3

No, I'm wrong. Nothing here but a third of an infinite language, less than half of a meta infinity, and a ukulele option.

Hold on just a gosh darn minute! That's not even a tiny bit of a meta infinity, let alone almost half of one. It's that silly tcl namespacing, isn't it?

 ::::::::::::::::::::::::::::::::::info tclversion
 ::info tclversion
 info tclversion

Never judge a namespace by the number of preceding colons. That's what pappy used ta always say.

So herm, maybe that's all of them? Maybe it would do for now. So now what are we looking at again?

   Commands
 ::oo::class            new in 8.6
 ::oo::copy             new in 8.6
 ::oo::define           new in 8.6
 ::oo::objdefine        new in France
 ::oo::object           big in Japan
 ::oo::util             namespaces solve problems
 ::oo::util             twice as nice as the last ::oo::util
 ::oo::dialect          new in tcllib 1.18 release notes
 ::oo::meta             new in tcllib 1.18 release notes
 ::oo::option           new in tcllib 1.18 release notes
 ::info
 ::info class           provides introspection of classes (many subcommands)
 ::info object          provides introspection of objects (many subcommands)

 Method Commands        The following commands are only available within the body of a method
 ::my                   new in 8.6
 ::next                 new in 8.6 
 ::self                 to thine be true

to be continued

Here's something from the wiki that you don't see every day

 package require TclOO
 namespace import oo::*

hmmmmm.. I say lets give it the old college try

 namespace import oo::*

So now class, object, copy, define, objdefine, info, my, next, & self boldly venture together in the global namespace. Now I can immediately see the upside of the ::oo:: namespace. "copy" and "define" don't especially scream to one's intuition, "I'm here to orient objectation!"

Lets try a OO finger exercise:

  namespace import oo::*

  class create AClass
  set instance1 [AClass new]
  AClass create instance2
  #instance1 destroy           error!
  instance2 destroy
  AClass destroy
  class destroy

Okay, that's a little weird. Not sure why instance2 can be destroyed, and instance1 isn't as happy to do so. TO THE DOCS!

https://www.tcl.tk/man/tcl/TclCmd/class.htm

  cls new ?arg ...?
  Note that this method is not exported by the oo::class object itself, so classes should not be created using this method.

Ah! So, don't do that. It's available, but clearly it has issues, and we have been warned. [class create] & [cls create] it is. Learning is power!

Also, I haven't figured out how to recover from [class destroy]. If you are following along at home, you probably want to fire up a new interpreter.

An 00 classic:

 namespace import oo::*

 class create Counter {
   constructor {{num 0}} {
     variable count
     set count $num
   }
   method increment {{num 1}} {
     variable count
     incr count $num
   }
   method decrement {{num 1}} {
     variable count
     incr count -$num
   }
   method currentcount {} {
     variable count
     return $count
   }
   destructor {}
 }

 Counter create counter

 counter currentcount
 counter increment
 counter increment 5
 puts [counter currentcount]
 counter decrement
 counter decrement 3
 puts [counter currentcount]

wargarble