aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Big-shop conventions for js variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Big-shop conventions for js variables" Watch "Big-shop conventions for js variables" New topic
Author

Big-shop conventions for js variables

Rick Goff
Ranch Hand

Joined: Nov 14, 2006
Posts: 54

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


OCPJP 6
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Nov 06, 2012
Posts: 295
    
    5

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.


Read my books: Hello! HTML5 & CSS3 | HTML5 in Action | Read my blog
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jan 10, 2002
Posts: 61206
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rob Crowther
author
Ranch Hand

Joined: Nov 06, 2012
Posts: 295
    
    5

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Big-shop conventions for js variables