Internal Documentation Conventions. Kinds of comments javadoc (“doc”) comments describe the user interface: –What the classes, interfaces, fields and.

Slides:



Advertisements
Similar presentations
Chapter 8 Technicalities: Functions, etc. Bjarne Stroustrup
Advertisements

1-May-15 Style. 2 About the book This book is a team effort by many good programmers, not just one person’s opinions The rules have been widely distributed.
Chapter 29: Integration Jacob Harper. The Integration Approach The order of adding components to a system is crucial Benefits to careful integration –
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
Debugging Introduction to Computing Science and Programming I.
15-Jun-15 Style Consolidated Lectures. 2 About the book This book is a team effort by many good programmers, not just one person’s opinions The rules.
15-Jun-15 Beginning Style. 2 Be consistent! Most times, you will enter an ongoing project, with established style rules Follow them even if you don’t.
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 Recursion. 2 Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example:
18-Jun-15 Arrays. 2 A problem with simple variables One variable holds one value The value may change over time, but at any given time, a variable holds.
1 Introduction to Software Engineering Lecture 42 – Communication Skills.
Loops – While, Do, For Repetition Statements Introduction to Arrays
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.
28-Jun-15 Recursion. 2 Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example:
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.
29-Jun-15 Recursion. 2 Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example:
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Algorithm Programming Coding Advices Bar-Ilan University תשס " ו by Moshe Fresko.
Programming – Touch Sensors Intro to Robotics. The Limit Switch When designing robotic arms there is always the chance the arm will move too far up or.
Arrays, Conditionals & Loops in Java. Arrays in Java Arrays in Java, are a way to store collections of items into a single unit. The array has some number.
Games and Simulations O-O Programming in Java The Walker School
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
1 Web Based Programming Section 6 James King 12 August 2003.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Karel J Robot An introduction to BlueJ and Object- Oriented Programming.
CSC204 – Programming I Lecture 4 August 28, 2002.
Control Structures. Important Semantic Difference In all of these loops we are going to discuss, the braces are ALWAYS REQUIRED. Even if your loop/block.
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
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,
Java Coding Standards and Best Practices Coding Standards Introduction: After completing this chapter, you will able to keep your code up to standards.
Best Practices. Contents Bad Practices Good Practices.
6/3/2016 CSI Chapter 02 1 Introduction of Flow of Control There are times when you need to vary the way your program executes based on given input.
Chapter 8 Repetition Statements. Introduction Iteration - process of looping or the repetition of one or more statements Loop body - the statement, or.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
CSC 212 – Data Structures Prof. Matthew Hertz WTC 207D /
Self-Documenting Code Chapter 32. Kinds of Comments  Repeat of code  Explanation of code  Marker in code  Summary of code  Description of code’s.
CMP-MX21: Lecture 5 Repetitions Steve Hordley. Overview 1. Repetition using the do-while construct 2. Repetition using the while construct 3. Repetition.
CIS 234: Project 1 Issues Dr. Ralph D. Westfall April, 2010.
Computing and Statistical Data Analysis Lecture 2 Glen Cowan RHUL Physics Computing and Statistical Data Analysis Variables, types: int, float, double,
Coding Conventions  Coding conventions are a set of guidelines for a specific software project that recommend programming style, practices and methods.
CS 11 C track: lecture 2 Last week: basics of C programming compilation data types ( int, float, double, char, etc.) operators ( + - * / = == += etc.)
Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, Pearson Addison-Wesley. All rights reserved. Chapter 4 Slide #1.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
ATS Programming Short Course I INTRODUCTORY CONCEPTS Tuesday, Feb 10th, 2009 Introduction to Programming.
Flow of Control Joe McCarthy CSS 161: Fundamentals of Computing1.
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,
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
Today… Preparation for doing Assignment 1. Invoking methods overview. Conditionals and Loops. Winter 2016CMPE212 - Prof. McLeod1.
Communicating in Code: Commenting Programming Studio Spring 2009 Note: several examples in this lecture taken from The Practice of Programming by Kernighan.
Flow Control. Comments u Comments: /* This is a comment */ –Use them! –Comments should explain: v special cases v the use of functions (parameters, return.
Working with Java.
The switch Statement, and Introduction to Looping
Chapter 3 Loops Section 3.3 Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
Loop Structures.
Repeating code We could repeat code we need more than once: i = 1 print (i) i += 1 print (i) #… stop when i == 9 But each line means an extra line we might.
How to Write Good Comments
Chapter 1: Computer Systems
Communicating in Code: Commenting
Coding Concepts (Basics)
CSC215 Lecture Flow Control.
CISC124 Labs start this week in JEFF 155.
How to Write Good Comments
How to Write Good Comments
How to Write Good Comments
How to Write Good Comments
CSC215 Lecture Control Flow.
Chapter 3 Flow of Control Loops in Java.
Presentation transcript:

Internal Documentation Conventions

Kinds of comments javadoc (“doc”) comments describe the user interface: –What the classes, interfaces, fields and methods are for –How to use them Obviously, the maintainer needs to know what the code does In addition, the maintainer needs to understand how the code works

Kinds of internal comments “Standard” (C-style) comments: /*... */ One-line and end-line comments: // a one-line comment is on a line by itself x = 0; // an end-line comment follows code –These are both “internal” comments, seen only by someone looking at your code –Internal comments are only for maintainers –But avoid things that would embarrass you to a user!

Which kind of internal comment? Rule 36: Use “standard” (/*...*/) comments to comment out code without removing it. I don’t agree –Suggested because it’s usually easy to do, but... –BlueJ’s comment and uncomment commands make it easier to use one-line ( //... ) comments –Standard comments cannot be nested, so it’s tricky commenting out code with comments One-line comments don’t have this problem

Explaining the code I Rule 59: Add internal comments only if they will aid in understanding your code. Don’t repeat the javadoc comments Don’t put in comments to explain things that are obvious from the code Don’t put in irrelevant or useless comments // Diamondbacks beat the Yankees, Always put comments before the code they describe, never after the code

Explaining the code II Rule 37: Use one-line comments to explain implementation details. One-line comments are also good for writing reminders for yourself about things you still need to work on // need to rewrite this if more than one rabbit I like to use one-line comments to tell what the next block of code is going to do // put the rabbit in a random location

End-line comments I Rule 61: Avoid the use of end-line comments. –This rule is largely to prevent overly long lines –But: Rule 62: Explain local variable declarations with an end-line comment. int edgeDistance; // distance to the nearest edge –And: Rule 64: Label closing braces in highly nested control structures. } // end switch } // end if } // end for j } // end for i

End-line comments II I also find end-line comments useful for an else that is a long way from its if : if (distance > 5) { a lot of code in between } else { // distance <= 5... }

Unresolved issues Rule 63: Establish and use a set of keywords to flag unresolved issues. –I personally like to use $$ // $$ the canvas isn't being redrawn properly –More specific flags are likely to be used in large projects

Intentionally missing break Rule 65: Add a “fall-through” comment between two case labels of a switch statement, if no break statement separates those labels. –The switch statement is so badly designed that forgetting the break is a common error –To keep an intentionally missing break from being “corrected,” add a comment

Label empty statements Sometimes you intentionally use a loop with an empty statement body Rule 66: Label empty statements. while ((c = reader.read()) == space) ; // Empty body I prefer a different solution: use an empty block as the statement body while ((c = reader.read()) == space) { }

Don’t repeat the code Rule 60: Describe why the code is doing what it does, not what the code is doing. Another way of saying this is: Comments should not echo code. –Here’s a typical example of a bad comment: count = 0; // set count to zero You should assume that anyone reading your internal comments knows some Java!

Use the active voice Rule 34: Use the active voice, and omit needless words –// zero out the array –// each of the elements of the array is set to // zero by the following loop Writing comments is still writing--all the rules for good writing apply to comments Best reference: The Elements of Style, by Strunk and White

Debugging statements We sometimes put in debugging statements that we plan to remove afterwards Simple trick: start these “temporary” statements in the first column, so you can find them easily boolean legalLocation(int row, int col) { System.out.println("legalLoc " + row + " " + col); return row >= 0 && row = 0 && column < numCols; }

The End