Ayende @ Rahien

Unnatural acts on source code

Brail: Null propagation

Here is a small, but interesting tidbit. Yesterday I have finally sat down and documented a lot of the changes that I made in Brail recently, I was surprised to see how much I had to document:

  • Auto Imports
  • Strongly typed variables
  • Sections
  • The "?variableName" syntax
  • Symbols
  • Null Propagation

The last part is what I want talk about now. Brail is a .Net language, which means that something like this:

output user.Parent.Name

will raise NullReferenceException if the user's parent is null. That can be somewhat of a pain in many scenarios. Brail now has a better syntax for this:

output ?user.Parent.Name

 will ignore any null values that it encounter in the way. It is will either output the parent's name or nothing at all.

The small print:

This will work only for variables that you get from the controller via the PropertyBag or Flash. You can't use it on variables that you define in the view. However, that is rare enough that I don't think that it is going to be a problem.

Note that I didn't document the DSL support in Brail yet, that is going to wait until it is stabilized a bit.

Comments

Mats Helander
07/15/2007 02:58 AM by
Mats Helander

?user.Parent.Name

Nice one! :-)

http://www.visual-design.se/blog/posts/200411251000.asp

/Mats

goodwill
07/16/2007 02:29 AM by
goodwill

Finally you have time for this :) May I have a url? Its on your wiki?

Bill Pierce
07/16/2007 01:08 PM by
Bill Pierce

Was this code comment documentation or something you put on the Castle Wiki? Just wanted to check it out and give it a read.

Ayende Rahien
07/16/2007 03:49 PM by
Ayende Rahien

It is an update to Castle's Docs.

It should be here:

http://www.castleproject.org/monorail/documentation/trunk/viewengines/brail/index.html

But I don't see my changes, let me check that.

hammett
07/17/2007 05:54 PM by
hammett

Changes are being held for now, at least until the RC3 is finally announced.

Comments have been closed on this topic.