Question

I have four variable in a program: xPos, yPos, xVel, yVel

Each one of them should have a setter/getter, but it will be awkward to say:

setXpos()
getXpos()
getXvel()
setXvel()

Is there a naming convention for these variables that is short and efficient?

Was it helpful?

Solution

What you've listed in your code snippet is the naming convention.

The more important question is, how can they be reframed for readability? As someone who hasn't seen your program, the four functions you listed seem perfectly clear to me. I'm having a hard time coming up with something clearer.

Any time you abandon a convention, even if the convention makes things icky, you lose readability/clarity (as people expect those conventions to be fulfilled). You have to weigh the advantage of abandoning an icky convention-result for something better against that loss of abandoning the convention.

All this to say, you have my permission to use 'getXvel()'. Godspeed. =)

OTHER TIPS

How about getXPos() and getXVel()? Although, getXPosition() and getXVelocity() seems clearer. It depends on context, but it took me a second to figure out that you didn't mean val.


This goes beyond your question, but (under the right circumstances) I might argue doing this:

foo.getX().position();
foo.getX().velocity();

There are a few schools of thought on naming convention. If you follow java bean conventions then your setters and getters are correct, however I would consider renaming your variables to be more descriptive, i.e. horizontalPosition, verticalPosition, verticalVelocity, horizontalVelocity with the getters and setters named appropriately.

Use the class Point for (x, y).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top