Re: [FreeMarker-user] Ideal tag syntax; what's your take on it?
Denis Bredelet <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.devel,gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
> Friday, June 10, 2011, 1:34:17 AM, Daniel Henrique Alves Lima wrote:
>
>> Daniel Henrique Alves Lima wrote:
>>>
>>> My answers were mostly useless :-|
>>>
>>> I'm not particularly comfortable with the syntax of JSP and GSP:
>>>
>>> http://www.grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.2%20Groovy%20Server%20Pages
>>>
>>> <img src="<g:createLinkTo dir="images" file="logo.jpg" />" />
>>>
>>>
>>> But is there a better way of writing a call to a function using named parameters/args?
>>>
>>>
>>> <img src="${createLinkTo(dir:'images', file:'logo.jpg')}" />
>>>
>>>
>>>
>>
>> <img src="${createLinkTo dir:'images', file:'logo.jpg'}" />
>>
>> <img src="${createLinkTo file:'images/logo.jpg'}" /> (it's not a syntax problem)
>>
>>
>> ?
>
> You mean parenthesisless calls? Those can look cute, but they have a
> great potential to cause headaches for the language designer (or for
> the user). Like, this:
>
> ${foo -1}
This is not a call with named arguments. I think ${foo age: -1} is fine, but without arg name you should use ${foo(-1)}.
Personally I don't mind the brackets around variables, ie. I don't have a preference for $bar over ${bar}. In fact syntax consistency helps spotting variables in the midst of text.
The real advantage of Velocity syntax is that it uses line-ending as a delimiter. That sometimes complicates white space handling but it is visually nicer.
> How FTL is still similar to SGML:
>
> - You have to add a "/" to each empty-directive tag ([@foo /]), but
> you don't have to add anything if nested content follows
> ([@foo]...). Isn't that anti-intuitive and often inconvenient?
> Nothing but SGML has this strange upside-down logic (I think).
>
> Also, to complicate things... there are those who are more equal
> than others. For a built-in directive you can write something like
> [#assign x = 1] instead of [#assign x = 1 /], since FreeMarker knows
> if they can have nested content or not.
In my opinion the issue is not with the closing of an empty directive, but with the end of directive syntax. The slash is short (1 character) but cryptic, it is not clear it means "end". My suggestion is to introduce an alternative syntax. Maybe:
[@foo @end]
[@foo]
[@end]
Equivalent to [@foo][/@]
(May need to use #end instead of @end because the latter is valid directive name AFAIK so it wouldn't be backward-compatible)
>
> - You don't have to put comma between named arguments. In SGML you
> have to quote non-trivial attribute values, so it isn't an issue
> there, but I don't think any sane modern *programming* language
> would do this with named arguments. [@foo x = a + 1 y = b + 1] is
> just horrible. Luckily, you can write [@foo x = a + 1, y = b + 1] in
> FTL, but you don't have to. (As a side note, we also have
> ambiguities because of this: <@foo x = a! y = 2> will be parsed as
> <@foo x = a!(y == 2)>. Yeah, part of this is that FTL allows "="
> instead of "==". That was a mistake too...)
I like using "=" instead of "==". But for named arguments, you could replace x = a with x: a if you don't care about being SGML-like. It would be nice in fact.
-- Denis.
------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev