|
Some common errors, marked with greek letters (lower-case). (See also, common proofreading marks.)
If you call a function, either put the entire function call on a single line, or put each arguments on its own line.
; good (f a b c) (f a b c) ; bad (f a b c) ; Horrible: (f a b c) |
; okay: (overlay/align 'right 'center (rotate -90 (triangle 20 "solid" "orange")) (ellipse 40 20 "solid" "blue"))) |
More precisely: EVERY function for EVERY homework in EVERY course requires:
Note that good function-names and parameter names go a long way towards self-documentation. If you have a name/field that uses an abbreviation, include a quick comment explaining:
int numPpl; // "number of people" /* Return the index of `needle` inside `haystack`, or null if it does not occur. */ @Nullable Integer locate( int needle, List<Integer> haystack ) |
Put yourself in the mindset of another programmer who might want to call your function: Do they have all the information they need? Note that your documentation should not discuss how your program works (its implementation), but rather what your program does (its interface).
If comlete Javadoc is required: Include one @param for each parameter (explaining what it means), and one @return if the method is non-void. Look at the resulting HTML documentation, and make sure it reads correctly. (ibarland won't require full javadoc unless specified on the homework, if the other guidelines above are followed.)
/** The lines of code below are taking in an ID and returning a boolean. * @param id an ID. * @return true or false */ static boolean isSoldByWeight( String id ) |
/** Returns whether or not a grocery-item ID is for an item which is sold by weight. * @param An ID `number', like "1572935" or "47AGM231". Must be a valid ID. * @return true if and only if the ID'd item is sold by weight. */ static boolean isSoldByWeight( String id ) |
For ibarland's classes, you may omit the @return line, in that case, unless otherwise specified on the particular assignment. (I wish Javadoc would do something like this by default, to maintain a single point-of-control -- a standard software goal!)
Incomplete testing. You should have test cases each method you write. Test cases include actual inputs, and the expected result.
Some functions need more test cases than others.
if (someCondition) { return true; } else { return false; } |
return someCondition; |
SomeType someVar = someExpression; return someVar; |
return someExpression; |
not ==. In general, be sure to understand the difference == between these two notions of equality; come to office hours if unsure.
Similarly, doubles/floating-point numbers should be compared with a method that allows for some tolerance, rather than exact-equality (== or Double#equals).
Separately: If you override equals, you should also override hashcode.
When writing papers, this indicates that your paper would still make exactly the same point with a much-shorter (or entirely omitted) sentence. Perhaps, it's a generic statement that is common knowledge, and it seems like you're just saying it to fill up time. E.g. “The internet is used by more and more people every year, and has come to play an important part of commerce, socializing, e-mailing, and communication.” Only include such a statement if it's really a key factor to the overall argument you're making, and if you are later coming back to refer to several specific parts of that statement.
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |