Creating readable code

Slides:



Advertisements
Similar presentations
Documentation 1 Comprehending the present – Investing in the future.
Advertisements

CS1061: C Programming Lecture 23: Review; Examination Details A. O’Riordan, 2005.
Program design example Task: Develop an algorithm expressed in pseudocode for a specified problem specified problem.
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 02.
Programming Style and Documentation Objective(s) F To become familiar with Java Style and Documentation Guidelines.
General Programming Introduction to Computing Science and Programming I.
INTRODUCTION TO ALGORITHMS PROGRAMMING. Objectives Give a definition of the term algorithm Describe the various parts of the pseudocode algorithm or algorithm.
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Program style. Global area Place comment s at beginning of the program: 1.purpose 2.author 3.the date the program was written 4.the data and description.
Beginning Fortran Introduction 13 October 2009 *Black text on white background provided for easy printing.
ATS Programming Short Course I INTRODUCTORY CONCEPTS Tuesday, Feb 10th, 2009 Introduction to Programming.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. 4 Simple Flow of Control.
Adapted from slides by Marty Stepp and Stuart Reges
Trace Tables In today’s lesson we will look at:
Introduction to Computing Science and Programming I
Writing algorithms Introduction to Python.
Pseudocode and comments
Pseudocode Key Revision Points.
Games Programming in Scratch
Component 1.6.
CS1022 Computer Programming & Principles
CHAPTER 4 REPETITION CONTROL STRUCTURE / LOOPING
Introducing Instructions
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
Chapter 1 Introduction to Computers, Programs, and Java
Visual Basic I Programming
7 - Programming 7P, Q, R - Testing.
The Selection Structure
CS 115 Lecture 8 Structured Programming; for loops
Programming Problem steps must be able to be fully & unambiguously described Problem types; Can be clearly described Cannot be clearly described (e.g.
Functions CIS 40 – Introduction to Programming in Python
Computer Science 101 While Statement.
Little work is accurate
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 2 Applications and Data.
Print slides for students reference
The while Looping Structure
PROGRAMMING METHODOLOGY
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
Winter 2018 CISC101 11/27/2018 CISC101 Reminders
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Chapter 1: Computer Systems
An Introduction to VEX IQ Programming with Modkit
CSc 110, Spring 2017 Lecture 4: Nested Loops and Loop Figures
The while Looping Structure
` Structured Programming & Flowchart
Programming We have seen various examples of programming languages
Learning Intention I will learn about evaluating a program.
Software Development Process
Winter 2019 CISC101 4/8/2019 CISC101 Reminders
CISC101 Reminders All assignments are now posted.
Flowcharts and Pseudo Code
Class 4: Repetition Pretest Posttest Counting Flowchart these!
Programming In Lesson 4.
Developing a Program.
EECE.2160 ECE Application Programming
Loops.
Pseudocode and comments
Do it now activity Log onto the computer.
Variables in C Topics Naming Variables Declaring Variables
Creating Maintainable code
The while Looping Structure
EECE.2160 ECE Application Programming
CMPT 120 Lecture 2 - Introduction to Computing Science – Problem Solving, Algorithm and Programming.
Arrays & Loops.
Software Development Techniques
IBC233 Lecture 3 Updated Fall 2011
Lecture 20 – Practice Exercises 4
Lecture 20 – Practice Exercises 4
Presentation transcript:

Creating readable code Learning Python Creating readable code

Code Readability Always try to make any code that you write is easy to read and understand This benefits you and anyone else who reads your code When you go back after a short time its easy to forget exactly why you wrote the code the way you did You should apply good readability principles to pseudocode and real code

Good Techniques - 1 At the beginning of the code include : Your Name Date Purpose Use descriptive names for variables eg userChoice instead of num Add blank lines between different block of code Add comments that explain what each part of the code does You can over comment Commenting each line is unnecessary and makes the code less readable

Good techniques - 2 Technique Description Comments Comments should be used to: Who wrote the code Date of writing Explain the purpose of the program Explain what each part does Explain any part where logic or setting variables is difficult to understand Descriptive Names Using descriptive identifiers for variables, constants and functions helps to make their purpose clear Use camel case for multi-word names eg firstName, totalScore Indentation Indentation makes it clear where each block of code starts and finishes. Getting this wrong can result in the program not running or producing incorrect results White space Spaces between Assignment operators and values Selection tests Blank lines between different blocks of code to make them stand out : If blocks While and For loops

Use the Python comment character # to start your comments Exercise 1 Rewrite this algorithm using appropriate techniques to make it easier to read: Set X to 10 While X >= 0 Do If X > Print (X) Else Print(“Blast Off”) End If X = X -1 End While Use the Python comment character # to start your comments

Exercise 1 - Solution # Name: your name # Date: Today’s date # Purpose: Count down from 10- 1 and display a message #initialise variables counter = 10 While counter >= 0 Do If counter > Print (counter) Else Print(“Blast Off”) End If counter = counter -1 End While