C OMP 110/401 D OCUMENTATION : C OMMENTS Instructor: Prasun Dewan.

Slides:



Advertisements
Similar presentations
Programmer-defined classes Part 2. Topics Returning objects from methods The this keyword Overloading methods Class methods Packaging classes Javadoc.
Advertisements

Self Check 1.Which are the most commonly used number types in Java? 2.Suppose x is a double. When does the cast (long) x yield a different result from.
CS 450 MPX P ROJECT Introduction to MPX. I NTRODUCTION TO MPX The MPX module is divided into six modules Module R1: User Interface Module R2: Process.
A Review. a review of lessons learned so far… ( 2 steps forward - 1 step back) Software Development Cycle: design, implement, test, debug, document Large.
C OMP 401 I NTRODUCTION Instructor: Prasun Dewan.
C OMP 110 A RRAYS Instructor: Jason Carter. 2 O UTLINE for loops Arrays.
C OMP 401 C LASS S TATE Instructor: Prasun Dewan.
C OMP 110 S TYLE Instructor: Jason Carter. 2 I NTERFACES AND M ORE S TYLE Define contracts between our users and implementers Optional – they may not.
By - Qiong Han. DON’T FALL BEHIND IN READING Submission Instruction Everyone needs to submit the printed HARD- COPY of the codes and the grading sheets.
Midterm Exam 75 points 1 min per point Allocate time proportionate to points Closed book Chapters 1-5 (except char) PDF/PS with index and corrections coming.
C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
16-Jun-15 javadoc. 2 Javadoc placement javadoc comments begin with /** and end with */ In a javadoc comment, a * at the beginning of the line is not part.
Program Style Identifier Names Comments Named Constants Avoiding Code Repetition Giving Least Privilege Efficiency Interfaces.
Chapter3: Language Translation issues
Classes we can write our own classes – to represent and define our objects e.g. class for Complex objects represents a complex number defines its properties.
Program design example Task: Develop an algorithm expressed in pseudocode for a specified problem specified problem.
ObjectEditor Prasun Dewan Comp 114. ObjectEditor Automatic user-interface generation. You only write computation code Separate object to do I/O Main just.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
1 More on Arrays Arrays of objects Command line arguments The ArrayList class Javadoc Review Lecture 8 notes and L&L 7.1 – 7.2 Reading for this lecture:
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.3 The Class String.
State Instance Variables Procedures Properties Print Statements Println Vs Print Overloading J++
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
INLS 560 – V ARIABLES, E XPRESSIONS, AND S TATEMENTS Instructor: Jason Carter.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
C OMP 401 P ATTERNS, I NTERFACES AND O BJECT E DITOR Instructor: Prasun Dewan.
CSC204 – Programming I Lecture 4 August 28, 2002.
Copyright © Curt Hill Java Looking at our first console application in Eclipse.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
1 Documenting with Javadoc. 2 Motivation  Why document programs? To make it easy to understand, e.g., for reuse and maintenance  What to document? Interface:
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
CIT 590 Intro to Programming First lecture on Java.
C OMP 401: C ONSTRUCTORS AND P OINTERS Instructor: Prasun Dewan (FB 150,
Program style. Global area Place comment s at beginning of the program: 1.purpose 2.author 3.the date the program was written 4.the data and description.
Programming with Visual C++: Concepts and Projects Chapter 2B: Reading, Processing and Displaying Data (Tutorial)
Documentation and Programming Style Appendix A © 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Javadoc Comments.  Java API has a documentation tool called javadoc  The javadoc tool is used on the source code embedded with javadoc-style comments.
C OMP 110/401 E NCAPSULATION AND L EAST P RIVILEGE Instructor: Prasun Dewan.
Documentation Dr. Andrew Wallace PhD BEng(hons) EurIng
CSC Programming I Lecture 6 September 4, 2002.
Chapter 3 Introduction To Java. OBJECTIVES Packages & Libraries Statements Comments Bytecode, compiler, interpreter Outputting print() & println() Formatting.
Javadoc. Purpose of javadoc javadoc is a program that reads your Java program and produces great-looking documentation in HTML format Without any help,
Javadoc. Purpose of javadoc  javadoc is a program that reads your Java program and produces great-looking documentation in HTML format  Without any.
Georgia Institute of Technology Creating Classes part 4 Barb Ericson Georgia Institute of Technology May 2006.
CreatingClasses-SlideShow-part41 Creating Classes part 4 Barb Ericson Georgia Institute of Technology Dec 2009.
GoodOO Programming Practice in Java © Allan C. Milne v
Page 1 – Autumn 2009Steffen Vissing Andersen SDJ I1, Autumn 2009 Agenda: Java API Documentation Code Documenting (in javadoc format) Debugging.
C OMP 401 R EFLECTION AND A CTION O BJECTS Instructor: Prasun Dewan.
CompSci 427jd.1 Javadoc. CompSci 427jd.2 Javadoc The Plan  What is Javadoc?  Writing Javadoc comments  Using the Javadoc tool  Practice.
Chapter 3 AS3 Programming. Introduction Algorithms + data structure =programs Why this formula relevant to application programs created in flash? The.
CSSE 375 Organizing Data – Part 1 Shawn and Steve Q1.
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
C OMP 110/401 D OCUMENTATION : A NNOTATIONS Instructor: Prasun Dewan.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
Variable Scope & Lifetime
More Sophisticated Behavior
JavaDoc CECS277 Mimi Opkins.
Lecture Note Set 1 Thursday 12-May-05
Design by Contract Fall 2016 Version.
Algorithm Efficiency, Big O Notation, and Javadoc
Java Tutotrial for [NLP-AI] 2
Comp 110/401 Documentation: Comments
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Documentation and Style
Anatomy of a Java Program
In this class, we will cover:
Java Looking at our first console application in Eclipse
Corresponds with Chapter 5
Presentation transcript:

C OMP 110/401 D OCUMENTATION : C OMMENTS Instructor: Prasun Dewan

2 P REREQUISITE State Properties

3 P ROGRAMMING S TYLE : T HE A RT OF P ROGRAMMING Use Interfaces Efficiency Document Program Avoid Code Repetition Giving Least Privilege Use Named Constants

4 C OMMENT ? Any code in the program removed by the compiler. double bmi; //computed by setWeight and setHeight Useful for documentation Also for enclosing debugging code // System.out.println(newHeight);

5 W HAT TO C OMMENT ? Any code fragment needing explanation Class Top-level algorithm, author, date modified Variable declaration Purpose, where used, how its value is computed Method declaration params, return value, algorithm, author, date modified Statement sequence Explanation Debugging code Summarizing and/or Elaborating Comments

6 C OMMENT T YPES double bmi; //computed by setWeight and setHeight Single line comments /* recompute dependent properties */ bmi = weight/(height*height); /* recompute dependent properties */ bmi = weight/(height*height); Single or multi-line arbitrary comments

7 System.out.println(newHeight); /*debugging statement */ R EMOVING D EBUGGING C ODE /* System.out.println(newHeight); /*debugging statement */ */ /* System.out.println(newHeight); // debugging statement */

8 W HAT TO W RITE IN A C OMMENT ? double w; // weight double weight; // weight double weight; double bmi; // computed by setWeight and setHeight Bad variable name Redundant Self-commenting Useful comment

9 S ELF C OMMENTING V ARIABLE N AMES Eclipse CTRL-SPACE will complete name for you public static final int NUMBER_WITH_LARGE_FACTORIAL = 15;

10 M ETHOD D ECOMPOSITION public static void modularReadAndPrintStrings() () { String[] strings = readStrings(readNumStrings()); printStrings(strings); printString(strings[0]);// unsafe } public static int readNumStrings() { System.out.println("Number of Strings:"); return Console.readInt(); // reads the next line as integer } public static String[] readStrings(int numElements) { System.out.println("Please enter " + numElements + " strings"); String[] strings = new String[numElements]; // dynamic array for (int elementNum = 0; elementNum < numElements; elementNum++) strings[elementNum] = Console.readString(); return strings; } Comment  long identifier name Eclipse CTRL-SPACE will complete name for you Useful information assuming the reader does not know it

11 F OR W HOM THE C OMMENTS T OLL Other programmers who may have to maintain your code Other programmers using the API provided by your code They do not have the context of the code, so some comments may not be redundant API comments useful in Web Documents and Tooltip Messages in Programming Environment Follow special format so they can be extracted by web doc tools and programming environment

12 J AVA D OC C ONVENTIONS F OR H EADERS (API) /** Prasun Dewan * For more info see: * html#exampleresult} */ public interface CommentedBMISpreadsheet { Interface or Class? /** newValue is the new value of variable weight * not only sets values of weight, * but also computes new value bmi and * assigns it to variable bmi */ public void setWeight(double newValue); Interface is the API JavaDoc Tags

13 E XAMPLE In well written code, difficult to find opportunities to comment Do not comment for the sake of commenting