Coding Practices. Why do we care? Good code is more than just functionality Other people will read your code You will forget what you code does Debugging.

Slides:



Advertisements
Similar presentations
Chapter 11 Introduction to Programming in C
Advertisements

User-Defined Functions Like short programs Can operate on their own data Can receive data from callers and return data to callers.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Chapter 29: Integration Jacob Harper. The Integration Approach The order of adding components to a system is crucial Benefits to careful integration –
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
CIT 590 Intro to Programming Lecture 2. Agenda ints, floats, strings, booleans Conditionals Loops Functions Testing The concept of scope.
Common project problems From Twin Cities CFUG meeting7/10/02.
16-Jun-15 javadoc. 2 Javadoc placement javadoc comments begin with /** and end with */ In a javadoc comment, a * at the beginning of the line is not part.
CS1061 C Programming Lecture 2: A Few Simple Programs A. O’Riordan, 2004.
The Project AH Computing. Functional Requirements  What the product must do!  Examples attractive welcome screen all options available as clickable.
Functions. Program complexity the more complicated our programs get, the more difficult they are to develop and debug. It is easier to write short algorithms.
Section 2 - More Basics. The char Data Type Data type of a single character Example char letter; letter = 'C';
Bret Juliano. Introduction What Documentation is Required? – To use a program – To believe a program – To modify a program The Flow-Chart Curse Self-Documenting.
Jun 16, 2014IAT 2651 Debugging. Dialectical Materialism  Dialectical materialism is a strand of Marxism, synthesizing Hegel's dialectics, which proposes.
Chapter 5: Control Structures II (Repetition)
CHAPTER 5: CONTROL STRUCTURES II INSTRUCTOR: MOHAMMAD MOJADDAM.
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
Chapter 3: Completing the Problem- Solving Process and Getting Started with C++ Introduction to Programming with C++ Fourth Edition.
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
Oct 15, 2007Sprenkle - CS1111 Objectives Creating your own functions.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
Chapter 5: Control Structures II (Repetition). Objectives In this chapter, you will: – Learn about repetition (looping) control structures – Learn how.
6/3/2016 CSI Chapter 02 1 Introduction of Flow of Control There are times when you need to vary the way your program executes based on given input.
Chapter 3 The Visual Basic Editor. Important Features of the VBE Alt-F11 will open the Visual Basic Editor. The Code window is to the right, Project Explorer.
COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving  Recognizing Patterns  If you can find a pattern in the way you solve.
C++ Basics L KEDIGH. Objectives 1. basic components of a c++ program using proper terminology and programming conventions adopted for this class. 2. List.
C++ Basics L KEDIGH. Objectives 1. basic components of a c++ program using proper terminology and programming conventions adopted for this class. 2. List.
End of unit assessment Challenge 1 & 2. Course summary So far in this course you have learnt about and used: Syntax Output to screen (PRINT) Variables.
Manish K Parmar PGT (CS) K V VVNagar Thursday, December 24, 2015 Lesson on USER DEFINED FUNCTION IN C++ Presented by Manish K Parmar PGT Computer Science.
Program Development Cycle 1.Edit program 2.Compile program - translates it from C to machine language 3. Run/execute your program. 4. If not satisfied,
Programming Fundamentals Enumerations and Functions.
CIT 590 Intro to Programming Lecture 2. Agenda ‘import’ Abstraction Functions Testing The concept of scope.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 5: Control Structures II (Repetition)
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Communicating in Code: Commenting Programming Studio Spring 2009 Note: several examples in this lecture taken from The Practice of Programming by Kernighan.
World of Wokcraft The very best in Single pan cooking themed fantasy gaming!
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
More Sophisticated Behavior
Chapter 6: User-Defined Functions I
The Selection Structure
User-Defined Functions
Communicating in Code: Commenting
Java for Beginners University Greenwich Computing At School DASCO
Chapter 11 Introduction to Programming in C
Escape sequences: Practice using the escape sequences on the code below to see what happens. Try this next code to help you understand the last two sequences.
Communicating in Code: Commenting
COMPUTER PROGRAMMING PYTHON
HOW TO CREATE A CLASS Steps:
Programming Fundamentals Lecture #3 Overview of Computer Programming
Global Challenge Love Heart Lesson 3.
Maintaining a Program In today’s lesson we will look at:
Global Challenge Love Heart Lesson 3.
Python 19 Mr. Husch.
Program Design Language (PDL)
Global Challenge Love Heart Lesson 3.
Global Challenge Love Heart Lesson 3.
Java for Beginners University Greenwich Computing At School DASCO
A First Program.
Global Challenge Love Heart Lesson 3.
Introduction to Computer Science
Global Challenge Love Heart Lesson 3.
Modules Programming Guides.
Global Challenge Love Heart Lesson 3.
Python 19 Mr. Husch.
Global Challenge Love Heart Lesson 3.
Global Challenge Love Heart Lesson 3.
Presentation transcript:

Coding Practices

Why do we care? Good code is more than just functionality Other people will read your code You will forget what you code does Debugging bad code is time consuming and frustrating

Basic Coding Practices Use meaningful names Don’t duplicate code Don’t reinvent the wheel Use comments effectively Test early and often Code maintenance

Names Give functions and variables meaningful names Bad names include ‘temp’, ‘integer1’, ‘l’ int l = 6; if (1 == 6) { print(“true”); } else { print(“false”); } What is the output from this piece of code?

Names Give functions and variables meaningful names Bad names include ‘temp’, ‘integer1’, ‘l’ int l = 6; if (1 == 6) { print(“true”); } else { print(“false”); } What is the output from this piece of code? Output is “false”. The variable in line 1 is a lower case L. In some fonts this is confused with the character for the number one, as found on the second line.

Names int func1(int a, int b) { if (a < 24 && b < 60) return 1; else return 0; } Bad names make code hard to read and understand What does this code do?

Names int func1(int a, int b) { if (a < 24 && b < 60) return 1; else return 0; } Bad names make code hard to read and understand int validateTime(int hours, int minutes) { if (hours < 24 && minutes < 60) return 1; else return 0; } What does this code do? How about this code?

Code Duplication Duplicated code adds confusion Duplicated code leads to more bugs Replace duplicated code with functions

Reinventing the Wheel The “I can do it better trap” Read and understand support code, especially so called “helper” functions Explore the standard libraries e.g.

Comments Comments help the reader understand the code Bad comments include: –repeating what the code does –lengthy explanations of badly written code

Comments Good comments include: –summarizing blocks of code –describing the programmers intent –identifying logical divisions in the code –identifying unconventional methods

Testing Test early and often – don’t write everything and the start testing Identify separate components that can be tested individually – Code in Blocks If necessary write your own test cases, but start small Test user inputs (and function inputs)

Code Maintenance Periodically backup your work Every time you get a particular feature to work, save a copy of your files More advanced source control – RCS or CVS