Names
You should always choose names that suggest the meanings of the things
being named. If the purpose of a method is to draw a rectangle, then a
good name for that method is drawRect. If there is a
variable of type FilledRect that is used as the stem of a
stop sign, then a good name would be stem or
stemRect.
- Names that have nothing to do with the program are very bad
names! Ex. FramedRect frodo
- Names that are not specific or descriptive enough are
generally bad names. Ex. Line line or Line l
are not as good as Line foulLine if the line represents
a foul line.
- Try not to name objects sequentially. You should only do
this when the objects are related in some way that is not
otherwise expressible. Ex.,
FramedRect box1, FramedRect box2,
FramedRect box3 are not as good as darksBasket,
whitesBasket, and colorsBasket if the rectangles
represent laundry baskets for clothes of specific colors.
By convention, constants (indicated by "static final" in
Java) are all capital letters, classes begin with uppercase, variable
and method names begin with lowercase, while uppercase is used to start
new words in multi-word names.
Instance variables should (almost) never be declared to be public. Instance
variables should only be used when a value must be saved for use
after a constructor or method has been completed. Otherwise local
variables should be used.