views:

47

answers:

3

What should be the convension while naming components and why? E.g

  • myJobButton

  • buttonMyJob

EDIT: When typing i.e. on netbeans and using code completion with ctrl+space if you choose the second naming convension then typing "button" results on a sorted list of all your buttons.

A: 

have a look here from the sun site.

extract

Variable names should be short yet meaningful. The choice of a variable name should be mnemonic- that is, designed to indicate to the casual observer the intent of its use. One-character variable names should be avoided except for temporary "throwaway" variables. Common names for temporary variables are i, j, k, m, and n for integers; c, d, and e for characters.

Paul Whelan
what are throw away variables?
ultrajohn
a variable you might use in a loop for example so its ok to do something like for(int i = 0; i < size; i++)
Paul Whelan
A for-loop counter is a good example. It's okay to write `for (int i = 0; i < 10; i++)` because even though `i` isn't a very expressive variable name, it's reasonably clear what it's doing -- in large part because the variable doesn't stay around for very long.
Etaoin
temporary variables, especially ones whose value won't be used and that are just there to satisfy some syntax requirement.
cHao
+2  A: 

As long as you're consistent, and as long as it's clear what your identifiers mean, it doesn't matter -- there's no single overarching standard for this sort of thing. If you're working on a project by yourself, do whatever makes the most sense to you; if you're working on a team, settle on a convention and follow it. In general, though, you've got more important things to worry about. :)

Etaoin
+1  A: 

I would choose myJobButton, because it is the way you would call it in English. The other version looks forced and unpleasant to me.

It is much more important that the code is easy to read than that it is easy to write.

starblue