Coding Conventions, Styles, and Software Engineering Tips
public class wugga { String nonsense; public void wugga(int dooba, int thibbeh) throws A_Fit { int i; for (i = 0; i < dooba; i++) { if (test(dooba) < 7) { do_something(thibbeh); } else { repossess_car(); throw A_Fit; } toast_cpu(i*70); } } String get_nonsense() { return this.nonsense; } }
There are a number of things going on here stylistically (spacing on a line, indentation, placement of brackets, etc.) but they all add up to one thing: improving readability. Make it easy to tell where a set of statements begins and ends. Use blank lines to separate blocks of code that aren't directly related--don't worry about the "wasted" space inside your code. For more examples of, and details on, good style, see the style guide on the CIS 210 web page. This style is a bit different from the one I have specified here, but is perfectly acceptable. (The major difference is that I prefer to put opening brackets '{' on a line by themselves; otherwise they're harder to find and match with the corresponding closing brackets '}'.)
A corollary: don't treat illegal input as if it were legal. An example of this might be as follows: suppose that you have subclassed Word into Data and Instructions. Incrementing an Instruction doesn't make any sense. However, simply returning the Word which is the Instruction itself doesn't make any sense either. A C programmer would write the inc() method so that it would return an error value, or set an error flag, if it were passed an Instruction. As Java programmers, you should use the Java mechanisms for handling problems, and throw an exception in this case.
Keep these comments in mind for future projects. There's a lot here, but at least it's all in one place. :)