variable naming

Okay, so I’m cleaning up Xenplat’s source code so it’s not all shitty like Blue Fiend. I’ve capitalized the names of my classes and put them each in their own .java. Now I’m renaming my variables.

The standard for variables is camelCase, right?
but what about underscores? like what should max_enemies be? It’s not static, so I don’t think it should be MAX_ENEMIES.

maxEnemies

There are certain coding standards. Eclipse has some nice built in syntax templates, and it warns you if you try to create a variable, method, class, enums or package with names that are not common.

Just google it. camelSyntax is just one part of the equation.

I never ever use underscores for anything. They are been acceptable for static fields, but I think there is some debate about that.

[quote=“appel,post:3,topic:33422”]
Constants should be named IN_CAPS_WITH_UNDERSCORE_BETWEEN_WORDS according to the code conventions, and I’ve never seen anyone argue against that. Constants in the standard api use that format as well (Integer.MAX_VALUE, for example).

Here’s a very old page with the code conventions on java.com.

I have this standard of not ever abbreviating any names either, so for instance position never becomes pos or p.

final NoMatterHowLongThisClassNameIs noMatterHowLongThisClassNameIs = NoMatterHowLongThisClassNameIs();

Then there is the matter of Lists/arrays, lets say we have a list of the class Position, I would then name the list like this.

final List<Position> positions = new ArrayList<Position>();

// Json

public static final int VERY_DESCRIPTIVE_VALUE; private static final int very_descriptive_value; private final int veryDescriptiveValue; private final VeryDescriptive value;

That’s a new one on me; and definitely not part of the Sun standard.
I don’t think the scope of a variable should ever influence the naming convention.

Hm… I learnt that like 10 years ago when I first encountered Java in some crappy book. I’ve used it like that ever since.

in another way if an idea can improve readabilty it can be helpfull even if it is not stamped by Sun

http://checkstyle.sourceforge.net/

If you want to get past the endless discussions:
write lossless converters so ppl could use whatever style they like. just convert backwards and forwards to your favourite style and that of the version control system.

adleast for whitespaces
so for example:

[quote]public void doFooMethod() {

}
[/quote]
vs

[quote]public void doFooMethod()
{

}
[/quote]
given the open source software that is avail now it should be trivial to implement and just have your IDE sort it out, and hide that the whole thing is happening away from the developer.

and for ppl who are fanatic about saving lines: try removing the brackets and use a different background colour.

The way the data is presented doesn’t really change the data.

It’s not static, so I don’t think it should be MAX_ENEMIES.

Well, is it supposed to be changed? Does changing the value make any sense? If not it probably should be static.

and final