Dinopolis Java Coding Convention



Similar documents
AppendixA1A1. Java Language Coding Guidelines. A1.1 Introduction

Official Android Coding Style Conventions

Moving from CS 61A Scheme to CS 61B Java

Designing and Writing a Program DESIGNING, CODING, AND DOCUMENTING. The Design-Code-Debug Cycle. Divide and Conquer! Documentation is Code

Software Development (CS2500)

CSE 308. Coding Conventions. Reference

Hypercosm. Studio.

Install Java Development Kit (JDK) 1.8

C Coding Style Guide. Technotes, HowTo Series. 1 About the C# Coding Style Guide. 2 File Organization. Version 0.3. Contents

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Software documentation systems

Lecture 5: Java Fundamentals III

Taxi Service Coding Policy. Version 1.2

The first program: Little Crab

CS 2112 Spring Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

2 The first program: Little Crab

Coding conventions and C++-style

ICT. PHP coding. Universityy. in any

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Decision Logic: if, if else, switch, Boolean conditions and variables

Intellect Platform - The Workflow Engine Basic HelpDesk Troubleticket System - A102

Introduction to Python

Manage Workflows. Workflows and Workflow Actions

Context-sensitive Help Guide

Java Program Coding Standards Programming for Information Technology

BF Survey Plus User Guide

Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459)

JavaScript: Control Statements I

3rd Edition, June standards/ecma-334.htm.

Approach of Unit testing with the help of JUnit

Ohio University Computer Services Center August, 2002 Crystal Reports Introduction Quick Reference Guide

Java Interview Questions and Answers

3 Improving the Crab more sophisticated programming

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

Example of a Java program

How To Write a Technical Lab Report with Practical Examples

Creating a website using Voice: Beginners Course. Participant course notes

The WebShop E-Commerce Framework

Chapter 14: Links. Types of Links. 1 Chapter 14: Links

10 Java API, Exceptions, and Collections

Software Engineering Techniques

CS 241 Data Organization Coding Standards

The C Programming Language course syllabus associate level

Outline. 1 Denitions. 2 Principles. 4 Implementation and Evaluation. 5 Debugging. 6 References

6.170 Tutorial 3 - Ruby Basics

1 Hour, Closed Notes, Browser open to Java API docs is OK

Java Application Developer Certificate Program Competencies

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

Web Service Facade for PHP5. Andreas Meyer, Sebastian Böttner, Stefan Marr

How to Format a Bibliography or References List in the American University Thesis and Dissertation Template

Project 4 DB A Simple database program

Web Development. Owen Sacco. ICS2205/ICS2230 Web Intelligence

#include <Gamer.h> Gamer gamer; void setup() { gamer.begin(); } void loop() {

Using Microsoft Access

JavaScript: Introduction to Scripting Pearson Education, Inc. All rights reserved.

REST Client Pattern. [Draft] Bhim P. Upadhyaya ABSTRACT

GenericServ, a Generic Server for Web Application Development

Programming Languages CIS 443

Capabilities of a Java Test Execution Framework by Erick Griffin

C++ INTERVIEW QUESTIONS

Introduction to Web Services

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

Johannes Sametinger. C. Doppler Laboratory for Software Engineering Johannes Kepler University of Linz A-4040 Linz, Austria

Understanding class definitions

Step-by-Step Instructions for Setting Up a Paper in APA Format

Chapter 1 Java Program Design and Development

BETTER YOUR CREDIT PROFILE

CSC 551: Web Programming. Spring 2004

Programming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions

egovernment Authority [Sharmila Naveen] [07/04/2010]

Programming in Access VBA

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

DESIGN REPORT FOR THE PROJECT INVENTORY CONTROL SYSTEM FOR CALCULATION AND ORDERING OF AVAILABLE AND PROCESSED RESOURCES

From Information to Answers: Transferring Expertise

Java Classes. GEEN163 Introduction to Computer Programming

PL / SQL Basics. Chapter 3

The Rules 1. One level of indentation per method 2. Don t use the ELSE keyword 3. Wrap all primitives and Strings

Software Documentation Guidelines

Help on Icons and Drop-down Options in Document Editor

Parcelhub - Linnworks Custom Courier Integration Script

Online Registrations for Summer Programming Josh Muse & Hannah Peacock (hpeacock@colchestervt.gov)

Fundamentals of Java Programming

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

USERV Auto Insurance Rule Model in Corticon

PA2: Word Cloud (100 Points)

Java CPD (I) Frans Coenen Department of Computer Science

Curriculum Map. Discipline: Computer Science Course: C++

Editors Comparison (NetBeans IDE, Eclipse, IntelliJ IDEA)

The Basic Java Applet and JApplet

Some Scanner Class Methods

Python Loops and String Manipulation

Search Engine Optimization

Syllabus for CS 134 Java Programming

Transcription:

Dinopolis Java Coding Convention Revision : 1.1 January 11, 2001 Abstract Please note that this version of the Coding convention is very much based on IICM s internal Dino coding convention that was used for the development of the predecessor of the Dinopolis library. As such it is very likely to be biased, therefore please post your comments in the discussion forum and help us improve it over time. It is important for a free software project with programmers distributed on the Internet that the code is easy to understand. If programmers follow a common coding convention and some fundamental design guidelines, this goal is easier to reach. If you modify code of others please follow the same convention and style that the original code uses. 1 General Rules The following principles strongly improve the readability and easy maintainance of source code: Simplicity: Also known as the KISS (Keep It Small and Simple) principle. In short this means that classes shall not have fat interfaces and methods shall fulfill exactly one atomic task according to their abstraction level. Intuitivity: In short this means that it shall be possible to read the code like a book and understand it without comments and explanations. Uniformity: In short this means that related pieces of code follow the same principles. For example methods doing the same shall be called the same throughout the code and take the parameters in the same order. As an example a method called copy that takes source and destination as parameters shall always take the parameters in the same order no matter which class implements such a copy method. 1.1 Simplicity of Code The following rules keep the code simple: Classes must not have fat interfaces. 1

Methods have to perform only one atomic task according to their abstraction level. Methods have to be as short as possible (as a rule of thumb not longer than 60 lines of code unless absolutely necessary, methods shorter than 60 lines of code are preferable). 1.2 Intuitivity of Code Following rules apply to keep the code intuitive: Variable names have to be self-explaining in a way that they describe exactly what they are standing for. As an example count stands for a counter variable. One-letter variables like i (as often used for counters) should be avoided. Method names have to be self-explaining in a way that they describe exactly what they are doing. As an example a method public boolean isaccessallowed() has to check if access is allowed and nothing else! If a method performs more than one task the name has to reflect that fact (although methods that perform more than one task are considered bad programming style and shall be avoided!). As an example public void spellcheckandcorrect(document doc) stands for a method that checks the spelling of doc and corrects it if necessary. In this case naming the method just public void spellcheck(document doc) would not reflect that this method also changes the document if necessary and therefore this name is not a good choice. Unnecessary comments are considered disturbing and should be omitted (e.g. // and here x is incremented). In fact comments in well-written code are mostly completely unnecessary. Only in very special cases if e.g. for performance reasons complicated code has to be written comments are necessary and therefore recommended. In this case the complicated algorithm has to be explained in a comment-block above the algorithm and comments in the running code shall be omitted if possible. 1.3 Uniformity of Code Following rules apply to keep code uniform: Methods that perform the same task are always called the same and take the same parameters (e.g. copy(src,dst)). It is bad programming style that a method s signature is e.g. copy(src,dst) in one class and e.g. copy(dst,src) in another! This also applies to the meaning of parameters: It is unwise to define a method int count() and another method int size() that both perform the same task, namely returning the number of elements. Variables that stand for the same are always called the same (e.g. length). This requirement is equal to the requirement for methods above. 2

2 Coding Conventions This section describes the coding conventions for the Dinopolis library. If you follow these rules and those described in the Design Guidlines it can be ensured that your code is easy to read, easy to understand and easy to modify which will make other programmers happy who have to deal with your code. The coding conventions deal with the way code is written. The design guidelines (=how code is written) can be found in the Dinopolis Design Guidlines. 1. The language for code is English. This applies for all names and identifiers in the code as well as for all comments. 2. The principles of simplicity, intuitivity and uniformity as described in section 1 should be followed. 3. Avoid the use of block comments (/* */) in the source code and use the line comments (//) instead. This makes the source code less fragile to erroreneous deletions of code-lines. 4. If it is absolutely necessary to put comments in the code to describe algorithmic details (see also section 1.2) preceed the according code fragment with a comment block rather than spreading the comments across the code fragment. 5. If it is absolutely necessary to clarify non-obvious code write short comments at the end of the appropriate code line. Nevertheless whenever such a comment seems necessary think twice if there is a better obvious solution that doesn t need a comment! 6. When describing a design pattern the name of the book which deals with this pattern should be cited (e.g. [Gamma et al. 1998]). 7. When describing algorithms the names of the book which deals with these algorithms and datastructures should be cited (e.g.[sedgewick 1992]. 8. The source code for every class (even for non-public classes) should reside in a file of its own. The only exception to this rule are inner classes and anonymous classes as it is per definition impossible to put them in files of their own. 9. When writing stand-alone programs the class with the main method in it should not have anything to do with the functional part of the code. The same applies for applets: The Applet class should not have anything to do with the functional part of the code. 10. Every class should be a member of a package. Classes belonging to the default package are undesired, even for testing. 11. Java import statements should be written in the following order: (a) Java Core API classes. (b) Java Extension API classes. (c) Classes from third party APIs. 3

(d) Dino classes. To increase the readability of the import part, all imports should be sorted by package names, that means imported classes belonging to the same package can be found in consecutive lines. Between the three categories mentioned above a single blank line is recommended. Using wildcards in import statements makes updating of classes hard and should therefore be avoided. 12. Classes should be preceded by a Javadoc header of the following form: /** * Description of the class in HTML format, if a useful link can * be given in the running text do this with * @link fully.qualified.class#method(fully.qualified.param) * @author <authorname> * @version <version number> * @see <fully.qualified.classname#methodname(param-classes)> * @deprecated <if applicable write reason here, otherwise omit * this line> */ class DExampleClass In the description text a usage example is highly recommended. 13. Prefix methods by a Javadoc header of the following form: /** * Description of the method in HTML format, if a link can * be given in the running text do this with @link * fully.qualified.classname#methodname(fully.qualified.paramclass) * @param <paramname> <paramdescription> * @return <return value> * @exception <exception> <description when it is thrown> * @see <fully.qualified.classname#methodname(param-classes)> * @deprecated <reason if applicable, otherwise omit this line> */ public Object myfunction(object test_param) throws MySpecialException In the description a usage example is highly recommended. 14. If bad hacks are absolutely unavoidable for whatever reason (e.g. absolutely have to meet a deadline, etc..) they should be tagged by a hack-start and hack-end comment of the following form: 4

// FIXXME (<author, date>) -> <description of the hack> [.. the hack..] // END FIXXME (<author, date>) To facilitate a grep, the keyword FIXXME should be written in upper-case and with at least two X s. More than two are allowed and should be used for really bad hacks - as a rule of thumb: the more X s the word FIXXME contains the worse the hack is, up to a maximum of five X s. All hacks that have found their way into the code should be removed as soon as possible! 15. Name dentifiers according to the following naming conventions: Packages: lowercase Classes: AllWordsCapitalizedWithoutUnderscores Methods: firstwordlowercaserestcapitalizedwithoutunderscores Constants (=finals): ALL UPPER CASE WITH UNDERSCORES Class and instance member variables: all lower case with underscores and with trailing underscore Auto variables (=variables used locally in methods): all lower case with underscores Exceptions: ClassNameEndsWithException Besides these general naming rules some special naming conventions apply: All Classes in the Dino core package should start with D to make them distinguishable from classes of other packages and to avoid name-clashes. The only exception to this rule applies when working with factories that can also be extended from third party application programmers. In this case the classes must not start with a D. All methods which change properties of classes should be named setxxx. The methods returning the value of certain properties of classes can be divided into two categories: getxxx for non-boolean properties and isxxx for boolean values respectively. Example: public void setcounter(int value) public int getcounter() 5

public void setreadonly(boolean value) public boolean isreadonly() 16. The following code structuring conventions apply: Write curly braces around code-blocks in lines of their own. Indent code-blocks by two spaces. Don t use tabs for indentations but use spaces instead. Only indent the code block, not the curly braces! When invoking methods the opening brace always should follow the method name without any whitespaces. Preceed every method definition with the following comment line to make the code more readable: //--------------------------------------------------------------- 6

References [Gamma et al. 1998] Gamma E., Helm R. Jonson R. Vlissides J.: Design Patterns - Elements of Reusable Object-Oriented Software, Addison Wesley (1999). [Sedgewick 1992] Sedgewick R.: Algorithms, Addison Wesley (1992). end of document 7