Chapter 7: High Quality Routines By Raj Ramsaroop.

Slides:



Advertisements
Similar presentations
Revealing the Secrets of Self-Documenting Code Svetlin Nakov Telerik Corporation For C# Developers.
Advertisements

Structured Design. 2 Design Quality – Simplicity “There are two ways of constructing a software design: One is to make it so simple that there are obviously.
Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
Chapter 3: Modularization
Communication between modules, cohesion and coupling
Software Engineering Routine design. High quality routines Routine: individual method or procedure invocable for a single purpose.
Programming Logic and Design Fourth Edition, Introductory
Software Engineering and Design Principles Chapter 1.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 4.0.
Objects First With Java A Practical Introduction Using BlueJ Designing object-oriented programs How to write code in a way that is easily understandable,
Slide 1 CS3 Fall 2005 Lecture week 13: Introduction to the Big Project.
Module: Definition ● A logical collection of related program entities ● Not necessarily a physical concept, e.g., file, function, class, package ● Often.
1 SOFTWARE DESIGN QUALITY COHESION and COUPLING (Part I)
Reasons to study concepts of PL
1 Introduction to Computers and Programming Quick Review What is a Function? A module of code that performs a specific job.
CS 201 Functions Debzani Deb.
Modules, Hierarchy Charts, and Documentation
1.9 Methods academy.zariba.com 1. Lecture Content 1.What is a method? Why use methods? 2.Void Methods and methods with parameters 3.Methods which return.
Unusual Control Structures and General Control Issues A Presentation by CJ Castellani as told in an American accent.
How do you simplify? Simple Complicated.
General Issues in Using Variables
Chapter 7 Designing Classes. Class Design When we are developing a piece of software, we want to design the software We don’t want to just sit down and.
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Coupling and Cohesion Pfleeger, S., Software Engineering Theory and Practice. Prentice Hall, 2001.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
CS 350 – Software Design The Object Paradigm – Chapter 1 If you were tasked to write code to access a description of shapes that were stored in a database.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
SWE © Solomon Seifu ELABORATION. SWE © Solomon Seifu Lesson 12-3 Cohesion.
Chapter 8: Writing Graphical User Interfaces Visual Basic.NET Programming: From Problem Analysis to Program Design.
Program Design Simple Program Design Third Edition A Step-by-Step Approach 9.
SOFTWARE DESIGN (SWD) Instructor: Dr. Hany H. Ammar
Quality Code academy.zariba.com 1. Lecture Content 1.Software Quality 2.Code Formatting 3.Correct Naming 4.Documentation and Comments 5.Variables, Expressions.
SOFTWARE DESIGN Design Concepts Design is a meaningful engineering representation of something that is to be built It can be traced to a customer’s requirements.
1 Software Design Overview Reference: Software Engineering, by Ian Sommerville, Ch. 12 & 13.
Computers and Scientific Thinking David Reed, Creighton University Functions and Libraries 1.
Cohesion and Coupling CS 4311
Functions, Procedures, and Abstraction Dr. José M. Reyes Álamo.
Coupling & Cohesion CMSC 201- Fall '11. Vocabulary Routine- A programming unit that performs a task, such as a function, procedure, method, or main class.
Coupling Cohesion Chandan R. Rupakheti Steve Chenoweth (Chapter 18)
Chapter 10 Software Engineering. Understand the software life cycle. Describe the development process models. Understand the concept of modularity in.
Code Development Code development for end user systems.
CS242.  Reduce Complexity  Introduce an intermediate, understandable abstraction  Avoid code duplication  Support subclassing  Hide sequences  Hide.
1 FUNCTIONS - I Chapter 5 Functions help us write more complex programs.
Designing Classes. Software changes Software is not like a novel that is written once and then remains unchanged. Software is extended, corrected, maintained,
Lecture 13 Law of Demeter. Cohesion Cohesion: the “glue” that holds a module together. Don’t do things that do not support a common goal Cohesion: the.
Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls.
Jump to first page (C) 1998, Arun Lakhotia 1 Design Quality Metrics Arun Lakhotia University of Southwestern Louisiana Po Box Lafayette, LA 70504,
Design and Planning Or: What’s the next thing we should do for our project?
High-Quality Routines Chapter 5-6. Review Class Quality Checklist 2.
Objects First With Java A Practical Introduction Using BlueJ Designing classes How to write classes in a way that they are easily understandable, maintainable.
Controlling Program Flow with Decision Structures.
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
1 Functions Part 1 Prototypes Arguments Overloading Return values.
Coupling and Cohesion Schach, S, R. Object-Oriented and Classical Software Engineering. McGraw-Hill, 2002.
Coupling and Cohesion Pfleeger, S., Software Engineering Theory and Practice. Prentice Hall, 2001.
Further Modularization, Cohesion, and Coupling. Simple Program Design, Fourth Edition Chapter 9 2 Objectives In this chapter you will be able to: Further.
Coupling and Cohesion Rajni Bhalla.
Coupling and Cohesion 1.
Chapter 8: Writing Graphical User Interfaces
Cohesion and Coupling Chapter 5, Pfleeger 01/01/10.
High-Quality Routines
Functions, Procedures, and Abstraction
Improving the Design “Can the design be better?”
Coding Concepts (Basics)
Chapter 09 – Part I Creating High-Quality Code
Programming Logic and Design Fourth Edition, Comprehensive
Software Design Lecture : 9.
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Programming Issues Code Complete (Roger S. Pressman)
Presentation transcript:

Chapter 7: High Quality Routines By Raj Ramsaroop

 A routine is a:  Function (C++).  Method (Java).  Procedure (Visual Basic).  Macro.  A routine should have a single purpose. What Is A Good Routine?

Example: A Bad Routine

 Name: HandleStuff().  Too many parameters.  No logical ordering to parameters.  Looks like it’s trying to do more than one task.  Not logically laid out.  Input variable is changed.  Unused parameters. Why Was That A Bad Routine?

 Biggest reason: reduce complexity.  Minimize code, avoid duplicate code.  Make your code more maintainable.  Easier to read. Why/When Create A Routine?

 Avoid duplicate code.  Only need to check one place.  Avoid writing the same thing twice.  Similar code in different routines – split them up.  Hide sequences.  Keeps code simple.  E.g. if you get data from a user and data from a file, neither routine should depend on each other. Why/When Create A Routine? Cont.

 Improve portability.  Make your code independent of hardware/software, or the project you are working on.  Can be reused – enforces object-oriented concepts.  Simplify complicated boolean tests.  E.g. isVisible()  Details of the test are out of the way.  The name is descriptive.  Emphasizes it’s significance. Why/When Create A Routine? Cont.

 Depends:  If you keep repeating the same line.  One line of code can balloon into something bigger.  Makes code more readable. Can Code Sometimes Be Too Small For A Routine?

 Cohesion refers to how closely the operations in the routine are related.  Ensures routines perform one task well – and nothing else.  Acceptable types of cohesion:  Functional cohesion – the best type, is when a routine performs only one function.  Sequential cohesion.  Communicational cohesion.  Temporal cohesion. Routine Cohesion

 Procedural cohesion – operations that are in a specific order and are combined for that specific reason.  Logical cohesion – basically methods with big ‘if statements’  Operations are not usually logically related.  Only time this would be acceptable would be something like an event handler.  Coincidental cohesion – if you have this it probably means you need to redesign your program! Unacceptable Types Of Cohesion

 Name can be as long as it needs to be – as long as it doesn’t sound silly!  Make it descriptive.  Avoiding meaningless verbs (e.g. processOutput(), calculateData()).  Don’t differentiate functions solely by a number!  Use what the function returns to name the function. E.g. customerId.next(), printer.isReady()  To name a procedure, use a strong verb followed by an object. E.g. printReport(), calculateInvoice()  Use opposites such as get/set, open/close, first/last etc Naming Routines

 A line is a noncomment, nonblank line of code.  Book suggests up to 200 lines.  They can be as long as they need to be as long as you focus on cohesion. How Long Should A Routine Be?

 Put parameters in “input-modify-output” order.  As opposed to randomly or alphabetically.  Implies a sequence of operations.  If several routines take similar parameters, put them in the same order.  Use all parameters.  Status and error variables go last.  Don’t use routine parameters as working variables.  Document the input variables (range, units, values that should never appear etc).  Limit number of parameters to 7.  Check parameter types (mismatched types etc). Using Routine Parameters

 A function is a routine that returns something.  A procedure is a routine that does something, but does not return anything.  You can combine the two.  Return values should return an object, not a reference or pointer to local data. When To Use A Function Or Procedure And Return Values