proposal: provide shorter 'on()' as a synonym for 'callsTo()'

12 views
Skip to first unread message

kbwelker

unread,
Aug 5, 2012, 5:34:29 PM8/5/12
to Funcito
I was asked to make a comparison between Funcito and LambdaJ in an
issue recently. When I was doing so, I noticed that their mechanism
which is similar to what Funcito does for proxying uses the very
concise "T on(T t)" in place of my "T callsTo(T t)". I then very
shortly noticed the same naming convention ("on()") in another
framework (unrelated to functional programming) which also creates
proxy objects.

One of my major goals is to let Funcito be as little in the way as
possible, as brief as possible, as little noise as possible. As I was
typing out example code for the Wiki pages, I kept getting bothered by
the repeated "callsTo()" noise, when I knew other frameworks had
limited that down to "on()".

So I was wondering whether there were any opinions on whether to
introduce "on()" as a synonym for "callsTo()". I don't want to
clutter the API, but it is still *very* simple at this point. I'm
thinking I would leave both in without deprecating the other, because
I can imagine some folks would still prefer the way "callsTo" reads.

kbwelker

unread,
Aug 9, 2012, 2:33:56 PM8/9/12
to Funcito
building on the previous thought, "on( )" is shorter but doesn't read
great with the current builder methods:

functionFor( on(MyClass.class).theMethod() );
doesn't read as well as the current:
functionFor( callsTo(MyClass.class).theMethod() );

So I was wondering whether to introduce a whole new preferred API
anyway. Here are some of the options, in roughl order of my
preference at the moment:
********
functionTo( use(MyClass.class).theMethod() );
vs:
makeFunction( on(MyClass.class).theMethod() );
vs:
functionTo( wrap(MyClass.class).theMethod() );
vs:
makeFunction( for(MyClass.class).theMethod() );
vs:
makeFunction( around(MyClass.class).theMethod() );
vs:
makeFunction( toWrap(MyClass.class).theMethod() );


I am also trying to consider the semantics when not used with the
inline call. In other words, is there a meaningful brief naming
convention that a user could name the resulting proxy object?
Currently if not inlining "callsTo( )" user could do something like:

MyClass CALLS_TO = callsTo(MyClass.class);
// above name is meaningless on its own
// but below it becomes readable (only) in its usage
functionFor(CALLS_TO.theMethod());
or
MyClass MYCLASS = callTo(MyClass.class);
// above name is more meaningful than previous example
// and usage below is pretty readable
functionFor(MYCLASS.theMethod());

Are there readable substitutes for any or all of the above proposed
options for an alternate terser API?
The first option (my favorite) could use:
MyClass USE_MYCLASS = use(MyClass.class);
functionTo(USE_MYCLASS.theMethod());
I find both the proxy name and usage very readable.

kbwelker

unread,
Aug 17, 2012, 12:59:27 PM8/17/12
to Funcito
Before I would make any possible API switch, I want to further
evaluate the possibility of wrapping static methods because I had
initially thought of doing that as:

functionFor( staticCallsTo(MyClass.class).someStaticMethod() )

Not sure what changed API would look like for this... maybe:

functionTo( useStatic(MyClass.class).someStaticMethod() )

kbwelker

unread,
Aug 17, 2012, 1:03:08 PM8/17/12
to Funcito
I thought of another even shorter API:

functionTo ( do(MyClass.class).theMethod() );

This may be my favorite.
Reply all
Reply to author
Forward
0 new messages