freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Dekany (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FREEMARKER-21) Reference to the object in condition - avoid repeating the same in #if and ${...}
Date Mon, 13 Feb 2017 09:32:41 GMT

    [ https://issues.apache.org/jira/browse/FREEMARKER-21?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15863386#comment-15863386
] 

Daniel Dekany commented on FREEMARKER-21:
-----------------------------------------

In {{(foo as bar)!"Hello!"}} the assignment to {{bar}} simply wouldn't happen, since evaluating
{{foo}} basically causes an exception which is then handled by the {{(...)!exp}}. Confusing,
I know, but the intended use is the opposite, that is, we use the `as`-ed (or, well, `into`-ed)
variable when its left side has existed.

As of handling missing values in FreeMarker, the problems of it (particularly when it comes
to assigning things) are known, but I don't think we can do much about it in FreeMarker 2.
It was made like this 14 years ago or so, and you simply can't break backward compatibility
that much in 2.x, because that means that tons of projects can't update FreeMarker anymore.
That's why FreeMarker 3 was started not long ago, and there the point is to move into another
package (so it doesn't interfere with FreeMarker 2) and break backward compatibility and do
what's right. But if 3 ever comes out one day, FreeMarker 2 will remain with us for a long
time...

> Reference to the object in condition - avoid repeating the same in #if and ${...}
> ---------------------------------------------------------------------------------
>
>                 Key: FREEMARKER-21
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-21
>             Project: Apache Freemarker
>          Issue Type: New Feature
>          Components: engine
>            Reporter: Ondra Žižka
>
> Repeating stuff is annoying, especially in programming.
> Therefore this is annoying:
> {code}
> <#if someVariable.someMethod.someProperty??>
> <div>${someVariable.someMethod.someProperty}</div>
> </#if>
> {code}
> This would be better:
> {code}
> <#if someVariable.someMethod.someProperty?? as value>
> <div>${value}</div>
> </#if>
> {code}
> Not talking about the fact that it could only be evaluated once.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message