Some students have requested more guidance about what we consider acceptable style for the homeworks. Therefore, please observe the following guidelines for the Java project. As always, style rules are guidelines only; there are always exceptions. Use your judgment. -- Keunwoo
We will accept any of the standard indent styles: K&R, Allman, Whitesmiths, or GNU/FSF (see here for explanations of the four styles). Please be consistent, at least within a single source file. Also, use at least two spaces for each indent level, and no more than eight.
As an exception, one-liner methods (you will probably have several of these) can be written on one line:
public class Foo { // ... public int getX() { return x; } }
Use meaningful names. It is not necessary in Java to abbreviate class names; for example, the Java designers named their input stream class InputStream, not istream. Java programmers are used to long, informative type names, so don't attempt to "save space" by using cryptic identifiers.
The Java convention for capitalization is
public class ClassName { public static final int CONSTANT_NAME = 0; public void methodName(ParamType paramName) { VariableType varName = (VariableType)paramName; } }
However, if you have already started your project using some other naming convention (e.g., C or Ada conventions) then feel free to continue using yours, as long as it's consistent.
It is common in the C++ world to name private instance variables with an initial underscore. This is discouraged in Java.
Documentation should take several forms:
See my BufferedCanvas.java file for an example of how to document your classes. We will not expect quite as much documentation for every one of your class files, but it should give you an idea of how to do it.
You should use good object-oriented design as described in lectures. Here are some points to remember:
public class GameActor { public int x, y; // ... }you should use the following:
public class GameActor { private int x, y; public int getX() { return x; } public int getY() { return y; } public void setX(int x) { this.x = x; } public void setY(int y) { this.y = y; } // ... }The latter frees you to make implementation changes in the future. It also frees you to make interface changes in the future; if, for example, you decided to make GameActor an Immutable class, you could remove the
set
methods
and the compiler would tell you all the places you need to change
your code.java.lang.Math
).