Re: Naming convention for variable holding an eventual reference

"Tyler Close" <[email protected]>
Newsgroups gmane.comp.lang.e.general
Message-ID <[email protected]>
On Fri, May 16, 2008 at 3:07 PM, Raoul Duke <[email protected]> wrote:
>> Q.post(drum, 'bang', [ 1 ])
>
> From the perspective of a newbie looking at code which uses that
> style, it sure uses an awful lot of "Q.fn(" everywhere which looks to
> make the code less readable (if perhaps more robust in other ways).
> Not that I have a constructive alternative to offer.

Ya, that bothers me too. It can be made a little better by adding the
following preamble to your Javascript file:

var post = Q.post;
var get = Q.get;
var when = Q.when;

The code then becomes:

var page = Q.connect(window.location.toString())
var drum = post(page, 'subject', [])
var hits = get(drum, 'hits')

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

when(get(drum, 'hits'), function (value) {
  print(value);
}, function (reason) {
  print('rejected: ' + reason);
})

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

Just removing most of the capital Q's, seems to be a lot less
distracting. I suspect this can't be the default though, because
adding lots of variables to the global Javascript scope is frowned
upon.

--Tyler
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.