views:

70

answers:

2

VBScript guarantees that the GC will run after every line, so if you create an object and don't keep a reference, its destructor will be called at the end of the line. This allows you to do a number of interesting things, one of which is simulating optional arguments:

with foo(mandatoryArg)
    .optArg = 42
end

Another is allowing for a convenient builder syntax:

with Schema.define("Foo")
    .attr "name", String

    with .attr "key", String
        .lengthEquals(10)
    end
end

In this example, define and attr return objects that finalize the schema and attribute definitions in the destructor.

I've been calling the temporary object an ephemeron, but I was wondering if there was a preexisting term for such constructions. Anyone seen this elsewhere?

+1  A: 

According to Builder pattern in wikipedia this is the builder or more specifically the concrete builder. In practice these objects are usually short lived. The builder pattern has a few components including the director, etc. But this short lived object you are calling an ephemeron seems to be precisely the builder object.

harschware
A: 

You're definitely using a builder pattern. The abuse of GC is new, though. The more general name for the type of syntax you're building is a fluent interface.

You could achieve something similar in C# with the "using" syntax, but in practice people use lambda expressions for this, which are more clear.

Julian Birch