High-Quality Routines

Slides:



Advertisements
Similar presentations
User-Defined Functions Like short programs Can operate on their own data Can receive data from callers and return data to callers.
Advertisements

Revealing the Secrets of Self-Documenting Code Svetlin Nakov Telerik Corporation For C# Developers.
Spring Semester 2013 Lecture 5
Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
Chapter 3: Modularization
Chapter 2: Modularization
Software Engineering Routine design. High quality routines Routine: individual method or procedure invocable for a single purpose.
Programming Logic and Design Fourth Edition, Introductory
Chapter 10 THINKING IN OBJECTS 1 Object Oriented programming Instructor: Dr. Essam H. Houssein.
Detailed Design Kenneth M. Anderson Lecture 21
Reasons to study concepts of PL
CS 201 Functions Debzani Deb.
Chapter 4 Sec. 4.1, 4.2, 4.4 Procedures (User-defined)
Algorithm Programming Coding Advices Bar-Ilan University תשס " ו by Moshe Fresko.
Computer Science 240 Principles of Software Design.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
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.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Java: Chapter 1 Computer Systems Computer Programming II.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
OOD Case Study (For parallel treatment, see Chapter 2 of the text)
Modular Programming. Modular Programming (1/6) Modular programming  Goes hand-in-hand with stepwise refinement and incremental development  Makes the.
Computer Science 240 © Ken Rodham 2006 Principles of Software Design.
Software Life Cycle Requirements and problem analysis. –What exactly is this system supposed to do? Design –How will the system solve the problem? Coding.
Chapter 7: High Quality Routines By Raj Ramsaroop.
Software Implementation (Writing Quality Code). void HandleStuff( CORP_DATA & inputRec, int crntQtr, EMP_DATA empRec, float & estimRevenue, float ytdRevenue,
SE: CHAPTER 7 Writing The Program
Triggers and Stored Procedures in DB 1. Objectives Learn what triggers and stored procedures are Learn the benefits of using them Learn how DB2 implements.
Address book By NIRMIT GANG. Main Program  Selection Screen 1.Enter Data 2. Read Data 3. Search Data 4. Modify Data 5. Delete Data 6. Exit Choice.
Cohesion and Coupling CS 4311
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
Career Your Library Resume Writing & Computer Skills.
CS242.  Reduce Complexity  Introduce an intermediate, understandable abstraction  Avoid code duplication  Support subclassing  Hide sequences  Hide.
Documentation Dr. Andrew Wallace PhD BEng(hons) EurIng
REFACTORINGREFACTORING. Realities Code evolves substantially during development Requirements changes 1%-4% per month on a project Current methodologies.
Jump to first page (C) 1998, Arun Lakhotia 1 Design Quality Metrics Arun Lakhotia University of Southwestern Louisiana Po Box Lafayette, LA 70504,
How to Test Methods Computer Science 3 Gerb Objective: Test methods properly.
High-Quality Routines Chapter 5-6. Review Class Quality Checklist 2.
Controlling Program Flow with Decision Structures.
R EPORT WRITING Purpose Help the reader understand a situation and make a decision on any action that may be necessary to improve matters 1.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
1 Functions Part 1 Prototypes Arguments Overloading Return values.
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Principles of Programming & Software Engineering
Coupling and Cohesion Rajni Bhalla.
More Sophisticated Behavior
High-Quality Routines
Coupling and Cohesion 1.
Chapter One Unser Interface.
Data Abstraction: The Walls
Principles of Programming and Software Engineering
Lecture 2 of Computer Science II
Functions Inputs Output
Improving the Design “Can the design be better?”
G063 - Testing.
Chapter 09 – Part I Creating High-Quality Code
Programming Logic and Design Fourth Edition, Comprehensive
Herbert G. Mayer, PSU CS Status 8/2/2013
Lecture 12: Message passing The Environment Model
C Programming Program Quality
Running a Java Program using Blue Jay.
Cohesion and Coupling.
Lecture 7: RPC (exercises/questions)
Chapter (3) - Procedures
Controlling Program Flow
Programming Issues Code Complete (Roger S. Pressman)
CS 240 – Advanced Programming Concepts
Preprocessor Directives and Macros Chapter 21
Programming Techniques
Presentation transcript:

High-Quality Routines Chapter 7

What is a “routine?” A routine is an individual method or procedure achieves a single purpose. Examples include a function in C++, a method in Java, a function or sub procedure in Visual Basic. The routine makes programs easier to read and easier to understand. It is also used for saving space and improving performance

Valid Reasons to Create a Routine Reduce complexity Make a section of code readable Avoid duplicate code Hide pointer operations Improve portability Improve performance

Cohesion have each routine do one thing well and not do anything else. (High Cohesion) Examples of highly cohesive routines include sin(), GetCustomerName(), EraseFile(), CalculateLoanPayment(), and AgeFromBirthday(). Example of low cohesive routine is TanAndCosine() One study of 450 routines found that 50 percent of the highly cohesive routines were fault free. To increase cohesion, split the operations into individual routines.

Good Routine Names .. Guidlines Describe everything the routine does Avoid meaningless or wishy-washy verbs: Routine names like HandleCalculation(), PerformServices(), ProcessInput(), and DealWithOutput() don’t tell you what the routines do. HandleOutput() could be replaced with FormatAndPrintOutput() Make names of routines as long as necessary To name a function, use a description of the return value If a function returns a value, the function should be named for the value it returns. For example, cos(), customerId.Next(), printer.IsReady(), and pen.CurrentColor() are all good function names that indicate precisely what the functions return

Good Routine Names .. Guidlines Use opposites precisely Examples add/remove begin/end create/destroy first/last get/put get/set increment/decrement insert/delete lock/unlock min/max next/previous

How Long Can a Routine Be? IBM once limited routines to 50 lines TRW limited them to two pages In worst case, number of lines in one routine should not exceed 200 lines

How to Use Routine Parameters Interfaces between routines are some of the most error-prone areas of a program. Put parameters in input-modify-output order If several routines use similar parameters, put the similar parameters in a consistent order Use all the parameters