File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Big-shop conventions for js variables

 
Rick Goff
Ranch Hand
Posts: 54
Clojure Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I work in a large group of Java web app developers and we, of course, insist on descriptive variable names in our Java code. Many of my coworkers assume that this naming standard applies for all of the languages in our stack. But my opinion is that because almost all js variables are local - and their complete lifespan can be viewed within a single block - using brief names not just acceptable, but preferable, as it reduces noise. By the nature of functional code, the variable's significance usually is internal to the function, or to the larger mathematical context, rather than to the business concept reflected by the program's design.

What is your advice regarding naming conventions for javascript variables?

Thanks,
Rick
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The variable name's significance is so you know exactly what is going on without guessing what "foo" "bar" "count" is. I think it is more important in JavScript to have good names since the variables are loosely typed.

Who cares how long the names are. If you are worried about bytes, that is what Google Closure and other compressors are for.

jQuery's style guide: http://contribute.jquery.org/style-guide/js/
Crockford's: http://javascript.crockford.com/code.html
 
Rob Crowther
author
Ranch Hand
Posts: 297
5
Android Fedora Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I care. The longer they are, the more there is to type. And if you look at both style guides you linked to the variable names are all quite short ;)

Another style guide.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Crowther wrote:I care. The longer they are, the more there is to type. And if you look at both style guides you linked to the variable names are all quite short ;)

Another style guide.


They do not have to be a book. Plus you do not have a modern IDE that does auto-completion?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think names should be as long as they need to be.

But never, ever, ever shorten names by simply removing the vowels! Makes me want to scream.

I tend to use shorter names in JavaScript than, say, Java, but they are still descriptive and still real words.
 
Rob Crowther
author
Ranch Hand
Posts: 297
5
Android Fedora Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah I'm fine with abbreviating a local integer variable to i, a local string variable to s, a length to len, an object to obj, an event parameter to e and an entire library namespace to $, but don't go using TXTSPK in polite company
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic