General Style Deductions
Students in CSE143X are expected to demonstrate good programming style in
their homework solutions. Every homework assignment will describe specific
style requirements and expectations that students should keep in mind when
writing their solutions. This page lists general style issues that are
likely to be relevant to multiple assignments. This list includes common
style mistakes but does not list every possible style mistake.
TAs provide feedback on graded homework assignments and often give a "-0"
warning to indicate a style issue that is not being penalized but might be in
a future assignment. The list below indicates general style issues that will
not be graded as "-0". Homework assignments are listed in reverse order
because once a style issue is included for one homework, it is included for
all future homeworks. The list is not meant to be exhaustive, although it
includes the most common style issues. Students should not ask about the
details of style grading on the message board, but can ask their TA or a TA
at the IPL to explain any of these style categories.
- Homework 10: Huffman
- class design errors:
- not using calls on this(...) to eliminate redundancy by having
one constructor call another
- data structure errors:
- not using x=change(x) when appropriate to simplify code
- poor choice of constructors for a node class (e.g., unused
constructors or just a zero-argument constructor)
- miscellaneous errors:
- poor choice of constructor (e.g., setting fields immediately
after construction when they could have been set by using a
different constructor)
- Homework 9: Anagram Solver
- Homework 8: Grammar Solver
- control structure errors:
- structuring a recursive solution so that it has extra recursive
cases or extra base cases that are not needed
- method errors:
- unnecessary parameters with redundant information that is
available to the method from another source
- Homework 7: Evil Hangman
- readability errors:
- nondescriptive names for local variables or methods
- method errors:
- not throwing exceptions at the top of a method when detecting the
error does not require significant computation
- using if/else instead of if for exception code (non-exception
code should not be in an else branch)
- reimplementing methods (i.e., writing code for a commonly used
method such as Arrays.toString)
- miscellaneous errors:
- not using interfaces when possible to refer to variables,
parameters, and return values
- not using generic types properly (e.g., manipulating a Stack
versus a Stack<Integer>)
- using a specific numerical value when the value can be obtained
in a more general way (e.g., even if an array called data is
expected to be of length 100, code to manipulate it after
construction should use data.length instead of 100)
- Homework 6: Assassin
- commenting errors:
- implementation details included in comments for a class or its
public methods
- method header does not describe the purpose of each parameter or
does not describe the meaning of the return value of a non-void
method
- method header does not document all preconditions or does not
describe exceptions that are thrown when preconditions are
violated, including the specific type of exception and the
conditions under which it is thrown
- method header does not document important behavior including
subtle cases like an empty structure or a search value not
found
- blind copying of text from assignment writeup
- readability errors:
- one-letter or nondescriptive field names
- method errors:
- modifying a parameter to a method when such modification was not
part of the intended behavior
- data structure errors:
- extra data structures that aren't necessary
- class design errors:
- extra public methods not in the specification
- extraneous data fields
- initializing non-final data fields outside of a constructor
- miscellaneous errors:
- failure to simplify code (e.g., not factoring out common code,
extra tests or loops that aren't necessary)
- Homework 5: Critters
- control structure errors:
- bad use of if/else (e.g., empty branch, unnecessary tests)
- miscellaneous errors:
- unnecessarily inefficient code (e.g., constructing a new object
on every iteration of a loop when it could have been constructed
once before the loop)
- Homework 4: Personality
- method errors:
- miscellaneous errors:
- using \n to produce more than one line of output with a single
print/println/printf
- bad Boolean Zen
- Homework 3: Bagels
- control structure errors:
- using incorrect if/else structure
- failing to factor out redundant code in if/else structures
- miscellaneous errors:
- constructing more than one Scanner for console input
- Homework 2: Cafe Wall
- readability errors:
- lines over 100 characters
- not following Java naming conventions (e.g., not using camel
case, not using uppercase letters and word-separating underscores
for constants)
- method header missing or does not adequately describe what the
method does
- inconsistent or nonexistent spacing within expressions (we
suggest one space on either side of an operator)
- control structure errors:
- bad use of loops (e.g., 1 to 1 loops, including an unnecessary
check before a loop that repeats the loop test)
- method errors:
- unused parameters or return value or passing a constant as a
parameter
- calling an inappropriate version of a method when a better
alternative exists (e.g., calling System.out.println("") instead of
System.out.println())
- class design errors:
- incorrect constant declaration (e.g., not final, not static)
- Homework 1: Song
- commenting errors:
- class header missing or doesn't describe both student and
program
- readability errors:
- bad indentation
- some method or constructor does not have a blank line before
it
note: "e.g." should be read as "for example" and "i.e." should be read as "in
other words"
In general, once a class has been discussed, it is available for use by
students. For example, once the String class is introduced, you may assume
that you can call any of the available String methods in future homework
assignments without asking permission. Student should realize, however, that
saying that you are not forbidden from using a certain construct is not the
same thing as saying that it is a good idea to use a certain construct. We
don't give advice to students about which constructs to use. You have to use
your best judgment to decide and you might lose style points if you make a
poor choice. In addition, there are some constructs that you are not allowed
to use, as described in the next paragraph.
Java has grown to be a complex language with many features. We don't have
time to teach all of these features in CSE143X. We have a general rule that
students should not use "advanced" material that we have not covered in
class. In addition, we have identified several Java features that we do not
want students to use. It is not bad style to use these features, but we want
to have a level playing field for all students. For any one of these
features, we prefer that either everyone in the class knows about it and can
use it or nobody is allowed to use it. The following features should not be
used in CSE143X homework or exam solutions:
- break, continue, return from a void method
- try/catch, annotations
- the var keyword
- Java 8 features (e.g., lambdas, streams, method references)
- toArray, clone
- StringBuilder, StringBuffer, StringJoiner, StringTokenizer, and String
methods toCharArray, join, matches
- Arrays.asList, Arrays.copyOf, Arrays.copyOfRange, Arrays.sort
- Collections.copy, Collections.sort
- package declarations
Many students find themselves wondering, "What is that feature you are
describing?" If you don't recognize it, then you're unlikely to use it, so
the best answer is, "Something that we have decided not to teach you in this
class so that we will be able to focus on the really important concepts you
need to learn."