Documentation Requirements Computer Science 2334 Spring 2016

Similar documents
CS 251 Intermediate Programming Coding Standards

QueueBlock, ReversalADT, LinkedList,CustomerAccount, not MaintainCustomerData

CS 351 Design of Large Programs Coding Standards

Write for your audience

Makefiles Makefiles should begin with a comment section of the following form and with the following information filled in:

CS 152 Computer Programming Fundamentals Coding Standards

Initial Coding Guidelines

Java Style Guide. 1.0 General. 2.0 Visual Layout. Dr Caffeine

Coding Standards for Java

CSCI 1060U Programming Workshop

CS 215 Software Design Homework 3 Due: February 28, 11:30 PM

Computer Programming : C++

Java Programming Style Guide

11 Coding Standards CERTIFICATION OBJECTIVES. Use Sun Java Coding Standards

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.

CSCI 2101 Java Style Guide

CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

Coding Standards for C

Variables. Data Types.

Full file at

Coding Standards for C

CSE 11 Style Guidelines

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

CSCI 200 Lab 1 Implementing and Testing Simple ADTs in Java

ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1

Tips from the experts: How to waste a lot of time on this assignment

Supplement D: Expanded Guidelines on Programming Style and Documentation

CS 251 Intermediate Programming Methods and More

CS 251 Intermediate Programming Methods and Classes

6.170 Laboratory in Software Engineering Java Style Guide. Overview. Descriptive names. Consistent indentation and spacing. Page 1 of 5.

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

Course Outline. Introduction to java

What does this program print?

CSE 142/143 Unofficial Style Guide

COMP 202 Java in one week

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java

Programming Style Guide v1.1

Expanded Guidelines on Programming Style and Documentation

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Introduction to C Programming

Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently.

Pace University. Fundamental Concepts of CS121 1

C++ Style Guide. 1.0 General. 2.0 Visual Layout. 3.0 Indentation and Whitespace

Lab # 2. For today s lab:

JOSE LUIS JUAREZ VIVEROS com) has a. non-transferable license to use this Student Guide

Project #1 Computer Science 2334 Fall 2008

Tips from the experts: How to waste a lot of time on this assignment

C++ Programming Style Guide

Assignment Marking Criteria

CIT 590 Homework 5 HTML Resumes

Classes, interfaces, & documentation. Review of basic building blocks

User Interface Programming OOP/Java Primer. Step 3 - documentation

CS 231 Data Structures and Algorithms, Fall 2016

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Coding Standard for ECE3090 August 24, 2005

CPS122 Lecture: Defining a Class

Example Program. public class ComputeArea {

CS 142 Style Guide Grading and Details

Programming Syntax and Style. David Greenstein Monta Vista High School

CSCI Lab 9 Implementing and Using a Binary Search Tree (BST)

CS112 Lecture: Working with Numbers

Scala Style Guide Spring 2018

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

APPENDIX A : Example Standard <--Prev page Next page -->

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

In Java, data type boolean is used to represent Boolean data. Each boolean constant or variable can contain one of two values: true or false.

Week 7 - More Java! this stands for the calling object:

Programming Standards: You must conform to good programming/documentation standards. Some specifics:

Com S 227 Spring 2018 Assignment points Due Date: Thursday, September 27, 11:59 pm (midnight) "Late" deadline: Friday, September 28, 11:59 pm

CS125 : Introduction to Computer Science. Lecture Notes #4 Type Checking, Input/Output, and Programming Style

Coding Guidelines. Introduction. General Points. Avoid redundant initialization/assignment

Java Programming Tutorial 1

public class Foo { private int var; public int Method1() { // var accessible anywhere here } public int MethodN() {

Appendix G C/C++ Notes. C/C++ Coding Style Guidelines Ray Mitchell 475

Problem Solving with C++

Variables and Functions. ROBOTC Software

ASSIGNMENT 5 Objects, Files, and a Music Player

Key Differences Between Python and Java

Quality of the Source Code Lexicon

A JavaBean is a class file that stores Java code for a JSP

Tips from the experts: How to waste a lot of time on this assignment

Documentation Nick Parlante, 1996.Free for non-commerical use.

Java Coding style guide 1. Java. Coding Style Guide. (July 2015)

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED

Introduction to Python Code Quality

3. NetBeans IDE 6.0. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

Perl Basics. Structure, Style, and Documentation

Problem 1: Building and testing your own linked indexed list

CS 170 Java Programming 1. Week 12: Creating Your Own Types

UEE1302 (1102) F10: Introduction to Computers and Programming

Introduction to Java. Java Programs Classes, Methods, and Statements Comments Strings Escape Sequences Identifiers Keywords

Transcription:

Overview: Documentation Requirements Computer Science 2334 Spring 2016 These requirements are based on official Java coding conventions but have been adapted to be more appropriate to an academic environment. All Java source code files should have an extension of.java. All Java bytecode files should have an extension of.class. Each file should contain only one class or interface, and the name of the file should match the name of the class or interface. For example, a class called Sample should be stored in a file named Sample.java. One specific note should be made: the website above (and most places) will also state that you should add an @author tag to your Javadoc class and method headers, to produce the proper documentation. We would usually follow this, but we will not because of our submission of assignments for accreditation. Therefore, do not place any personally identifiable information anywhere inside your code. This includes the aforementioned tags, your name, your 4x4, or anything else related. You should even look to make sure that you do not include the path to your files at the bottom of your code (which some programs will do, and some people include their work inside folders with their 4x4). Instead, we ask that you provide a cover sheet for each assignment (lab, design, or final project) that includes the following: The names of all group members. (For Projects 2 4 you must submit as part of a group at least 2 members. For Projects 1 and 5 you will do individual work.) A breakdown of which member wrote which code. If more than one person helped on a class, then break the class down by method. (For Projects 2 4 only.) Citations of any and all code that was borrowed from any outside sources. Any other information that would be relevant to the assignment. Lastly, don't forget to add your UML, your source code (or stubs), and your Javadoc to your submissions. The Milestones file should be added to your final project submission. Ordering: The ordering of components within a file is as follows: 1. Package statement (optional) 2. Import statement(s) (optional, but almost always necessary) 3. Javadoc style class header comment 4. Class header 5. Static variables (sorted in the order of public, protected, default, then private variables) 6. Instance variables (sorted in the order of public, protected, default, then private variables) 7. Constructors 8. Methods (sorted in the order of accessors and then mutators then others) Documentation Requirements CS 2334 1

Comments: Java programs have two types of comments. Documentation comments, which are of interest to someone using the class, and implementation comments, which are of interest to someone writing or maintaining the class. Documentation Comments: Documentation comments record the behavior, usage, and specifications of a class. In this course we will also use documentation comments to record the design of a class. Documentation comments are in the form of Javadoc comments. Javadoc is a tool that processes Java code files extracting the comments and creating HTML files that present the information contained in the comments in an easy-to-read and user-friendly form. Javadoc comments appear before the code that they describe. Javadoc comes as a part of the JDK. At the beginning of each class, a Javadoc style class header comment like the one below must be given. This comment must include the project number, course number (CS 2334), class section, date, and @version Javadoc tags. However, they should not include the @author tag, as mentioned above. Multi-line Javadoc comments begin with '' on a line by itself and a '*' followed by a space on each line of the comment with the last line consisting of '' on a line by itself. A single line Javadoc comment starts with '' and ends with ''. * Project #1 * CS 2334, Section 010 * Jan 12, 2016 * <P> * A comment describing the class fully. This comment may be a page long * and use HTML. * </P> * @version 1.0 Note that the package statement and import statement(s) must come before the Javadoc style class header comment. If a package or import statement is placed between the Javadoc style class header comment and the class header itself, then Javadoc will fail to associate the class header comment with the corresponding class. Each class variable should also be documented as shown in the example below. Stores the speed of the airplane as a floating point value. float speed; Each method must be preceded by a method header comment like the one given below. This comment must give a specification of the purpose and design of the method. This should focus on what the method is intended to do (interface) not on how the method is intended to do it (implementation). Implementation comments are described separately, below. Documentation Requirements CS 2334 2

The method header comment must also include the Javadoc tag fields @param, @return, and @exception. Each @param field specifies the parameters required and provides a short description of its purpose. The @return field specifies the type of the return value of the method and description of its purpose. Each field specifies the type of any exceptions the method throws and their purpose. Note that your methods may have zero, one, or more parameters and will contain a corresponding number of fields. Additionally, your methods may throw zero, one, or multiple exceptions and will contain a corresponding number of @exception fields. Finally, the method header comment is used to document the preconditions and postconditions associated with a method. Each precondition and postcondition is specified on a separate line, as shown in the example below, with preconditions specified before the postconditions. Some methods such as accessors that do not change the state of the object or perform any calculations may not need preconditions or postconditions. You must also provide code in your methods that tests the preconditions and postconditions. This will be discussed in class. * A descriptive comment goes here. This comment may be several lines long. * <P> * Algorithm:<br> * 1. You may explain the PURPOSE the algorithm here.<br> * 2. Do NOT include a step by step description of the algorithm here.<br> * 3. Be sure to put an html <br> tag after each line.<br> * </P> * @param input Each parameter has a separate listing like * this one. * @return Include a descriptive comment describing the return * type. * @exception IllegalArgumentException Explain when this exception * will be thrown. * <dt><b>conditions:</b> * <dd>pre - List the precondition here. Each precondition has a * separate listing. * <dd>post - Postconditions are listed the same way as * preconditions but with <dd>post instead of <dd>pre. It is imperative that you create the Javadoc class header and method header comments using your UML class diagram before you begin programming. This step lets you think about how your classes and methods need to be constructed and implemented at a detailed design level before you become concerned with Java language specific implementation details. First you should create class header comments, class headers, class variables (and their corresponding comments), and Javadoc style method headers and method stubs. Then you can use the Javadoc tool to create a detailed level design specification that is easy to read and will help you as you implement each method and test your program. The command will create a sub-directory named javadocs that contains the Javadoc HTML files. javadoc -breakiterator -private -author -version -d javadocs <source files> This command may be hard to remember and type. Therefore, an options file has been provided Documentation Requirements CS 2334 3

for you named docs.opt on the class website. Download this file into the directory that contains your.java source files and run the command as shown below. javadoc @docs.opt <source files> Also, note that the above commands will not produce Javadoc files for your entire project. To correctly produce Javadoc files for the entire project your must list all of your.java files in place of <source files> or you must specify *.java in place of <source files>. See the examples below. javadoc @docs.opt SpellChecker.java CustomIO.java Dictionary.java or javadoc @docs.opt *.java Javadoc comments can be used to create fancy documentation and the Javadoc specification includes many features that are not covered here. To explore more options see the Javadoc website http://www.oracle.com/technetwork/java/javase/documentation/index-jsp-135444.html. An article on how to write Javadoc documentation comments is available from the Oracle website at http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html. Also, keep in mind that these instructions are for generating Javadoc when you are not using Eclipse. Since we, in this class, will be using Eclipse for all but one programming assignment (part one of Lab 1), you can follow the directions in the Submission Instructions file for generating your Javadoc. You must format the comments correctly (as detailed above), however, for Eclipse to properly create the Javadoc for you. Implementation Comments Implementation comments describe specific implementation details about your code that are helpful in program maintenance, both debugging and enhancement, and incremental implementation. Implementation comments can be written in a block comment form, a single line form, or a trailing form as shown below. /* * This is a block comment. * Putting asterisks at the beginning of each line makes the comment * more noticeable and easier to read. /* This is a single line comment on a line by itself. iamanexression = anotherexpression; // This is a trailing comment. Selecting the proper style of comment for the situation is at the discretion of the programmer. Whenever possible all comments should should be proper English and in the form of complete sentences. Documentation Requirements CS 2334 4

Indentation and Line Wrapping: Each level of indentation must consist of one tab (usually four spaces). Indentation must exactly match the block structure of the code, shown with curly braces below. * This method demonstrates the proper indentation of code. * This method calculates the following step equation * <code>yvalue = 0 if xvalue < 5, 1 otherwise.</code> * * @param xvalue Contains the value to be compared with 5. * @return yvalue Calculated as specified above. public int mymethod (int xvalue){ int yvalue; if (xvalue < 5){ yvalue = 0; else { yvalue = 1; return yvalue; // end mymethod Different editing programs interpret tabs to represent different number of spaces, therefore you should use spaces instead of tabs. Many text editors can be set to insert spaces instead of tabs. Lines must be less than 80 characters in length (at a reasonable font size you cannot get more than about 80 characters of text per line and your printout will likely cut-off or wrap the text which makes it difficult to read). Word wrap should not be used. Instead, lines should be broken according to these rules: 1. Break after a comma. 2. Break after an operator. 3. Align the new line with the start of the expression at the same level on the previous line. 4. If the above rules result in unreadable code, then indent one tab instead. SomeMethod (thisisareallylongparamter, andsoisthisone, thelineislong, sothelastonegoeshere); longexpression = thisisalongmathexpression + andthisisonlypartofit + thisoneshouldbehere; Declarations: Each class variable declaration must be on a line by itself, preceded by a class variable comment as discussed previously. All other variable declarations should be on a line by themselves, preceded by a comment on the previous line or followed by a trailing comment on the same line as shown below. int size; // Stores the number of objects in the array. Documentation Requirements CS 2334 5

All declarations should occur at the beginning of a block, except for loop counters that are declared inside a for loop. For (int i = 0; i < size; i++){ int sum = 0; // This declaration should occur before the next statement. total = total + (i * size); // Note that total was previously declared. // The rest of this code is not shown for brevity. All declared variables should have unique names within a given code segment. The code below for example, is not allowed by convention, although the compiler will accept it. float grade; // Holds the grade of a student in CS 2334. grade = 10.0; if (grade < 20.5){ float grade; // Holds the grade awarded for an examination. grade = 5.5; Statements: As a general rule, each line should contain at most one statement. argc++; x++; // Don't write two statements on the same line. argc++; x++; // This statement and the one on the line above are better. Braces should be used around all blocks, even if they consist of only one statement. if (x < 0){ x = x*-1; // This block has proper formatting. Return statements should not contain parenthesis, unless they improve reliability. return x; // This return statement has correct formatting. return (x); // Don't use this style of a return statement. The proper indentation for a nested conditional statement is shown below. if (x < 0) { x = x + 1; else { x = x - 1; if (x > 3) { x = 2; Documentation Requirements CS 2334 6

The proper indentation for loops is shown below. The braces should be included even if the body consists of only one statement. (Note that loops with empty bodies are considered poor style and should not be used.) // This is a for loop. for (int i = 0; i < 10; i++){ x++; // Do some calculations here. // This is a while loop. while (k < 20){ x++; // These curly braces are also required. // This is a do-while loop. do { x++; while (x < 0); // These curly braces are also required. Switch statements have poor structure and should be used sparingly or (preferably) not at all, and with copious comments to ensure accidental fall-through does not happen if they are used. The following format would be appropriate if a switch statement is used. switch (i){ case 1: x = 0; // This case falls through. case 2: x = x + 2; break; // This case does not fall through. case 3: x = 3; break; // This case doesn't fall through. default: // If you think you've got all the cases, throw an exception here. break; Try-catch statements are formatted as shown below. try { x = 0; catch (Exception e) { x = 1; finally { x = 2; Documentation Requirements CS 2334 7

Blank Lines: A reasonable number of blank lines improves the readability of code. However, it is neither desirable nor acceptable to use a blank line between each line of code. Blank lines should always be used in the following circumstances: 1. Between sections of a source file 2. Between class and interface declarations 3. Between methods 4. Between the local variables of a method and its first statement 5. Before a block or single line comment 6. Between logical sections inside a method Naming Conventions: Package names are always written in all lower case letters. For example, java.io. Class and interface names should be nouns in mixed case with the first letter of each internal word capitalized, for example ImageSprite. Method names should be verbs, in mixed case with the first letter lowercase and with the first letter of each internal word capitalized, for example run() and runfast(). Additionally, variables are in mixed case with the first letter lowercase and with the first letter of each internal word capitalized. Variable names may not start with an underscore or a dollar sign. One character variable names should be avoided, except for throwaway counter variables. Constants should be upper case with words separated by underscores as shown in the following example. As a general rule, all constants should be named, except for -1, 0, and 1 in loop counters. int final MY_CONSTANT = 3; Examples: The following pages contain the code of a sample class that shows the proper formatting and documentation required for this course. // If there was a package statement, it would go here. // If any import statements existed they would go here. * Project #1 * CS 2334, Section 010 * Jan 12, 2016 * <P> * This is an example class for CS 2334 that shows proper documentation. * It doesn't do much of anything useful, which makes it hard to write a * really great comment up here. It is, however, properly documented. * </P> * @version 4.0 Documentation Requirements CS 2334 8

public class MyString { * A constant that contains the standard number of * characters in a string. static public int DEFAULT_SIZE = 10; A private array to store the characters in the string. private char[] data; * The number of characters that are actually stored in the * string. private int size; * A constructor for an empty string of * <code>currentsize</code> elements. * * @param currentsize The number of characters in the * string. * @throws IllegalArgumentException if currentsize < 0 * <dt><b>conditions:</b> * <dd>pre - <code>currentsize</code> contains a non-negative * integer. * <dd>post - The character array data is of length * <code>currentsize</code>. public MyString (int currentsize) { /* Test preconditions. * In public methods, preconditions are tested with an "if" * statement that throws an IllegalArgumentException if the * the condition fails. In private classes, preconditions * can be tested using "assert" statements. if (currentsize < 0) { throw new IllegalArgumentException ( Illegal currentsize: " + currentsize); data = new char[currentsize]; size = 0; // Set the number of characters stored to zero. /* Test postconditions. * In all methods, postconditions are tested using "assert" * statements. assert (data.length == currentsize); // end MyString Documentation Requirements CS 2334 9

* An accessor for the variable <code>size</code>. * * @return The number of characters in the current string. public int getlength() { return size; // end getlength * The accessor for the character array <code>data</code>. * * @return A reference to the array <code>data</code>. public char[] getdata() { return data; // end getdata * A mutator that sets the size of the array. This is a simple * method, so it does not have a very sophisticated algorithm. * <P> * Algorithm:<br> * 1. Allocate more space.<br> * 2. Copy existing data into the new array.<br> * 3. Record changes in the instance variables.<br> * </P> * @param newlength The desired length for the modified * string. * @throws IllegalArgumentException if newlength < 0 * <dt><b>conditions:</b> * <dd>pre - <code>newlength</code> contains a non-negative * integer. * <dd>post - The character array data is of length * <code>newlength</code>. public void setlength (int newlength) { /* Test preconditions. if (newlength < 0) { throw new IllegalArgumentException("Illegal newlength: " + newlength); /* * Contains the number of characters in the string after it * has been re-sized. int newsize; // Allocate more space. Documentation Requirements CS 2334 10

char[] newdata = new char[newlength]; // Copy existing data into the new array. for (int i = 0; i< Math.min(newLength, size); i++) { newdata[i] = data[i]; // end for // Record changes in the instance variables. data = newdata; size = Math.min(newLength, size); /* Test postconditions. assert (data.length == newlength); // end setlength * A mutator that changes the contents of the character array * <code>data</code>. * * @param newdata A reference to the character array to be * used. * <dt><b>conditions:</b> * <dd>pre - The character array data has the same length as * <code>newdata</code>. * <dd>post - Both data and newdata refer to the same character * array. public void setdata (char[] newdata) { /* * Set data to refer to the character referenced by * newdata. data = newdata; size = data.length; /* Test postconditions. assert (data.length == newdata.length); assert (data == newdata); // end setdata // End of class MyString Documentation Requirements CS 2334 11