Re: [FM3] Call syntax, positional and named parameters

2017-08-03 Thread Daniel Dekany
OK, it (see quoted mail, and
https://issues.apache.org/jira/browse/FREEMARKER-63) is partially
done, so insights are highly welcome! It's not yet merged, so see:

https://github.com/ddekany/incubator-freemarker/tree/FREEMARKER-63
https://github.com/apache/incubator-freemarker/pull/30

It works fully for directives (like macros), as per FREEMARKER-63.
(#function-s/methods is the next issue,
https://issues.apache.org/jira/browse/FREEMARKER-64)

The syntax is as it was described earlier, except "byName" and
"byPosition" was replaced with "named" and "positional":

   <#macro message text{positional}, color id=someDefault>...
   <#function message(text, color{named}, id{named}=someDefault)>...

and then you call it like this (as it was said much earlier):

   <@message 'Hello World' color='red' id='test' />

(You can't yet call function with named arguments. You can already
define functions with named parameters though.)

More examples:
https://github.com/ddekany/incubator-freemarker/blob/FREEMARKER-63/freemarker-core-test/src/test/java/org/apache/freemarker/core/TemplateCallableModelTest.java

As of the main API-s, the key interfaces are TemplateCallableModel and
its two sub-interfaces:

https://github.com/ddekany/incubator-freemarker/blob/FREEMARKER-63/freemarker-core/src/main/java/org/apache/freemarker/core/model/TemplateCallableModel.java
https://github.com/ddekany/incubator-freemarker/blob/FREEMARKER-63/freemarker-core/src/main/java/org/apache/freemarker/core/model/TemplateDirectiveModel.java
https://github.com/ddekany/incubator-freemarker/blob/FREEMARKER-63/freemarker-core/src/main/java/org/apache/freemarker/core/model/TemplateFunctionModel.java

One of the potentially controversial thing with them is that they use
a somewhat low-level way of argument passing, where all the arguments
are passed in a single TemplateModel array, and there's a
ArgumentArrayLayout that describes which parameters go to what indexes:

https://github.com/ddekany/incubator-freemarker/blob/FREEMARKER-63/freemarker-core/src/main/java/org/apache/freemarker/core/model/ArgumentArrayLayout.java

This is for efficiency (we avoid building Map-s on runtime, and just
create an array, and can also do some of the grinding later without
HashMap lookups and string comparisons, with simply reading array
items from know (constant) indexes. It isn't the most user friendly
API to implement for sure (but the majority users don't implement
FreeMarker directives/function in Java anyway - it's power user thing
mostly), though I have implemented a few directives and functions with
this, and it's not that bad after doing the same with FM2,
particularly because with named arguments you don't have to deal with
unknown names anymore, or write those switch-by-String statements (or
worse, Map.Entry loops before Java 7). Anyway, later I plan to add
some utility for defining directives/function with annotated static
methods, so it can be much more friendly if it has to.

Calling a TemplateCallableModel from user Java code is a much more
inconvenient thing though, as then you are responsible for setting up
the argument array as per the provided ArgumentArrayLayout. Luckily,
that's done very rarely by users (and can also be supported with some
utility methods if really needed). After all, FreeMarker
directives/function are to be called from templates, otherwise you
just use plain Java methods.

See also some more smaller changes here:
https://github.com/ddekany/incubator-freemarker/blob/FREEMARKER-63/FM3-CHANGE-LOG.txt


Wednesday, July 5, 2017, 10:00:26 PM, Daniel Dekany wrote:

> Something from the first mail of this thread that I want to emphasize
> is that which parameter needs to be passed by position and which by
> name is decided when the directive or function is defined. It's not
> decided by the caller (see reasons below).
>
> For example, the 1st parameter of #include can only be passed by
> position, as in `<#include "foo.ftl">`. You can't write
> `<#include template="foo.ftl">`. However, the `ignoreMissing`
> parameter (and in FM2 we also had `encoding` and `parse` parameters)
> can only be passed by name, as in
> `<#include "foo.ftl" ignoreMissing=true>`. You can't write
> `<#include "foo.ftl", true>`.
>
> Some may have used languages where the caller decides what is passed
> by position and what by name, but IMO it just leads to chaos in our
> case. I also realize and accept that everybody has different taste,
> but people read/edit other people's code a lot, so the taste of the
> original author often doesn't matter much. Plus if someone overuses
> positional parameters (laziness/rushing and C/Java habits may make
> people do that...), the template becomes less readable, especially for
> someone less experienced with writing templates. Consistency regarding
> how core directives are called is even more valuable, as people
> copy-paste it from StackOverflow etc. Imagine if in some cases you see
> `<#if test=foo>`, while in others <#if foo>... conf

[PPMC] Re: Proposed policy change: Don't require CLA from contributos

2017-08-03 Thread Daniel Dekany
Dear PPCM members, please tell me if you agree, or there's any problem.

John D. Ament had some concerns (see his "Is Freemarker becoming too
process heavy?" thread), but he didn't follow through when I asked
back.

Anyway, why I want this is that even if very rarely, sometimes we get
very trivial contribution like this recently:
https://github.com/apache/incubator-freemarker/pull/29
If I will ask the guy to send a ICLA, you know... I'm certain that if
I just merge such things without any of you agree, Legal can't say a
bad word, but still, I would prefer if you say something.


Wednesday, June 21, 2017, 12:47:12 PM, Daniel Dekany wrote:

> Currently we strictly require a CLA (by which I mean an ICLA or CCLA)
> for any contributions to be accepted, as
> http://freemarker.org/contribute.html says.
>
> This practice was inherited from the pre-ASF times, when without
> lawyers available, we tried to be on the safe side. But based on
> https://issues.apache.org/jira/browse/LEGAL-156 and
> https://wiki.apache.org/couchdb/CommitPolicy and some other mails we
> can make things simpler for contributors (not to be confused with
> committers).
>
> So I propose that we say that:
>
> - People sending contributions with GitHub pull requests need no CLA.
>   But, before merging, we must check that:
>   - The mail about the pull request was received to
> notificati...@freemarker.incubator.apache.org, so that there's
> a record of this even in the ASF infrastructure.
>   - The files in the pull request has the standard ASF copyright
> headers, or no copyright headers in files where that's normally
> not present. There's no other conflicting copyright information
> included either (like a such LICENSE file).
> - People sending in patches as attachment to FreeMarker Jira issues
>   need no CLA. But, before merging, we must check that:
>   - It's clear from the wording of the issue that the user wishes to
> contribute (as opposed to, for example, just showing an example).
>   - Copyright headers are in order, just as with GitHub pull request.
>
> If someone contributes a bigger feature, yet they isn't a committer,
> we might still ask a CLA though. But that can be dealt with when such
> thing happens.
>

-- 
Thanks,
 Daniel Dekany