Reasoning behind the default jQuery alias ($)

I've been thinking a lot about the way that jQuery is implemented in Javascript code. Libraries such as jQuery and Prototype bind to an alias by default; for these examples, they use the dollar sign $. (Underscore, appropriately, uses an underscore character _.)

I understand how this works. I also understand that many libraries provide a noConflict mode.

My question is, why do these libraries use an alias by default?

From what I've seen, aliases like these only seem to let a programmer type less characters when calling a function, which seems trivial. (Honestly - I'm a little biased, because I don't have issues typing long variable names.) I thought that maybe it was for filesize purposes, but with the proliferation of minifiers, it seems like it'd be a moot point (and a form of premature optimization).

On the flip side, the aliases seem to cause a lot of confusion for people using these libraries.

Now, I'm not really arguing against the use of aliases - I'm just wondering why it's the default option for these libraries. Currently, to avoid an alias, we explicitly have to declare that we don't want to use it. Are there specific benefits that I'm missing about the use of aliases for library calls? The only advantage that I could readily think of is if you somehow wrote cross-library code - to swap libraries, you simply swap the alias. I don't think I've ever seen this done, though.

Anyone know the reasoning behind this? I, for one, would really love to know.


"From what I've seen, aliases like these only seem to let a programmer type less characters when calling a function, which seems trivial."

That's what the people who designed VB thought too. "What's this

for (int i=0; i<10;i+=2){

Stuff! What's wrong with:

For i as Integer = 0 To 10 Step 2
Next i 

So I save 13 keystrokes! That's trivial."

It's not trivial when this is what we do all. day. long.

Take the jQuery Cycle plugin: It has 400 instances of $. If you were to use jQuery instead of $, that would be an extra 2000 keystrokes. It's the reason why IDEs now perform autocomplete of parens, etc. etc. etc.

Using jQuery and Prototype together is not good idea. Ideally there must be only 1 javascript framework for the site, and a lot of calls to it. So the best (default) choice is to use shorthand alias for it's main function.

Anyway, if you need to use several libraries/frameworks together on the same page, and you want to avoid conflicts, you can use noConflict mode.

Need Your Help

How to move cursor position in Delphi StringGrid cell?

delphi tstringgrid

When you have a TStringGrid with the goEditing option set and a cell has several lines of text in it, when you go to edit that cell by clicking on it, the cursor will be at the very end of that tex...

Crystal Reports for VS won't connect to SQL on Windows 10

c# sql-server crystal-reports windows-10

I'm using Crystal Reports SP 13.0.17 for VS 2010 (also tried with VS 2015) and ODBC for SQL Server 2014. When I run my program (passing an external report), I get a login dialog for the database, e...