Intro to Computer Science II
Intro to Computer Science II CS 112
Popular in Course
Miss Lucienne Hamill
verified elite notetaker
Popular in ComputerScienence
verified elite notetaker
This 3 page Class Notes was uploaded by Michele Herzog on Thursday October 29, 2015. The Class Notes belongs to CS 112 at University of San Francisco taught by Staff in Fall. Since its upload, it has received 6 views. For similar materials see /class/231245/cs-112-university-of-san-francisco in ComputerScienence at University of San Francisco.
Reviews for Intro to Computer Science II
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 10/29/15
Department of Computer Science University of San Francisco Computer Science 112 Coding Standards Spring 2008 1 Why have coding standards Code readability and maintainability are incredibly important Coding standards are a relatively easy way to increase the readability and hence maintainability of your code 2 Identi er Naming Method and variable names should start with a lowercase letter and class names should start with an uppercase letter ldendi ers 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 rst name might be called rstName A class representing a bank account might be called BankAccount Identi er 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 studentlD and playerName are better Longer is not necessarily better however Names like i and j are perfectly ne for loop control variables Some examples 0 Bad too sparce int f int a int b int c int 1 IntegerMAXVALUE for int i b i lt C i if ai lt d d ai return 1 0 Bad too verbose int findTheSmallestValueFromLowTDHightInArray int arrayToSeachForLowValue int lowIndeXDfArray int highlndeXUfArray int smallestValueInArray IntegerMAXVALUE for int indeXForArrray lowlndeXDfArray indeXForArray lt highlndeXUfArray indeXForArray if arrayToSeaChForLowValueindeXForArray lt smallestValuelnArray smallestValuelnArray arrayToSeachForLowValueindeXForArray lt smallestValuelnArray return smallestValuelnArray 0 Good int smallestValueInRangeint array int lowlndex int highlndex int smallest IntegerMAXVALUE for int i lowlndex i lt highlndex i if arrayi lt smallest smallest arrayi return smallest 3 Indendation Code between an open brace and the corresponding close brace should be indented a consistent number of spaces This applies to if statements7 loops7 method de nitions7 and class de nitions The close brace should always be lined up with the header ofthe statement The open brace be on a new line7 like the code examples above 4 Spacing 0 Put one space after each comma in a parameter list 0 Put one space on either side of a binary operator 0 Do not put spaces immediately after a left parenthesis or before a right parenthesis Do not put spaces before a semicolon Put one space before a left parenthesis except before an empty parameter list 5 Commenting and Documentation 0 Every source code le should contain a header block of documentation providing basic information about the contents and the author Each class and interface and each method in a class should have a small header block that describes its role Use in line documentation as appropriate to clearly describe interesting processing Don7t wait until a program is nished to insert documentation As pieces of your system are completed comment them appropriately 6 Program Decomposition and Design Beginning programmers are typically most concerned with getting their code to run Just getting a program to compile can be such a huge hurdle that the programmer doesn7t stop to think about whether someone else can actually read the code or whether it can be easily extended to support new functionality However the process of designing a clean program is extremely important and a good design can make the coding itself much simpler Becoming a good designer takes lots of practice and it also takes a bit of con dence As you design programs you have to have con dence that you will be able to gure out a way to implement your designs Rather than try to piece together what you know how to do think about what you want your program to do and have con dence that you can nd a way to make your program do that Additionally understand that program design is a creative process Your design for a program may differ from that of one of your classmates You may also design a program and decide that your design isn7t quite right You need to be willing to redesign your programs when you discover that your design just doesnt support everything it needs to 61 Design Goals 1 Reusability As you develop more programs you will undoubtedly notice that many of them require similar functionality If you are careful in designing your programs you should be able to easily reuse components in future programs For example you might notice that lots of your programs require you to maintain a sorted list of items If you were careful in designing that very rst program that required a sorted list you probably implemented a general purpose class that maintained a sorted list of items and supported methods such as add remove and nd You can easily reuse this class in any program that requires a sorted list
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'