Search code examples
javanaming-conventionsconventionsconventioncoding-style

Java convention: when referring to coordinates, do I name methods and variables with "location" or "position"?


My program deals with a lot of coordinates and I want to keep things consistent throughout my program to improve readability, but I am stuck on whether to use the word "location" or "position".

Java itself seems to be conflicted on this; the java.awt.JFrame class has both setLocation() and getMousePosition(), which each use different words to refer to the java.awt.Point class.

I had a look in Oracle's Java Coding Conventions document but I saw no mention of how to refer to coordinates.

Is there a standard naming convention for this, or should I just choose the one I prefer and stick to it?


Solution

  • You should choose a naming convention and follow it within your team. Although naming convention is important, I think the situation described is too much of a purism. Java has no notion of coordinates in its naming convention. Just follow the general rules for getters/setters and so on.

    On a more philosophical note:

    • location - describes the location (x,y,z).
    • position - could imply position in reference to something (vertical, beneath, above, facing North)