Naming convention for variable holding an eventual reference

David Wagner <[email protected]>
Newsgroups gmane.comp.lang.e.general
Message-ID <[email protected]>
Tyler Close writes:
> Instead of making Javascript promises directly invokable, as in:
> 
> drum_.post('bang', [ 1 ])
> 
> we make all eventual invocations via a global object, so:
> 
> Q.post(drum, 'bang', [ 1 ])
> 
> The 'drum' reference can be either a promise or an immediate
> reference; either way, the invocation is still an eventual invocation.
[...]
> I think the last line is the only one that presents a significant
> concern. In the current syntax, it's:
> 
> hits_ = drum_.post('bang', [ 3 ]).get('hits')
[but in the proposed new syntax it's:]
> hits = Q.get(Q.post(drum, 'bang', [ 3 ]), 'hits')
>  
> This inversion happens to the whole chain of calls in the statement.

I haven't been following this too closely, but would the following
be any better?  Javascript promises wouldn't be directly invokable,
but must be passed in a call to a global function Q to obtain an
object that can be directly invoked, like this:

  Q(drum).post('bang', [ 1 ])

The problem line at the end of your post becomes

  hits = Q(Q(drum).post('bang', [ 3 ])).get('hits')

Is this any better?

This variant doesn't provide a naming convention on the variables
themselves, only a special syntax at the place where those variables
are used -- just like your proposal.  The only advantage of this
variant over your proposal is that this variant avoids the inversion.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.