Software Testing and Maintenance Modifying Code

Slides:



Advertisements
Similar presentations
ECE 454 Computer Systems Programming Compiler and Optimization (I) Ding Yuan ECE Dept., University of Toronto
Advertisements

Unit 6 Assignment 2 Chris Boardley.
Chapter 1: Computer Systems
Documentation 1 Comprehending the present – Investing in the future.
Coding Practices. What are Coding Practices ? Coding practices are a set of informal rules that the software development community has learned over time.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Introduction to Refactoring Excerpted from ‘What is Refactoring?’ by William C. Wake and Refactoring: Improving the Design of Existing Code by Martin Fowler.
Algorithm Programming Coding Advices Bar-Ilan University תשס " ו by Moshe Fresko.
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.
Language Evaluation Criteria
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
Design-Making Projects Work (Chapter7) n Large Projects u Design often distinct from analysis or coding u Project takes weeks, months or years to create.
The Java Programming Language
Software Testing and Maintenance Modifying Code Jeff Offutt SWE 437 George Mason University 2008 Thanks to Jeff Lei, Susan Eisenbach, Jonathan Hardwick.
SE: CHAPTER 7 Writing The Program
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
Java Coding Standards and Best Practices Coding Standards Introduction: After completing this chapter, you will able to keep your code up to standards.
Advanced Computer Science Lab Coding Style & Documentation.
Code Conventions Tonga Institute of Higher Education.
Feb. 8, 2008 UHCO Graduate Course in MATLAB Core Programming Module Best Practices Core Grant Programming Module Best Practices (Coding Conventions) General.
Design - programming Cmpe 450 Fall Dynamic Analysis Software quality Design carefully from the start Simple and clean Fewer errors Finding errors.
Program Development C# Programming January 30, 2007 Professor J. Sciame.
User Interface Principles in API Design Elliotte Rusty Harold
Programming & Debugging. Key Programming Issues Modularity Modifiability Ease of Use Fail-safe programming Style Debugging.
CSCE 240 – Intro to Software Engineering Lecture 3.
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
Implementation Topics Describe –Characteristics of good implementations –Best practices to achieve them Understand role of comments Learn debugging techniques.
Principles and examples
More Sophisticated Behavior
Working with Java.
Reviewing Code A guide to smelling another developer’s source code.
Chapter 11 Object-Oriented Design
Dynamic Domain Allocation
Testing and Debugging.
About the Presentations
Understand the Programming Process
Design and Maintenance of Web Applications in J2EE
Krug Chapter 5 A: Omit Needless Words and Defaults and Memory
To Get Started Paper sheet
Coding Design, Style, Documentation and Optimization
PROGRAMMING METHODOLOGY
Testing UW CSE 160 Winter 2016.
Software Testing and Maintenance Maintenance and Evolution Overview
Chapter 1: Computer Systems
Refactoring and Code Smells
Creating your first C program
Unit 6 Assignment 2 Chris Boardley.
Units with – James tedder
Understand the Programming Process
Programming.
Algorithms and Problem Solving
Fall 2018 CISC124 2/24/2019 CISC124 Quiz 1 marking is complete. Quiz average was about 40/60 or 67%. TAs are still grading assn 1. Assn 2 due this Friday,
Focus of the Course Object-Oriented Software Development
Beginning Style 27-Feb-19.
Lecture 06:Software Maintenance
Refactoring and Code Smells
Tonga Institute of Higher Education IT 141: Information Systems
User Interface Design and Development
Tonga Institute of Higher Education IT 141: Information Systems
CS 112 Programming 2 Lecture 02 Abstract Classes & Interfaces (2)
Tonga Institute of Higher Education
Computer Science 340 Software Design & Testing
Variables in C Topics Naming Variables Declaring Variables
Creating Maintainable code
CMPE212 – Reminders Assignment 2 due next Friday.
Chapter 4: Writing and Designing a Complete Program
Creating readable code
CS 240 – Advanced Programming Concepts
Chapter 9: Implementation
Refactoring and Code Smells
Presentation transcript:

Software Testing and Maintenance Modifying Code Jeff Offutt SWE 437 George Mason University 2018

Programming for Maintainability Understanding the Program Programming for Change Coding Style 1. Understanding the Program SWE 437 - Software Testing and Maintenance © Jeff Offutt

Major Maintenance Activities We must understand an existing system before changing it How to accommodate the change ? What are the potential ripple effects ? What skills and knowledge are required ? Identify the change What to change, why to change Manage the process … what resources are needed? Understand the program How to make the change, determining the ripple effect Make the change Test the change Document and record the change SWE 437 - Software Testing and Maintenance © Jeff Offutt

Comprehension Process Read documentation Run the program Dynamic analysis Read the source code Static analysis SWE 437 - Software Testing and Maintenance © Jeff Offutt

What Influences Understanding? Expertise : Domain knowledge, programming skills Program structure : Modularity, level of nesting Documentation : Readability, accuracy, up-to-date Coding conventions : Naming style, small design patterns Comments : Accuracy, clarity, and usefulness Program presentation : Good use of indentation and spacing SWE 437 - Software Testing and Maintenance © Jeff Offutt

Programming for Maintainability Understanding the Program Programming for Change Coding Style Programming for Change SWE 437 - Software Testing and Maintenance © Jeff Offutt

Avoid Unnecessary Fancy Tricks Write for humans, not compilers Fully parenthesize expressions Pointer arithmetic is anti-engineering Clever programming techniques are for kids, not engineers In 1980, computers were slow and memory expensive Control flow dominated the running time Hence the undergraduate CS emphasis on analysis of algorithms Today: Make it easier to change the program Readable code is easier to debug, more reliable, and more secure Only optimize when you know it will help Overall architecture usually dominates running time SWE 437 - Software Testing and Maintenance © Jeff Offutt

Document Clearly Include header blocks for each method (author & version) Add a comment every time you stop to think Why a method does something is more important than what What is more important than how Document : Assumptions Variables that can be overridden by child methods Reliance on default and superclass constructors Write pseudocode as comments, then write the method Faster and more reliable Use a version control system with an edit history Explain why each change was made clearly SWE 437 - Software Testing and Maintenance © Jeff Offutt

Use White Space Effectively A 1960s study asked “how far should we indent” 2 — 4 characters is ideal Fewer is hard to see More makes programs too wide Never use tabs – they look different in every editor and printer Mixing tabs and spaces is even worse Use plenty of spaces newList(x+y)=fName+space+lName+space+title; newList (x+y) = fName + space + lName + space + title; Don’t put more than one statement per line SWE 437 - Software Testing and Maintenance © Jeff Offutt

Write Maintainable Java Be tidy Sloppy style looks like sloppy thinking Sloppy style creates maintenance debt Use clear names Long names are simpler than short names Don’t make the so long they’re hard to read Don’t test for error conditions you can’t handle Let them propagate to someone who does If you can’t develop these habits, find a non-developer job SWE 437 - Software Testing and Maintenance © Jeff Offutt

Java Specific Tips Implement both or neither equals() and hashCode() Implementing just one can cause some very subtle faults Always override toString() to produce a human-readable description of the object If equals() is called on the wrong type, return false, not an exception If your class is cloneable, use super.clone(), not new() new() will break if another programmer inherits from your class Threads are hard to get right and harder to modify Don’t add error checking the VM already does Array bounds, null pointers, etc SWE 437 - Software Testing and Maintenance © Jeff Offutt

Keep It Simple, Stupid and Long methods are not simple Good programmers write less code, not more Bad designs lead to more and longer methods Don’t generalize unless it’s necessary Ten programmers … deliver twice as much code four times as many faults, and half the functionality that … five programmers do SWE 437 - Software Testing and Maintenance © Jeff Offutt

Classes and Objects Think about what it is, not what it does The point of OO design is to look at nouns (data) first, then verbs (algorithms and methods) Think about what it is, not what it does Classes names should not be verbs Objects are defined by state–the class defines behavior Lots of switch statements may mean the class is trying to do too many things Use inheritance or type parameterization Make methods that don’t use class instance variables static Don’t confuse inheritance with aggregation Inheritance implements “is-a” Aggregation implements “has-a” SWE 437 - Software Testing and Maintenance © Jeff Offutt

Programming for Change Summary The cost of writing a program is a small fraction of the cost of fixing and maintaining it … Don’t be lazy or selfish Be an engineer ! Remember that complexity is the number one enemy of maintainability SWE 437 - Software Testing and Maintenance © Jeff Offutt

Programming for Maintainability Understanding the Program Programming for Change Coding Style Coding Style SWE 437 - Software Testing and Maintenance © Jeff Offutt

Using Style Conventions Select a set of style conventions Follow them strictly ! Follow the existing style when making changes Even if you do not like it Lots of style conventions are available It is more important to be consistent than to have perfect style Programmers need to be told to follow the team’s style SWE 437 - Software Testing and Maintenance © Jeff Offutt

What Style Guides Tell Us Case for names Variables, methods, classes, … Guidelines for choosing names Width, special characters, and splitting lines Location of statements Organization of methods and use of types Use of variables Control structures Proper spacing and white space Comments SWE 437 - Software Testing and Maintenance © Jeff Offutt

That is what engineering means ! Summary Programming habits have a major impact on readability Readability has a major impact on maintainability Maintainability determines long-term costs The minor decisions that engineers make determine how much money the company makes That is what engineering means ! SWE 437 - Software Testing and Maintenance © Jeff Offutt