Naming convention for variable holding an eventual reference

View: New views
3 Messages — Rating Filter:   Alert me  

Naming convention for variable holding an eventual reference

by David Wagner-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.
_______________________________________________
e-lang mailing list
e-lang@...
http://www.eros-os.org/mailman/listinfo/e-lang

Re: Naming convention for variable holding an eventual reference

by Karp, Alan H :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

David Wagner wrote:
>
> 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.
>
I don't have any problem with the inversion.  Programmers are used to seeing code evaluated from the innermost nested parens out.

________________________
Alan Karp
Principal Scientist
Virus Safe Computing Initiative
Hewlett-Packard Laboratories
1501 Page Mill Road
Palo Alto, CA 94304
(650) 857-3967, fax (650) 857-7029
http://www.hpl.hp.com/personal/Alan_Karp

_______________________________________________
e-lang mailing list
e-lang@...
http://www.eros-os.org/mailman/listinfo/e-lang

Re: Naming convention for variable holding an eventual reference

by Sandro Magi-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Karp, Alan H wrote:
> David Wagner wrote:
>> 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.
>>
> I don't have any problem with the inversion.  Programmers are used to seeing code evaluated from the innermost nested parens out.

Yes, method chaining is an object-centric viewpoint.
Functional/procedural code always looks like that.

Sandro
_______________________________________________
e-lang mailing list
e-lang@...
http://www.eros-os.org/mailman/listinfo/e-lang
LightInTheBox - Buy quality products at wholesale price