Getting there...
A valid solution for me is to "Drop the key from the context if the value is null".
"Geir Magnusson Jr." wrote:
>
> Christoph :
> > My experience shows me these situations where a NULL can happen.
>
> > a) The template designer has written an invalid identifyer:
> > #set( $foo = $bar.woobie )
> > where getWoobie() does not exists. here it is sufficient that
> > its logged...
>
> Yes, that will be logged. It is actually checked before it's shoved into
> the context, so the only issue there is that $foo is still not in the
> context if it wasn't, or unchanged if it is. Maybe to support the semantics
> of 'no null references' we just remove $foo from the context ?
If you make 'no null references' configurable some others will scream,
saying this will counteract velocimacro libraries...
>[snip]
> right. Hm. Maybe if you do what amounts to a #set( $foo = <null value
> returned from something> ) then we remove $foo from the context if it is
> there? That would support the semantics, be predictable, etc.
+1
> This strikes
> me as a little yecchy though, somehow, although in some ways clean : there
> are no null objects in the context.
It seems clean from the context point of view: Context is a list of
objects accessible by a name (key). NULL is not a object, therefore
cannot be in the context. Setting something to NULL, removes the key
from the context.
> It also makes the proposed addition of
>
> #if( $foo == NULL )
>
> as a not-a-reference check clean.
+1 if the context cannot contain nulls, otherwise #if( $foo == $NULL )
Note that the access to nonexistent $foo in a production environment
should not emit any log messages, as 2) in your proposal (this thread).
>[snip]
> >Somebody already said in this list "NULL is your friend".
>
> That was Jose or Daniel, I think. I don't quite get why though. I do in
-------------------^^^^^^
> Java, but in template land? I guess one will be able to find uses, but if
> you formalized things from the Java side by adding booleans to tell you
> about valid data... I dunno. That's extra work. Just hoping to get things
> clean, and describable in documentation in as few lines as possible.
And with the clean definition (see above) of the Context API, I agree
we can avoid having NULL context keys and values. Keys make no sense
and NULL values are avoided by removing the key!
:) Christoph