• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A question about something that has been annoying me.

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
camelCase
 
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java naming conventions are specified near the middle of this page.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Brian Fenno wrote:I'm just curious to know the naming conventions



Code Conventions for the Java™ Programming Language
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note these are conventions not rules, but many companies insist their staff follow the local variations of these conventions.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic