CS 351 Design of Large Programs Coding Standards

Similar documents
CS 251 Intermediate Programming Coding Standards

CS 152 Computer Programming Fundamentals Coding Standards

CS 351 Design of Large Programs

Documentation Requirements Computer Science 2334 Spring 2016

CSE 11 Style Guidelines

Assignment Marking Criteria

CSE 142/143 Unofficial Style Guide

11 Coding Standards CERTIFICATION OBJECTIVES. Use Sun Java Coding Standards

Coding Standard for ECE3090 August 24, 2005

CS 251 Intermediate Programming Methods and More

IT Web and Software Developer Software Development Standards

QueueBlock, ReversalADT, LinkedList,CustomerAccount, not MaintainCustomerData

Java Programming Style Guide

CSCI 2101 Java Style Guide

Identifiers and Variables

CS 251 Intermediate Programming Java Basics

CSCI 1060U Programming Workshop

CS 251 Intermediate Programming Methods and Classes

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

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

Coding Standards for Java

ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1

What does this program print?

Beginning Style. 16-Nov-15

Coding Style Handout #15 February 1, CS106A Winter

Objectives. Coding Standards. Why coding standards? Elements of Java Style. Understand motivation for coding standards

PROGRAMMING STYLE. Fundamentals of Computer Science I

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

EECS 280 C++ Coding Standards

Lab # 2. For today s lab:

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

Perl Basics. Structure, Style, and Documentation

Full file at

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

Introduction to Java. Java Programs Classes, Methods, and Statements Comments Strings Escape Sequences Identifiers Keywords

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

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

C++ Programming Style Guide

Chapter 2 Author Notes

CSCI 262 C++ Style Guide

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

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

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

Expanded Guidelines on Programming Style and Documentation

Programming Syntax and Style. David Greenstein Monta Vista High School

COMP 111. Introduction to Computer Science and Object-Oriented Programming. Week 2

Formatting & Style Examples

BLM2031 Structured Programming. Zeyneb KURT

Enums. In this article from my free Java 8 course, I will talk about the enum. Enums are constant values that can never be changed.

Generating/Updating code from whole project

Supplement D: Expanded Guidelines on Programming Style and Documentation

CSCI 161: Introduction to Programming I Lab 1b: Hello, World (Eclipse, Java)

D2: explain how the structure and design of a game can assist in maintenance and capacity for extension.

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

Lecture 27. Lecture 27: Regular Expressions and Python Identifiers

C Formatting Guidelines

Course Coding Standards

Chapter 2: Programming Concepts

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Computer Hardware. Java Software Solutions Lewis & Loftus. Key Hardware Components 12/17/2013

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

Welcome to... CS113: Introduction to C

Variables and Functions. ROBOTC Software

IT 374 C# and Applications/ IT695 C# Data Structures

Lesson 1A - First Java Program HELLO WORLD With DEBUGGING examples. By John B. Owen All rights reserved 2011, revised 2015

Working with JavaScript

class objects instances Fields Constructors Methods static

Variables in C. Variables in C. What Are Variables in C? CMSC 104, Fall 2012 John Y. Park

Key Differences Between Python and Java

Variables in C. CMSC 104, Spring 2014 Christopher S. Marron. (thanks to John Park for slides) Tuesday, February 18, 14

A Fast Review of C Essentials Part I

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

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

Conditionals, Loops, and Style. Control flow thus far. if statement. Control flow. Common branching statement Evaluate a boolean expression

Conditionals, Loops, and Style

Software and Programming 1

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

Project 1. Java Control Structures 1/17/2014. Project 1 and Java Intro. Project 1 (2) To familiarize with

CS 231 Data Structures and Algorithms, Fall 2016

Programming Style Guide v1.1

Hello, World and Variables

Coding Standards for C

Generating/Updating code from whole project

PROGRAM READABILITY. A program's readability readability, which is a measure of how

Coding Standards for C

EE 382 Style Guide. March 2, 2018

CMSC 201 Fall 2018 Python Coding Standards

CS106A, Stanford Handout #30. Coding Style

Basics of Java Programming

Scala Style Guide Spring 2018

Recitation 3 Class and Objects

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

CS 1027b Foundations of Computer Science II Assignment 1: File Compression Due Date: February 5, 11:55 pm Weight: 10%

Object Oriented Programming

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

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

Introduction to Programming Style

Computer Programming : C++

CS11 Java. Fall Lecture 1

CSE 230 Intermediate Programming in C and C++ Functions

Transcription:

CS 351 Design of Large Programs Coding Standards Brooke Chenoweth University of New Mexico Spring 2018

CS-351 Coding Standards All projects and labs must follow the great and hallowed CS-351 coding standards. These standards do not necessarily represent the best nor the only good way to write Java code. If you have experience programming, then these standards may not be the standards you are used to using. However, in this class, these are the standards we will use.

Primary Reasons for Defined Standard 1. A standard makes it easier for the instructors to read your code. 2. A class standard makes it easier for a grader to recognize when a program does not use a consistent standard. Often when each student is allowed to define his or her own standard, students switch standards multiple times in a single project. It is tedious for a grader to deduce each persons standard and then check for self-consistency. 3. It is good practice to learn to follow a standard.

Coding Standard: Naming Multi-word names are generally written in mixed-case (also known as camelcase). Internal words start with a capital letter. All variables not declared final shall begin with a lowercase letter. Non-local variables that do not ever change value (that is, constants) shall be declared final and shall be all uppercase with words separated by underscores. All class and member variables (non-local variables) will be given descriptive names. Never use the single letter l nor the single letter O as a name.

Coding Standard: Naming Method names must be descriptive (usually verbs) and start with a lowercase letter. All class and interface names shall be descriptive (usually nouns) and begin with an uppercase letter.

Coding Standard: Indenting Code blocks will be indented to show the block structure with four spaces per level. (Note: I often use only two spaces in order to fit on the slides. Do as I say, not as I do.) Tab characters shall not be used for indenting. All statements within a block must be indented to the same level. You should be able to configure your text editor to use spaces to indent to the correct level when you type a tab. (IntelliJ IDEA uses spaces by default.)

Coding Standard: Curly Braces Open brace is last non-space character on a line. Closing brace begins a line and is indented to the beginning of the block. Exceptions: Empty/single statement class/method body. public class ExampleClass { private int mynumber ; } public static void main ( String [] args ) { // statements go here } private void emptymethod () {} private void singlestatementbody () { mynumber ++; }

Coding Standard Blocks and { } Whenever a structure spans more than one line, curly braces must be used. For example: /* OK */ if (x == 5) y=y +1; /* OK */ if (x == 5) { y=y +1; } /* Not CS - 351 standard */ if (x == 5) y=y +1; /* OK */ if (x == 5) { y=y +1; }

Comments At the top of every.java file, there must be a Javadoc comment block with your name, a description of the what the class/interface is used for and how to use it. Before every public method, there must be a Javadoc comment block describing what the method does, its parameters, and its return value. (You may comment non-public methods, too, if you wish.) There must be a Javadoc comment describing any public variables, enums, nested classes, etc. (Again, good idea to comment non-public stuff too.)

Coding Standard 80 Character Line Max No line shall be more than 80 characters. The best way to avoid overly long statements is by not doing too much in a single statement. Use temporary variables to break up large expressions. If you must keep a long statement, the statement should be broken in a logical place and each line over which the long statement is continued must be indented at least as much as the first line of the statement. (Use more indentation if it improves readability.)

Principle of Least Privilege In computer science, the Principle of Least Privilege requires that in a particular abstraction layer of a computing environment, every module must be able to access only such information and resources that are necessary for its legitimate purpose. Variables used in only one method shall be local variables. Don t make an instance or class variable public without good reason. (Note: I couldn t make it work otherwise is not a good reason!)

Access Modifiers All methods, variables, nested classes, etc. contained within a class shall have an explicit access modifier. In other words, do not use package-private access in this course. Package-private access sometimes has a place in complex projects, but in this course, it is generally a sign that you forgot the access modifier.

Getters and Setters In Java, when outside access is needed for a field, the class should provide a getter and/or setter for the field. DO NOT blindly auto generate a getter and setter for every field in your class. Only create a getter or setter when there is actually a use for that getter or setter.

Package Names With the complexity of the projects you will write in this course, your code should be organized into named packages. Do not use long chains of sparsely populated directories edu.unm.cs.351.2018.spring.lab1.gui.abc.xyz.foo.java Don t make a separate package just to hold a single class.

Write Self-Documenting Code Self-documenting code uses well-chosen names and has a clear style. The program s purpose and workings should be obvious to any programmer who reads the program, even if the program has no comments. To the extent that is possible, strive to make your programs self-documenting.

Clean up Debug Output When your program is run, it is okay if a few lines of status/debug info is displayed. For example, if the user resizes the window, you might want to have your program print the new window size. However, your program should not be printing pages of debug spew. Either comment out your debug statements or protect them with: if (DEBUG_GUI) or some equivalent. Be sure to turn in a version with all the debug flags set to false.

Java Code Conventions For examples of how to format specific constructs and guidance on issues not covered in these slides, see Java code conventions online.