CS 251 Intermediate Programming Coding Standards

Similar documents
CS 152 Computer Programming Fundamentals Coding Standards

CS 351 Design of Large Programs Coding Standards

CS 351 Design of Large Programs

Documentation Requirements Computer Science 2334 Spring 2016

Assignment Marking Criteria

11 Coding Standards CERTIFICATION OBJECTIVES. Use Sun Java Coding Standards

CSE 11 Style Guidelines

Coding Standard for ECE3090 August 24, 2005

CSE 142/143 Unofficial Style Guide

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

CSCI 2101 Java Style Guide

QueueBlock, ReversalADT, LinkedList,CustomerAccount, not MaintainCustomerData

Identifiers and Variables

CS 251 Intermediate Programming Java Basics

IT Web and Software Developer Software Development Standards

CSCI 1060U Programming Workshop

What does this program print?

Beginning Style. 16-Nov-15

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

Java Programming Style Guide

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

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

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

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

PROGRAMMING STYLE. Fundamentals of Computer Science I

Programming Syntax and Style. David Greenstein Monta Vista High School

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

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

CMSC 201 Fall 2018 Python Coding Standards

Coding Standards for Java

CSCI 262 C++ Style Guide

C++ Programming Style Guide

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

Chapter 2 Author Notes

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

Lab # 2. For today s lab:

Full file at

Expanded Guidelines on Programming Style and Documentation

Programming Style Guide v1.1

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

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

Coding Style Handout #15 February 1, CS106A Winter

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

class objects instances Fields Constructors Methods static

EE 382 Style Guide. March 2, 2018

Formatting & Style Examples

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

Supplement D: Expanded Guidelines on Programming Style and Documentation

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.

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

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

Java Program Coding Standards Programming for Information Technology

EECS 280 C++ Coding Standards

Chapter 2: Programming Concepts

ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1

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

Lecture 27. Lecture 27: Regular Expressions and Python Identifiers

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

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

Conditionals, Loops, and Style

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

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

Key Differences Between Python and Java

Computer Programming : C++

CSE 230 Intermediate Programming in C and C++ Functions

CS 231 Data Structures and Algorithms, Fall 2016

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

Perl Basics. Structure, Style, and Documentation

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

Coding Standards for C

Using C++, design an Abstract Data Type class named MyGrades. The class must have the following private members :

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

Coding Standards for C

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

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

CS Problem Solving and Object-Oriented Programming

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.

BLM2031 Structured Programming. Zeyneb KURT

This course supports the assessment for Scripting and Programming Applications. The course covers 4 competencies and represents 4 competency units.

Scala Style Guide Spring 2018

C Formatting Guidelines

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

Introduction to C Programming

Java objects: a first view [Reading: chapters 1 & 2] CSC 142 B 1

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

Project 1: Scheme Pretty-Printer

Write for your audience

Welcome to... CS113: Introduction to C

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

Laboratory Assignment #3 Eclipse CDT

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

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

Java Fall 2018 Margaret Reid-Miller

CS106A, Stanford Handout #30. Coding Style

Initial Coding Guidelines

CS : Programming for Non-majors, Fall 2018 Programming Project #2: Census Due by 10:20am Wednesday September

CPS122 Lecture: Defining a Class

CS : Programming for Non-majors, Summer 2007 Programming Project #2: Census Due by 12:00pm (noon) Wednesday June

Working with JavaScript

Transcription:

CS 251 Intermediate Programming Coding Standards Brooke Chenoweth University of New Mexico Fall 2018

CS-251 Coding Standards All projects and labs must follow the great and hallowed CS-251 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.

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 - 251 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 has a place in complex projects, but in this course, it is generally a sign that you forgot the access modifier.

Packages Unless otherwise specified, all code you submit for this course shall be placed in the default (nameless) package. Multiple packages are helpful for organizing larger programs, but it is overkill for our small labs.

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.

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.

Last Word... Use clean coding standards as you code. Of course, only the end product is graded; however, if you take the time to maintain proper indenting and formatting as you write your code, then you will find coding easier. When you show clean code to an instructor, the instructor is more likely to be friendly and will require less time to help you.