[e-lang] Naming convention for variable holding an eventual reference
david.hopwood at industrial-designers.co.uk
Fri May 16 10:13:37 CDT 2008
David-Sarah Hopwood wrote:
> Sandro Magi wrote:
>> 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 :-)
>> $ 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
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.
// Send a POST request to increment the counter...
drum$.post('bang', [ 1 ])
Doesn't look too bad, if a bit more visually noisy than _.
- ideally we want a convention that can be used across several languages,
Most languages, following the Unicode identifier recommendations (or
something more restrictive), do not allow '$' after the first character.
conflicts with a convention used in Prototype and several other libraries
for getting DOM nodes.
More information about the e-lang