I honestly can't think of any, except in regular expressions.
There's no potential for ambiguity in those.
Indeed, I'm very concerned about code maintainability. In this
case, however, I don't really see the problem.
I admit I've been using a $() function myself, long before
jQuery and the new host of JS libraries entered the game.
I saw it in an early release of Prototype.js, and after
confirming that it was indeed syntactically fine, I decided
to borrow the idea.
As have so many others (and I don't think it originated with
Prototype.js, though that library may have popularised the idea). One
of the consequences of using an explicit, meaningful Identifier (in
writing self-documenting code) is that you only see naming collisions
if you have to functions (methods/object, at the same 'level') that do
the same thing (at which point one of them is redundant and can be
removed). The use of non-meaningful and short/'convenient' Identifiers
in non-restrictive scopes directly leads to a high risk of naming
collisions, hence JQuery's 'no conflict' stuff (and associated
additional hoops to be jumped through).
Trends suggest an increasing frequency of web contexts where code
originating from multiple independent sources is going to find itself
being imported into single documents, and so find its self sharing a
single global object. In that context it becomes absurd to be choosing
a short/'convenient' Identifier as your code's exposed public entry
point.
My version isn't much more than a glorified wrapper for
document.getElementById (no CSS selectors or other magic),
and it's not exported by default - you'd have to do something
like 'var $ = LibraryName.byId'. The only problem I can
see here is that (today) people would probably assume $ to
be an alias for jQuery.
That would probably depend on the depth of their experience. The more
experienced should know not to assume anything from a $ identifier. On
the other had, anyone seeing - .getElementById - with and appropriate
argument, and making the obvious assumption will not be wrong often
enough to worry about doing that.
I can live with that.
I also use $identifiers to mark global variables from external
sources. For example, an included script could require a value
that can only be provided by the current server-side language.
Then there'd be a <script> element with something like
'var $USER_HOME = "/home/thomas"' in the PHP or JSP file, and
these external constants will immediately stand out when you
read the script.
That is pretty much the standard example of using the $ symbol to mark
mechanically generated identifiers (it is more like mechanically
initialised variables, but is still a useful way of flagging the
origins of the value stored by the variable).
The passage about "mechanically generated code" in the specs is
vague enough to be practically useless.
That depends. It does state why the $ symbol was included in the set
of characters that are allowed in an Identifier when it could just as
easily have been omitted.
By the way, none of the available minifiers (that I know of)
add dollar signs when they replace identifiers.
Why would they? Adding characters is hardly going to contribute
towards minimisation.
That would have been the intended
use case of the dollar-identifiers,
Not "the intended use case", rather one possible use case, if it was
not directly at odds with what minifiers are supposed to do. Remember
that facilitating an abilty to indicate mechanically generated code
does not then make a requirement to use that facility with all
mechanically generated code.
The case you mentioned above is a much better example; where the $
symbol is telling you that if the value stored is at odds with what
you were expecting then it is the server-side code that needs looking
at rather than the client-side.
but it hasn't caught on, and so the
suggestion was dropped in ES5.
It was almost certainly not its use (or non-use, if we accept "hasn't
caught on") with machine generated code that provoked the change in
ES5. After all, how could the ECMA committee know the extent to which
the $ symbol is or is not used in mechanically generated code?
It is much more realist to suppose that the ECMA committee observed
that the $ symbol had been employed in numerous 'popular' libraries,
was then in widespread use for a huge variety of other reasons (and
suggested meanings), and so recognised that the ability to employ it
to signify mechanically generated code had been neutralised. Basically
a recognition that the horse had bolted, and given that there was no
longer any point in keeping a stable for it.
I can perfectly understand that some people don't like '$'s
in their identifiers. I'm usually as diplomatic as I can be, but
when the topic is code style preferences, I can be as fascistic
as any other full-time developer
The way I see it, '$'s don't
cause problems, and they can be useful as a convention to denote
"special" cases, so I use them. Others don't.
<snip>
The problem with 'special cases' is that there are many, and they
start to risk overlapping as their number increase. Apparently JQuery
developers, for example, have been encouraging the use of a leading $
symbol to indicate a variable or property name that holds a reference
to a JQuery object (the object returned from calls to - $() -). That
doesn't seem such a bad convention in the context of JQuery code.
Another suggested convention was to use a leading $ symbol to indicate
variable that held string values (apparently inspired by the syntax of
some other programming language, and proposed by an individual who
couldn't see that some of the values he was assigning to these
variables were actually numbers, undermining the notion form the
outset). VK proposes a 'convention' where a leading $ symbol get used
in property names (but not in any sort of consistent way over time).
In any single context any one such convention can be usefully
employed, but try mixing them together and the outcome is that each
becomes useless on it own and acts to confuse developers more familiar
with any other.
The thing that worries me here is that we have an OP who should have
been seeing ordinarily function/method calls in the code he posted but
was instead seeing (apparently undocumented) syntax extensions for
defining "classes" and "packages". It is difficult to see the $
symbols used in that code as not contributing to the misperception.
Richard.