


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Department of Computer Science University of San Francisco
Code readability and maintainability are incredibly important. Coding standards are a relatively easy way to increase the readability (and hence maintainability) of your code.
Method and variable names should start with a lowercase letter, and class names should start with an uppercase letter Idendifiers are often multi-word descriptions of what they are identifying, and uppercase letters are used to specify word breaks. For example, a variable representing a first name might be called firstName. A class representing a bank account might be called BankAccount. Identifier names should be descriptive enough for someone reading the code to know what the variable is, and how it is being used, just by looking at the name of the variable. Thus, variables like x, y, a, and b are usually poor choices, while variable names like studentID, and playerName are better. Longer is not necessarily better, however. Names like i and j are perfectly fine for loop control variables. Some examples:
int f (int a[], int b, int c) { int d = Integer.MAX_VALUE; for (int i = b; i <= c; i++) { if (a[i] < d) { d = a[i]; } } return d; }
int findTheSmallestValueFromLowTOHightInArray (int arrayToSeachForLowValue[], int lowIndexOfArray, int highIndexOfArray)
int smallestValueInArray = Integer.MAX_VALUE; for (int indexForArrray = lowIndexOfArray; indexForArray <= highIndexOfArray; indexForArray++) { if (arrayToSeachForLowValue[indexForArray] < smallestValueInArray) { smallestValueInArray = arrayToSeachForLowValue[indexForArray] < smallestValueInArray; } } return smallestValueInArray =; }
int smallestValueInRange(int array[], int lowIndex, int highIndex) { int smallest = Integer.MAX_VALUE; for (int i = lowIndex; i <= highIndex; i++) { if (array[i] < smallest) { smallest = array[i]; } } return smallest; }
Code between an open brace ({) and the corresponding close brace (}) should be indented a consistent number of spaces. This applies to if statements, loops, method definitions, and class definitions. The close brace should always be lined up with the header of the statement. The open brace be on a new line, like the code examples above.
Design really is a creative process and each person may approach the process differently. For the purposes of this class, the outcome of the design process will be a set of classes you need to implement, the data and methods each class will contain, and and overview of how the classes will interact. Larger programs may have more complex design issues and the first outcome of the design process will be a system architecture with multiple components for which a more refined design will then be developed. Keep in mind that an initial design is unlikely to be flawless. You will almost certainly need to go back and refine or change your design as you implement your program.