When I was playing with template field substitution last couple of days, I was again reminded that the common Smalltalk substitution syntax (John Brant informs me that it is indeed in more than just VisualWorks and Squeak) is really frustrating to use for any sort of HTML/XML generation. The use of the < and > means you have to constantly escape those characters in your templates if you are generating any kind of output that you actually want to include the alligator brackets.
And a thought occurred to me. As long as I'm not generating HTML or XML, I couldn't think of a better field identifying character to use. There are some others such as { } or [ ] that work visually as well. But for the last 15+ years, we've all been reading more and more and more of the "when Lisp met alligators" syntax. It's been pounded mercilessly into our brains. We've all gotten quite accustomed to parsing, in our heads, the text shows up between brackets, apart from the rest. Because of that, using them as field identifiers, is actually the best thing possible.
It's the meta that's the achilles heel. When you want to use these same field separators to generate other field separators. In other words, I could posit that if HTML/XML had used { } to enclose tags, we'd find ourselves appreciating it in a substitution syntax the most, and hating it most when we tried to use it to generate more of the same.
Some weeks ago i ran into Mustage: http://mustache.github.com/.
ReplyDeleteMustage is a template engine where placeholders, by default are put into double curled brackets like in {{tag}}. I think that's quite a clever idea, as double-brackets are rarely used anywhere else.
Mustage even allows the use of different characters (check the Set Delimiter section in the man page, linked on its website).
After many years with VA I got used to...
ReplyDelete'change %1 to %2' bindWith: 'first' with: 'second'
...and ended up porting it to VW and GS.
For text substitution, I'm a real fan of the EvaluableString library, which Lukas Renggli wrote a while back. It's like:
ReplyDelete'my name is {self name}' evaluate. Very easy to read and perfect for generating error messages and what have you for web sites. I really think it should be added as an extension to the standard libraries.