PROPOSAL: Named method parameters
Paul Martin
paul.martin at gmail.com
Sun Mar 22 05:57:53 PDT 2009
Hi,
In reply to Howard Lovatt (who proposed a simpler syntax for creating
classes):
Your suggestion does seem interesting, but I have a few of questions:
- Would it be possible for the compiler or a tool like Findbugs to ensure
that all of the Args members had been set? Your example allows default
values to be easily defined, but I don't think that the language can
(currently) determine that name would always be set (if it didn't have a
default). This was really one of my main arguments agaist the Builder
pattern (which your proposal seems to refine).
- Would the overhead of effectively creating a new anounymous inner class
for every method invocation be significant?
- In the general case, does this make the programmers intent clear - is
passing an Args-style object effectively the same as just using named
parameters directly? On the other hand, when my main desire is to use such
parameters when constructing immutable object, then perhaps the distinction
is moot.
- Is this approach effectively the same as that suggested earlier by Florian
Weimer, who noted that "Standard ML kind of solves the issue by having a
lightweight syntax for constructing record values"?
- How are JavaFX named parameters used/implemented? From what I can see,
they are only used in object constructors, so perhaps they work in a similar
way to your suggestion, though perhaps subclassing the class being
constructed directly (rather than subclassing an argument class). I suppose
the limitation with this (if that is correct) is that it might be harder to
use static factory methods (though argument classes could then be used I
expect).
In any case, if named parameters are not implemented, I certainly think that
your simpler Args class could be used in many cases instead of the more
complex Builder.
Regards,
Paul
More information about the coin-dev
mailing list