• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question about something that has been annoying me.

 
Brian Fenno
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to Java and Javascript(which i know is kind of unrelated to Java but it is to my question". Sooo, why do seemingly random function names and variables in the Head First books as well as one in the Java API have every word after the first capitalized(hopefully you know what I am talking about)? And then others have everything lowercase. It's really annoying because I'm used to having everything lowercase because I end up making more mistakes when I start capitalizing function names and variables. I'm just curious to know the naming conventions you more experienced programmers use, and what the better habits are to pick up.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java naming conventions are specified near the middle of this page.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian Fenno wrote:I'm just curious to know the naming conventions


Code Conventions for the Java™ Programming Language
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note these are conventions not rules, but many companies insist their staff follow the local variations of these conventions.
 
Vance Montague
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just pick the style you like the best and stick with it. The important thing isn't which style you use, but to be consistent throughout the code, all for the purpose of making it easier for you to read and scan quickly with your eyes.

One common style is to use underscores/lowercase for private data (some_private_variable), and camel case for public (somePublicMethod). It's not set in stone, it just makes it easier for your eyes to pick things out faster.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vance Montague wrote:Just pick the style you like the best and stick with it.

You may not have a choice. Many companies have their own in-house style guides. You need to be flexible.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vance Montague wrote:Just pick the style you like the best and stick with it. The important thing isn't which style you use ...

While that may be true of things like number of spaces to indent, or where the {}'s go, I'd not screw around with the naming conventions.

Not following the established naming conventions for Java code makes code surprisingly hard to read. If you want the Java community to help you with your code, follow the conventions. Otherwise, your posted code is likely to just be ignored.
 
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Plus tool support will suffer severely. Even some frameworks will not work, at least for Java beans and frameworks that utilise them (some) naming conventions are mandatory.
 
randy orton
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vance Montague wrote:Just pick the style you like the best and stick with it. The important thing isn't which style you use, but to be consistent throughout the code, all for the purpose of making it easier for you to read and scan quickly with your eyes.

One common style is to use underscores/lowercase for private data (some_private_variable), and camel case for public (somePublicMethod). It's not set in stone, it just makes it easier for your eyes to pick things out faster.

using the style which suits you makes the code easily readable by you only.What about others.So why not use the coding standards so that the code is easily readable by others.
 
Harlin Seritt
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
camelCase -- remember... it is more important that your variables, methods, etc be understandable rather than just brief. The name of methods (verbs really) should be similar to: getSomething or setSomething or doSomething.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic