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

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

Write for your audience

Initial Coding Guidelines

CSE 11 Style Guidelines

QueueBlock, ReversalADT, LinkedList,CustomerAccount, not MaintainCustomerData

CS106A, Stanford Handout #30. Coding Style

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

CS 351 Design of Large Programs Coding Standards

Documentation Requirements Computer Science 2334 Spring 2016

Java Programming Style Guide

Advanced Microsoft Word 2010

CSCI 2101 Java Style Guide

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

CSE331 Winter 2014, Midterm Examination February 12, 2014

Java Programming Tutorial 1

Documenting Advanced Programming Techniques

EE 382 Style Guide. March 2, 2018

Coding Style Handout #15 February 1, CS106A Winter

CS 251 Intermediate Programming Coding Standards

Javadoc. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 7

Assignment Marking Criteria

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

Identifiers. Identifiers are the words a programmer uses in a program Some identifiers are already defined. Some are made up by the programmer:

Supplement D: Expanded Guidelines on Programming Style and Documentation

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

Chapter Two Bonus Lesson: JavaDoc

UNDERSTANDING CLASS DEFINITIONS CITS1001

FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING UNIT III. 2 Marks PROBLEM SOLVING AND OFFICE AUTOMATION

Data Abstraction and Specification of ADTs

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

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

Maintainability and Readability. What makes code readable? Understandable code. General Routine Structure. General Module Structure

Creating Word Outlines from Compendium on a Mac

C++ Programming Style Guide

Expanded Guidelines on Programming Style and Documentation

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

Computer Nashua Public Library Advanced Microsoft Word 2010

CSE 142/143 Unofficial Commenting Guide Eric Arendt, Alyssa Harding, Melissa Winstanley

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

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

Introduction to Programming Style

For the purposes of this course, the following coding guidelines are in effect.

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

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

Example Program. public class ComputeArea {

The NetBeans IDE is a big file --- a minimum of around 30 MB. After you have downloaded the file, simply execute the file to install the software.

Examination in Compilers, EDAN65

CSCI 4000 Assignment 1

CS 152 Computer Programming Fundamentals Coding Standards

Computer Components. Software{ User Programs. Operating System. Hardware

CSSE2002/7023 The University of Queensland

CPS122 Lecture: Defining a Class

Guidelines for Writing C Code

HTML/CSS Lesson Plans

Mobile App:IT. Methods & Classes

11 Coding Standards CERTIFICATION OBJECTIVES. Use Sun Java Coding Standards

Full file at

Pace University. Fundamental Concepts of CS121 1

5. Control Statements

CS 251 Intermediate Programming Methods and Classes

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

CS 251 Intermediate Programming Methods and More

CS112 Lecture: Defining Instantiable Classes

Module 1: Introduction to Computers, Programs, and Java

CSCI 1226 Sample Midterm Exam

Documenting Java Code. Javadoc: The Tool and the Legend

C Language Coding Standard

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

CSE 142/143 Unofficial Style Guide

CMSC 201 Fall 2018 Python Coding Standards

Pointers, Arrays and Parameters

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

Algorithms and Flowcharts

STUDENT LESSON A12 Iterations

Software Implementation (Writing Quality Code)

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

Chapter 1 INTRODUCTION TO COMPUTER AND PROGRAMMING

Programming Assignment 2 ( 100 Points )

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s

Chapter 2: Programming Concepts

APS105. Modularity. C pre-defined functions 11/5/2013. Functions. Functions (and Pointers) main. Modularity. Math functions. Benefits of modularity:

SML Style Guide. Last Revised: 31st August 2011

Computer Components. Software{ User Programs. Operating System. Hardware

Recap: Functions as first-class values

Final Exam. COMP Summer I June 26, points

User Defined Functions

Code Convention and version control help us to success in Botball

COMP 202 Java in one week

PROBLEM SOLVING AND OFFICE AUTOMATION. A Program consists of a series of instruction that a computer processes to perform the required operation.

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

CSCE150A. Introduction. While Loop. Compound Assignment. For Loop. Loop Design. Nested Loops. Do-While Loop. Programming Tips CSCE150A.

Chapter 5 Lab Methods

CSCI 262 C++ Style Guide

Control Structures in Java if-else and switch

C++ Coding Standards and Practices. Tim Beaudet March 23rd 2015

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

CS 302: INTRODUCTION TO PROGRAMMING IN JAVA. Chapter 5: Methods. Lecture 10

Computer Science & Engineering 150A Problem Solving Using Computers. Chapter 5. Repetition in Programs. Notes. Notes. Notes. Lecture 05 - Loops

def F a c t o r i a l ( n ) : i f n == 1 : return 1 else : return n F a c t o r i a l ( n 1) def main ( ) : print ( F a c t o r i a l ( 4 ) )

Transcription:

User Interface Programming OOP/Java Primer Step 3 - documentation Department of Information Technology Uppsala University

What is the documentation? Documentation about program in the program Clearly written code (!) Good naming Conventions Expressive names Anything else that makes the program easy to read and understand!

Good programming style Good structure Modularity Programming concepts Clarity Naming conventions Clear coding Documentation Public documentation Javadoc Internal documentation commented code

Good Programming Style implies Good Documentation

Quick guidelines Make the code clear and easy to read. Make the code consistent. Use obvious identifier names. Logically organize your files and classes. Have only one class per file (not including inner classes). Use a maximum line width of 80-90 characters. Use whitespace and/or other separators judiciously. Use spaces instead of tabs for indentation.

Good structure The structure of a program should mirror the purpose of the program Package structure File structure Class structure Indentation! Avoid having more than 2000 lines in one file Including documentation

Well-considered: Purpose? Purpose of program Purpose of package Purpose of class Purpose of method

Modularity Files in the same package should have a common higher theme Use subpackages to structure large packages Cf. The API structure! Name every package! Don t put files in the default package

Programming Concepts Make sure you display the intention of the code through the programming concepts Loops what is the loop doing? Is it a loop or a pass through a collection? Data structure what are they storing?

Example for (int i = 0;i<100; i++) { check(x[i]); } or Iterator iterator = x.iterator(); while(iterator.hasnext()) { check(iterator.next()); }

Programming Concepts Programming concepts have a meaning Clear use of concepts makes the code more transparent Even if the code works it might still be contradictory

Clarity The code should be clear and readable Indentation shows scope! Variable scope can be difficult to judge Variable names should display the content Method names should display what they do

Conventions Loop variables: i,j,k,m,n, commonly used in non-semantic loops loop through arrays, pixelmaps etc the indexes have no meaning in themselves Coordinate variables: x,y,z,... a commonly used for working with GUI positions pixelmaps where we are interested in the pixel value (a = normally alpha value) Following conventions increases readability

Temporary variables The name temp can be used, but should be complemented by the content type: tempfile, tempcounter, tempname Temporary variables are not just temporary holders of information, they are TYPED! Be careful with scope Don t reuse a temporary variable in other places!

Variables Be generous with letters Use long names! Use describing names Make the names unique (not sum1, sum2, etc.) Use of the wrong variable is easier to detect, if you have longer, meaningful names, cf. s = h/k

Variables Be generous with letters Use long names! Use describing names Make the names unique (not sum1, sum2, etc.) Use of the wrong variable is easier to detect, if you have longer, meaningful names, cf. s = h/k speed = hours/kilometers

Methods The name of a method should tell the story Use long names if needed The compiler will detect errors for you if you spell them wrong NetBeans will suggest the method for you Long, meaningful names will enhance the readability of the code

Long, meaningful names One important drawback! Make sure to also change the name, if you change the functionality!!! If you correct a conceptual bug, the name might have to change: addinterest(int sum) needs to change name if we change the functionality so that it subtracts the interest

Clear Coding Avoid smart solutions It is better to have a few more steps in the code The Compiler will most of the time be able to optimize it. A temporary variable is cheap Try to make clear steps in the code Make sure the code is logical Finish one thing in the code before starting a new Don t mix several tasks in the code unless necessary

Complex code If you need to write complex code in a method you should provide one of: pseudo code in the comments an English description of what you are doing Not the procedure, but the effect! Complex code could sometimes be rewritten Can you extract part of it as a separate method? Can you indent or restructure the code for better readability?

Complex code Some ways to approach complex code: Try to explain it to a fellow programmer Try to explain it to a non-programmer

Documentation Public documentation: Javadoc Documentation follows specific rules Special sections and keywords Compiles to an API description Local documentation Documents the thoughts in the code Supports understanding, reading and debugging Just as important as the public Documentation

Javadoc A documentation system for code Generates the HTML-documentation of your system. Inline comments Keywords Supported by NetBeans

Comment types /* */ Comment area (one or more lines) // Single line comment (rest of the line) /** */ Javadoc Comment (one or more lines)

Keywords A javadoc keyword is used to mark special parts of documentation: @author the author of the class @version the version nr of the class @param a parameter for a method (one keyword per parameter @return the return value of a function @exception the exception thrown

Typical /** * Summary sentence. * More general information about the * program, class, method or variable which * follows the comment, using as many lines * as necessary. * * zero or more tags to specify more specific kinds * of information, such as parameters and return * values for a method */ It is good practice to use the star at the beginning of every line!

Variable description /** * The number of students in the class. * This variable must not be * negative or greater than 200. */ public int numstudents;

/** Method description * Draws an arrow between the two points * given as arguments. * @param point1 the starting point * @param point2 the end point * (arrowhead) */ If the method had returned a value, we would have had a @return tag as well.

Formatting Javadoc can use the basic HTML-tags for simple formatting. <br> line break <p> new paragraph <pre> </pre> preformatted text (

Inline comments A textline initiated by // A textblock surrounded by /* */ Crucial for understanding the code But do not over-comment

What s in a comment? Meaningful and useful information // increase counter two steps first time (why?) Don t write the obvious info, but the thoughts behind. // Add 1 to x (yes, and???) Give the information that is not there already What is the reason for adding? // Don t ask how this works, it does, don t change! I WANT to know! That s why the comment is there // Loop We can probably see that in the code!

Comments /** * This message repaints a warning icon (the badge) over the field given as * parameter. * * @param field the field over which to repaint the icon. */ private void repaintbadge(jcomponent field) { Javadoc Parameter } // First we get the fields location on the screen (!), and convert it to a // point located on this JComponent. // Point p = field.getlocationonscreen(); SwingUtilities.convertPointFromScreen(p, this); // Find out the size of the warning icon and set its position to a point // that is moved slightly for visual appearance. // int x = p.x - warningicon.getwidth() / 2; int y = (int) (p.y + field.getheight() - warningicon.getheight() / 1.5); // Here we call repaint (!), but with a definition of the dirty area, // so that we only paint the icon! // repaint(x, y, warningicon.getwidth(), warningicon.getheight()); Describes the meaning of the code Very little reference to the coded steps and calculations

Comments Should be used with care Should explain what you are doing Not parafrase the algorithm Should clarify the code Can also be too extensive

Your comments Follow good style as described here Add: If a class is co-authored, each method should have a note about the author Important design rationale should go in the class documentation

Further Read the Java Code Conventions! Link on the course home page.