Name of coding pattern

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Name of coding pattern

Kasper Osterbye
Hi.

I was looking at the zink stream, and noticed this pattern with 

strm tag: 'h1' do: aBlockWhichWriteTheTitle

It is also used in baselines, and I have used it myself a few times.

Is anyone aware of this having a name? 

Best,

Kasper
Reply | Threaded
Open this post in threaded view
|

Re: Name of coding pattern

Richard O'Keefe
In my library it would be
  strm
    tag: 'h1';
      do: aBlockWhichWritesTheTitle;
    end.
because one so very often needs to add attributes and/or a namespace.
#tag:do: is related to the C++ "Resource Allocation is Initialisation"
pattern, where the point is to automatically clean up.  In RAII, the clean
up is to release a lock or free a resource.  In this case, it is to write
an end-tag.  In a similar way, it is related to the Common Lisp with...
pattern, where (with-open-file (variable filespec option...) body...)
ensures that the file is closed, to unwind-protect, and of course to the
#critical: method on Semaphores, Mutexes, &c.

I don't know if there is an official name other than RAII;
I've always thought of it as "automatic cleanup".  The difference
between this and #ensure: or try-finally or unwind-protect is that
in those you have to say what the clean-up action is while in this
it is implicit.

On Wed, 27 May 2020 at 01:52, Kasper Osterbye <[hidden email]> wrote:
Hi.

I was looking at the zink stream, and noticed this pattern with 

strm tag: 'h1' do: aBlockWhichWriteTheTitle

It is also used in baselines, and I have used it myself a few times.

Is anyone aware of this having a name? 

Best,

Kasper