[e-lang] Naming convention for variable holding an eventual reference

David-Sarah Hopwood david.hopwood at industrial-designers.co.uk
Fri May 16 10:13:37 CDT 2008


David-Sarah Hopwood wrote:
> Sandro Magi wrote:
>> I believe JavaScript allows $ in names. The following are all valid 
>> identifiers from my tests:
>>
>> var $tmp;
>> var tmp$;
>> var $tmp$;
>> var $t$mp$;
>> var tmp_$;
> 
> Yes, although you should be looking at the spec *as well as* testing :-)
> <http://www.ecma-international.org/publications/standards/Ecma-262.htm>
> 
>> $ seems like a fairly recognizable symbol, particularly as a suffix.
> 
> Section 7.6 of ECMA-262 3rd ed. says:
> 
> # [...] The dollar sign ($) and the underscore (_) are permitted
> # anywhere in an identifier. The dollar sign is intended for use only
> # in mechanically generated code.
> 
> OTOH, that intention is widely flouted, e.g. by libraries such as
> Prototype.

Based on <http://waterken.sourceforge.net/bang/>:
----------
// Turn the URL for the current page into a remote reference
var page$ = $.connect(window.location.toString())

// The test page is a factory object for constructing a
// org.waterken.bang.Drum object. A Drum is just a counter object that can
// be incremented. We'll create a new Drum by invoking the factory method.
var drum$ = page$.post('subject', [])

// By convention, the name of a variable holding a promise is suffixed
// with an '$' character. When following this convention, you can recognize
// ansynchronous operations by looking for the '$.' character sequence.
var hits$ = drum$.get('hits')

// Since I'm just typing in an interactive shell, the response to the GET
// request sent above will already have been received and processed by the
// time I hit the 'Enter' key.
hits$

0

// Send a POST request to increment the counter...
drum$.post('bang', [ 1 ])
----------

Doesn't look too bad, if a bit more visually noisy than _.

However,
  - ideally we want a convention that can be used across several languages,
    including E, Java/Joe-E, Emily, etc. as well as subsets of Javascript.
    Most languages, following the Unicode identifier recommendations (or
    something more restrictive), do not allow '$' after the first character.

  - in Javascript, using just '$' as the name of the "eventual operator"
    conflicts with a convention used in Prototype and several other libraries
    for getting DOM nodes.

-- 
David-Sarah Hopwood


More information about the e-lang mailing list