Formatting & Style Examples

Similar documents
c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

Lecture 4 CSE July 1992

CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting

Full file at C How to Program, 6/e Multiple Choice Test Bank

Numerical Computing in C and C++ Jamie Griffin. Semester A 2017 Lecture 2

Chapter 2, Part I Introduction to C Programming

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

CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

Scala Style Guide Spring 2018

T H E I N T E R A C T I V E S H E L L

CpSc 1111 Lab 5 Formatting and Flow Control

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Coding Standard for ECE3090 August 24, 2005

CpSc 1011 Lab 4 Formatting and Flow Control Windchill Temps

Programming for Engineers Introduction to C

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

Boolean Expressions. Is Equal and Is Not Equal

Add Subtract Multiply Divide

AN OVERVIEW OF C. CSE 130: Introduction to Programming in C Stony Brook University

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

CS 142 Style Guide Grading and Details

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Note : Your program must contain the following 6 functions :

More Complex Versions of the if Statement. Class 13

CSE 142/143 Unofficial Style Guide

4. Structure of a C++ program

Computer Science & Engineering 150A Problem Solving Using Computers. Chapter 3. Existing Information. Notes. Notes. Notes. Lecture 03 - Functions

CpSc 111 Lab 3 Integer Variables, Mathematical Operations, & Redirection

CS 251 Intermediate Programming Coding Standards

EE 382 Style Guide. March 2, 2018

Learning to Program with Haiku

Use of scanf. scanf("%d", &number);

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

Fundamentals of Programming. Lecture 3: Introduction to C Programming

Chapter 2, Part III Arithmetic Operators and Decision Making

CS 351 Design of Large Programs Coding Standards

Overview of C, Part 2. CSE 130: Introduction to Programming in C Stony Brook University

Fundamental of Programming (C)

Boolean Expressions. Is Equal and Is Not Equal

CpSc 1111 Lab 4 Formatting and Flow Control

Chapter 3. Computer Science & Engineering 155E Computer Science I: Systems Engineering Focus. Existing Information.

CSE 11 Style Guidelines

Fundamentals of Programming Session 4

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

Visual Programming. Lecture 3: Loops, Arrays. Mahmoud El-Gayyar

CS 106 Introduction to Computer Science I

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual:

In Fig. 3.5 and Fig. 3.7, we include some completely blank lines in the pseudocode for readability. programs into their various phases.

3 The L oop Control Structure

Chapter 4: Expressions. Chapter 4. Expressions. Copyright 2008 W. W. Norton & Company. All rights reserved.

Chapter 4: Conditionals and Loops

Expressions and Casting. Data Manipulation. Simple Program 11/5/2013

Computer Science & Engineering 150A Problem Solving Using Computers

COMP 202 Java in one week

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Expressions and Casting

CpSc 1111 Lab 9 2-D Arrays

Variables and literals

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

Variables and Functions. ROBOTC Software

CSCI 262 C++ Style Guide

11 Coding Standards CERTIFICATION OBJECTIVES. Use Sun Java Coding Standards

Only to be used for arranged hours. Order of Operations

Visual C# Instructor s Manual Table of Contents

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

C / C++ Coding Rules

Welcome to... CS113: Introduction to C

2.2 Order of Operations

Course Coding Standards

CMSC 201 Fall 2018 Python Coding Standards

Lecture 3 (02/06, 02/08): Condition Statements Decision, Operations & Information Technologies Robert H. Smith School of Business Spring, 2017

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

CS 1044 Program 6 Summer I dimension ??????

Coding Standards for C

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

Section we will not cover section 2.11 feel free to read it on your own

Chapter 6. Decision and Control Statements

Copyright. For more information, please read the Disclosures and Disclaimers section at the end of this ebook. First PDF Edition, February 2013

The Program Specification:

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Coding Standards for C

BRANCHING if-else statements

Discrete Structures Lecture 14

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

How to Format Modern Language Association (MLA) Style Papers

Flow Control. CSC215 Lecture

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

CS 31: Intro to Systems Binary Arithmetic. Martin Gagné Swarthmore College January 24, 2016

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an . Michigan State University CSE 231, Fall 2013

Sets. Sets. Examples. 5 2 {2, 3, 5} 2, 3 2 {2, 3, 5} 1 /2 {2, 3, 5}

1 Getting used to Python

C++ Programming Style Guide

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Outline. Computer programming. Debugging. What is it. Debugging. Hints. Debugging

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING

Introduction. C provides two styles of flow control:

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

Intro to Computer Programming (ICP) Rab Nawaz Jadoon

Transcription:

Formatting & Style Examples The code in the box on the right side is a program that shows an example of the desired formatting that is expected in this class. The boxes on the left side show variations of the same program, most are examples of what NOT to do. In some cases certain things are just not allowed. However, there is some room for personal style, and sometimes consistency is what is important. For example, some instructors insist on a space before and after every math or comparison operator, such as: count > 0; instead of count>0; Personally, I like to have spaces before and after, but that s the type of thing where consistency is more important (I think) so, if you are consistent with no spaces all the way through, then I let that go. Same with curly braces I prefer to have my opening curly brace at the end of the opening line, not on the next line, but if you consistently put them on the next line, then that s ok. An example of something that is not allowed ever is when lines exceed 80 characters (which includes the leading indentation spaces). No indentation, no comments, no header comment, no blank lines Below is the same program as in the box to the right, but without any indentation, comments, or blank lines to break up groups of lines for readability. It s not very often that I get assignments turned in that look this bad, but once in a while, some look almost as bad as this. You will lose up to 20 points if this is what your code looks like even if your program works perfectly. If your program doesn t work perfectly and your code looks like this I probably won t even try to look at the code to see if I can figure out why it s not working perfectly. int main(void) printf( The following will show some simple math using an integer that you provide.\n\n ); printf( \n\nshowing addition and subtraction with input greater than 20:\n ); printf( \n\nshowing multiplication and division with input less than or equal to 20:\n );

Lines that exceed 80 characters are one of the most common formatting errors and point deductions on assignments for students (-5 points for having lines that exceed 80 characters). Print statements and comments are common places where students make this formatting error. The print statement below shows what it looks like when a line exceeds a certain number of characters. Because of the size of these text boxes to get the code to fit on these pages, these lines are probably not 80 characters per line, but you can see what it looks like when it does exceed a certain number of characters it wraps around to the next line. printf( The following will show some simple math and precedence rules:\n ); The code to the right shows one way to fix this: split up the print statement into 2 (or more) print statements. Another way to fix this problem is to use a backslash at the end of each line and continue your print statement on the following line(s). The remaining portion of the program is shown below, with this second solution shown to the right. NOTE: For the sake of consistency, I would not mix both of those solutions on any one single print statement. printf( The following will show some simple math using an integer that you provide.\n\n ); printf( \n\nshowing addition and subtraction with input greater than 20:\n ); printf( \n\nshowing multiplication and division with input less than or equal to 20:\n );

Opening curly brace location The code below shows the placement of the opening curly braces on the next lines. It is consistent throughout the program, so this example is perfectly fine. When it is not consistent sometimes on the same line and sometimes on the next line, sometimes indented and sometimes not indented that is when it doesn t look good. The next page shows an example where the opening and closing curly braces are all kinds of inconsistent (-5 points for code that looks like the example on the next page). int main(void) // took out some code here if( input > 20 ) else int main(void)

Curly brace location -5 points for code that has inconsistent open and closing curly brace placement. int main(void) int main(void) // took out some code here if( input > 20 )

Inconsistent indentation -5 points for code that has inconsistent indentation. int main(void) int main(void)