1 Doc Comment Conventions. 2 Write for your audience Rule 32: Write documentation for– those who must use your code Users should not need to care how.

Slides:



Advertisements
Similar presentations
11-Jun-14 The assert statement. 2 About the assert statement The purpose of the assert statement is to give you a way to catch program errors early The.
Advertisements

Internal Documentation Conventions. Kinds of comments javadoc (“doc”) comments describe the user interface: –What the classes, interfaces, fields and.
Utilities (Part 3) Implementing static features 1.
Conversation Form l One path through a use case that emphasizes interactions between an actor and the system l Can show optional and repeated actions l.
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.
16-Jun-15 Exceptions. Errors and Exceptions An error is a bug in your program dividing by zero going outside the bounds of an array trying to use a null.
23-Jun-15 HTML. 2 Web pages are HTML HTML stands for HyperText Markup Language Web pages are plain text files, written in HTML Browsers display web pages.
26-Jun-15 Methods. About methods A method is a named group of declarations and statements If a method is in the same class, you execute those declarations.
Chapter 10 Classes Continued
Algorithm Programming Coding Advices Bar-Ilan University תשס " ו by Moshe Fresko.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMING PRACTICES API documentation.
Ranga Rodrigo. Class is central to object oriented programming.
1 Web Based Programming Section 6 James King 12 August 2003.
CPSC 252 Exception Handling Page 1 Exceptions and exception handling Client programmers can make errors using a class attempting to dequeue an item from.
(1) Coding Standards Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu HI
Java: Chapter 1 Computer Systems Computer Programming II.
Java Language and SW Dev’t
PHP meets MySQL.
JavaDoc1 JavaDoc DEPARTMENT OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING CONCORDIA UNIVERSITY July 24, 2006 by Emil Vassev & Joey Paquet revision 1.2 –
07 Coding Conventions. 2 Demonstrate Developing Local Variables Describe Separating Public and Private Members during Declaration Explore Using System.exit.
The Java Programming Language
Program documentation Using the Doxygen tool Program documentation1.
Program documentation using the Javadoc tool 1 Program documentation Using the Javadoc tool.
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:
Classes CS 21a: Introduction to Computing I First Semester,
Java Syntax and Style JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin,
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Utilities (Part 2) Implementing static features 1.
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
23-Oct-15 Abstract Data Types. 2 Data types A data type is characterized by: a set of values a data representation, which is common to all these values,
Everything Is an Object Manipulate objects with references The identifier you manipulate is actually a “reference” to an object. Like a television.
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.
Software Documentation Section 5.5 ALBING’s Section JIA’s Appendix B JIA’s.
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
Documentation javadoc. Documentation not a programmer's first love lives in a separate file somewhere usually a deliverable on the schedule often not.
Javadoc A very short tutorial. What is it A program that automatically generates documentation of your Java classes in a standard format For each X.java.
CSC 212 – Data Structures Prof. Matthew Hertz WTC 207D /
CSC Programming I Lecture 6 September 4, 2002.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
JavaDoc and Contracts Spring Documenting Contracts with JavaDoc Contract model for methods Preconditions Postconditions JavaDoc Industry standard.
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.
1  lecture slides online
Page 1 – Autumn 2009Steffen Vissing Andersen SDJ I1, Autumn 2009 Agenda: Java API Documentation Code Documenting (in javadoc format) Debugging.
Java Doc Guideline R.SANTHANA GOPALAN. Java Doc Guideline Audience Internal Developers PQA - who write test plans PPT – who write the documentation Customers.
TCU CoSc Introduction to Programming (with Java) Java Language Overview.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
28-Feb-16 How to Write Good Comments. 2 Write for your audience Program documentation is for programmers, not end users There are two groups of programmers,
Today Javadoc. Packages and static import. Viewing API source code. Upcoming Topics: –protected access modifier –Using the debugger in Eclipse –JUnit testing.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Advanced Programing practices
More Sophisticated Behavior
Working with Java.
Chapter 11 Object-Oriented Design
How to Write Good Comments
Introduction to javadoc
Chapter 1: Computer Systems
JavaDoc and Contracts Fall 2008.
Anatomy of a Java Program
Advanced Programing practices
How to Write Good Comments
How to Write Good Comments
Introduction to javadoc
How to Write Good Comments
Classes CS 21a: Introduction to Computing I
How to Write Good Comments
Presentation transcript:

1 Doc Comment Conventions

2 Write for your audience Rule 32: Write documentation for– those who must use your code Users should not need to care how your code works those who must maintain your code Maintainers need to understand your code These two groups of people require different kinds of documentation javadoc is the best way to document for users use internal comments to explain “how it works”

3 javadoc javadoc is a separate program that comes with every Java installation javadoc reads your program, makes lists of all the classes, interfaces, methods, and variables, and creates an HTML page displaying its results This means javadoc documentation is always accurate Your doc comments are integrated into javadoc ’s HTML page It’s your job to ensure these are also accurate BlueJ includes a limited version of javadoc

4 javadoc Rule 35: Use documentation comments (javadoc) to describe the programming interface javadoc can be set to display: only public things (classes, methods, fields) public and protected things public, protected, and package things everything, even private things BlueJ emphasizes simplicity--doesn’t give options Always write doc comments for the user of your classes (a programmer)

5 Contracts “The primary purpose for documentation comments is to define a programming contract between a client and a supplier of a service. The documentation associated with a method should describe all aspects of behavior on which a caller of that method can rely and should not attempt to describe implementation details.” --The Elements of Java Style (Rule 35)

6 Know where to put comments! javadoc comments must be immediately before: a class an interface a constructor a method a field Anywhere else, javadoc comments will be ignored! Plus, they look silly

7 javadoc comment style Rule 42: Use a single consistent format and organization for all documentation comments. /** * This is where the text starts. The star lines * up with the first star above; there is a space * after each star. The first sentence is the most * important: it becomes the “summary.” * these go at the end, after a blank line */ void myMethod() { // this lines up with the / in /**

8 HTML in doc comments Doc comments are written in HTML In a doc comment, you must replace: with >...because indicate tags in HTML Other things you may use:... to make something italic Example: This case should never occur!... to make something boldface to start a new paragraph Other types of comments are not in HTML

9 Identifiers in doc comments Rule 43: Wrap keywords, identifiers, and constants with... tags Example: /** * Sets the programIsRunning flag * to false, thus causing * run() to end the Thread * doing the animation. */

10 Code in doc comments Rule 44: Wrap code with... tags. Preformatted text is shown in a monospaced font (all letters the same width, like Courier), and keeps your original formatting (indentation and newlines) Preformatted text is also good for ASCII “drawings” NW N NE \ | / W — + — E / | \ SW S SE

11 Tags in doc comments I Rule 46: Establish and use a fixed ordering for javadoc tags. In class and interface descriptions, your a version number or date Use tag in your assignments!!! In method descriptions, p A description of parameter A description of the value returned (unless it’s e Describe any thrown exception.

12 Tags in doc comments II Rule 54: Fully describe the signature of each method. The signature is what distinguishes one method from another the signature includes the number, order, and types of the parameters Use tag to describe each tags should be in the correct order Don’t mention the parameter type; javadoc does that Use tag to describe the result (unless it’s void )

13 Keep comments up to date Rule 33: Keep comments and code in sync An incorrect comment is often worse than no comment at all Rule 38: Describe the programming interface before you write the code. It’s better to decide what to do, then do it than it is to do something, then try to figure out what you did

14 Document nearly everything Rule 39: Document public, protected, package, and private members. Personally, I don’t see much need to document private variables, provided they have good, meaningful names Rule 40: Provide a summary description and overview for each package. In other words: tell what your program does!

15 this object Rule 52: Use “this” rather than “the” when referring to instances of the current class. In Java, this is a keyword that refers to the instance of this class that is responding to the message (that is, the instance that is executing the method) Hence, this object has an especially clear meaning in comments Example: Decides which direction this fox should move. (As a comment in the Fox class)

16 Parentheses C and C++ programmers, pay attention! Rule 52: Do not add parentheses to a method or constructor name unless you want to specify a particular signature. If, in a comment, you refer to turn( ), you are implying that turn is a method with no parameters If that’s what you meant, fine If that’s not what you meant, say turn instead Why is this different from C and C++? In C, method overloading is not allowed C++ programming is strongly rooted in C

17 Write summaries Rule 53: Provide a summary description for each class, interface, field, and method. The first sentence in each doc comment is special; it is used as the summary sentence javadoc puts summaries near the top of each HTML page, with a link to the complete doc comment further down the page Rule 48: Write summary descriptions that stand alone.

18 Rules for writing summaries Rule 49: Omit the subject in summary descriptions of actions or services. Rule 47: Write in the third-person narrative form. Good: Finds the first blank in the string. Not as good: Find the first blank in the string. Bad: This method finds the first blank in the string. Bad: Method findBlank(String s) finds the first blank in the string.

19 Include examples Rule 55: Include examples if they are helpful. Most methods should be simple enough not to need examples Sometimes an example is the best way to explain something

20 Input and output conditions Rule 56: Document preconditions, postconditions, and invariant conditions. A precondition is something that must be true beforehand in order to use your method Example: The rabbit must be alive A postcondition is something that your method makes true Example: The rabbit is not against an edge An invariant is something that must always be true about an object Example: The rabbit is in a valid row and column

21 Bugs and missing features Rule 57: Document known defects and deficiencies. What? Admit my code isn’t perfect? That might lower my grade, or get me in trouble with my boss! But it will be worse if they discover it themselves Pity the poor user, struggling to find the bug in her code, when the bug is really in yours

22 Who cares? Aren’t we supposed to be learning how to program in Java, not a bunch of stupid “style rules”? Or in other words: What do we care what our teachers and prospective employers think?

23 Aren’t these just arbitrary conventions? All these rules have good reasons, but some rules are more important than others Keep comments and code in sync (Rule 33) This rule is important Write in the third person narrative form (Rule 47) That’s “just” ordinary good writing style Good documentation is essential in writing, debugging, and maintaining a large program It even helps in small programs

24 When do you add comments? There is always time at the start of a project There is never time at the end of a project Remember the 90/90 rule: The first 90% of a project takes the first 90% of the time; the remaining 10% of the project takes the remaining 90% of the time. (Yes, that adds to 180%. That’s the point!) Rule 3: Do it right the first time. Rule 38: Describe the programming interface before you write the code.

25 Vocabulary I Preformatted text: HTML text that maintains your indentation and spacing Monospaced font: One in which all the letters (and usually other characters) have the same width Signature of a method: The information needed to distinguish one method from another

26 Vocabulary II Precondition: A condition that must be true before a method (or other block of code) if it is to work properly Postcondition: A condition that is made true by executing a method (or other block of code) Invariant: A condition that must always be true of an object. 90/90 rule: The first 90% of a project takes the first 90% of the time; the remaining 10% of the project takes the remaining 90% of the time.

27 The End