High Quality Code – Style Matters  Chapter 5. Design in Construction  Chapter 31. Layout and Style Software Construction by Jeff Nogy.

Slides:



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

Software Engineering Key construction decisions Design challenges.
Software Engineering Key design concepts Design heuristics Design practices.
Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
By Justin Hendrix. Design Challenges Design is the activity that links requirements to coding and debugging. Good design is useful on small project and.
High Quality Code Why it matters. By Ryan Ruzich.
Software Engineering and Design Principles Chapter 1.
Programming Language Paradigms: summary. Object-oriented programming Objects are the fundamental building blocks of a program. Interaction is structured.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
Fall 2007CS 2251 Software Engineering Intro. Fall 2007CS 2252 Topics Software challenge Life-cycle models Design Issues Documentation Abstraction.
CS 201 Functions Debzani Deb.
Chapter 1 Principles of Programming and Software Engineering.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 7: Methods.
The Software Design Process CPSC 315 – Programming Studio Fall 2009.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
1 Working with Classes Chapter 6. 2 Class definition A class is a collection of data and routines that share a well-defined responsibility or provide.
Introduction - The Need for Data Structures Data structures organize data –This gives more efficient programs. More powerful computers encourage more complex.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
13 Jul 2006CSE403, Summer'06, Lecture10 Lifecycle Architecture Review: Preliminary Feedback Valentin Razmov.
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
Programming Language Concepts
Chapter 5CSA 217 Design in Construction Chapter 5 1.
1/19 Component Design On-demand Learning Series Software Engineering of Web Application - Principles of Good Component Design Hunan University, Software.
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.
University of Toronto Department of Computer Science CSC444 Lec05- 1 Lecture 5: Decomposition and Abstraction Decomposition When to decompose Identifying.
More with Methods (parameters, reference vs. value, array processing) Corresponds with Chapters 5 and 6.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
1 Chapter 5 Software Engineering Practice. 2 What is “Practice”? Practice is a broad array of concepts, principles, methods, and tools that you must consider.
Chapter 13 Recursion. Learning Objectives Recursive void Functions – Tracing recursive calls – Infinite recursion, overflows Recursive Functions that.
THE SOFTWARE DESIGN PROCESS CSCE 315 – Programming Studio Spring 2010.
1 Systems Analysis and Design in a Changing World, Thursday, January 18, 2007.
The Way to Produce Good, Clean Code That Will Blow Your Boss Away!
CSE 403, Spring 2008, Alverson Software Design “There are two ways of constructing a software design: one way is to make it so simple that there are obviously.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
1 FUNCTIONS - I Chapter 5 Functions help us write more complex programs.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Introduction to Software Architecture.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
KIC/Computer Programming & Problem Solving 1.  Introduction  Program Modules in C  Math Library Functions  Functions  Function Definitions  Function.
Chapter 8 Lecture 1 Software Testing. Program testing Testing is intended to show that a program does what it is intended to do and to discover program.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
5.3 Sorting Techniques. Sorting Techniques Sorting is the process of putting the data in alphabetical or numerical order using a key field primary key.
High Quality Code – Style Matters  Design in Construction  Layout and Style Software Construction by Jeff Nogy.
Lecture 7 February 24, Javadoc version and author Tags These go in the comments before named classes. –Put your SS# on a separate line from the.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
Introducing Java Chapter 3 Review. Why Program in Java? Java, is an object-oriented programming language. OOP languages evolved out of the need to better.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Chapter 2 Principles of Programming and Software Engineering.
07 Jul 2006CSE403, Summer'06, Lecture10 Lecture 10: Core Principles and Best Practices for Software Design (Part I) “Treat design as a wicked, sloppy,
Layout and Style Chapter 31. Outline  Laying Out Control Structures  Laying Out Individual Statements  Laying Out Comments  Laying Out Routines 
MAITRAYEE MUKERJI Object Oriented Programming in C++
1 Sections 7.2 – 7.7 Nested Control Statements Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
A Method for Improving Code Reuse System Prasanthi.S.
Principles of Programming & Software Engineering
Design in Construction
CompSci 280 S Introduction to Software Development
Data Abstraction: The Walls
Chapter 3: Using Methods, Classes, and Objects
Deitel- C:How to Program (5ed)
Chapter 5 Design in Construction
Chapter 5 - Functions Outline 5.1 Introduction
Questions First On class? On project? On material we’ve discussed?
Producing Production Quality Software
Feedback open / closed questiond
Extending Interface Based Design
Presentation transcript:

High Quality Code – Style Matters  Chapter 5. Design in Construction  Chapter 31. Layout and Style Software Construction by Jeff Nogy

Chapter 5. Design in Construction  Introduction  5.1. Design Challenges  5.2. Key Design Concepts  5.3. Design Building Blocks: Heuristics  5.4. Design Practices  5.5. Comments on Popular Methodologies

Introduction - Code Complete

5. Introduction  Process of building  The hands-on part  Coding or Programming  Construction = Programming

5.1. Design Challenges  Design Is a Wicked Problem Wicked problem Solve the problem once, then solve it again Tacoma Narrows Bridge  Design Is a Sloppy Process (Even If it Produces a Tidy Result) False steps and go down many blind alleys Good Enough?

5.1. Design Challenges  Design Is About Tradeoffs and Priorities Ideal world vs. Real world  Design Involves Restrictions Create possibilities and Restrict possibilities

5.1. Design Challenges  Design Is Nondeterministic More than one way to skin a cat  Design Is a Heuristic Process Trial and Error  Design Is Emergent Evolve and Improve

5.2. Key Design Concepts  Software's Primary Technical Imperative: Managing Complexity Essential and Accidental Difficulties Importance of Managing Complexity How to Attack Complexity

5.2. Key Design Concepts  Desirable Characteristics of a Design  Levels of Design Level 1: Software System Level 2: Division into Subsystems or Packages Level 3: Division into Classes Level 4: Division into Routines Level 5: Internal Routine Design

5.3. Design Building Blocks: Heuristics  Find Real-World Objects  Form Consistent Abstractions  Encapsulate Implementation Details  Inherit—When Inheritance Simplifies the Design

5.3. Design Building Blocks: Heuristics  Hide Secrets (Information Hiding) Secrets and the Right to Privacy Value of Information Hiding  Identify Areas Likely to Change  Keep Coupling Loose Coupling Criteria Kinds of Coupling

5.3. Design Building Blocks: Heuristics  Look for Common Design Patterns Patterns provide several benefits  Other Heuristics Things to aim for  Guidelines for Using Heuristics

5.4. Design Practices  Iterate  Divide and Conquer  Top-Down and Bottom-Up Design Approaches  Experimental Prototyping

5.4. Design Practices  Collaborative Design  How Much Design Is Enough?  Capturing Your Design Work

5.5. Comments on Popular Methodologies  “Treat design as a wicked, sloppy, heuristic process. Don't settle for the first design that occurs to you. Collaborate. Strive for simplicity. Prototype when you need to. Iterate, iterate, and iterate again. You'll be happy with your designs.”

Chapter 31. Layout and Style  Introduction  Layout Fundamentals  Layout Techniques  Layout Styles  Laying Out Control Structures  Laying Out Individual Statements  Laying Out Comments  Laying Out Routines  Laying Out Classes

Introduction  Layout of program source code  Execution speed, memory use  Understand the code  Others to read

31.1. Layout Fundamentals  Layout Extremes: Listing 31-1 /* Use the insertion sort technique to sort the "data" array in ascending order. This routine assumes that data[ firstElement ] is not the first element in data and that data[ firstElement-1 ] can be accessed. */ public void InsertionSort( int[] data, int firstElement, int lastElement ) { /* Replace element at lower boundary with an element guaranteed to be first in a sorted list. */ int lowerBoundary = data[ firstElement-1 ]; data[ firstElement-1 ] = SORT_MIN; /* The elements in positions firstElement through sortBoundary-1 are always sorted. In each pass through the loop, sortBoundary is increased, and the element at the position of the new sortBoundary probably isn't in its sorted place in the array, so it's inserted into the proper place somewhere between firstElement and sortBoundary. */ for (int sortBoundary = firstElement+1; sortBoundary <= lastElement; sortBoundary++ ) { int insertVal = data[ sortBoundary ]; int insertPos = sortBoundary; while (insertVal < data[ insertPos-1 ] ) { data[ insertPos ] = data[ insertPos-1 ]; insertPos = insertPos-1; } data[ insertPos ] = insertVal; } /* Replace original lower-boundary element */ data[ firstElement-1 ] = lowerBoundary; }

31.1. Layout Fundamentals  Layout Extremes: Listing 31-3 /* Use the insertion sort technique to sort the "data" array in ascending order. This routine assumes that data[ firstElement ] is not the first element in data and that data[ firstElement-1 ] can be accessed. */ public void InsertionSort( int[] data, int firstElement, int lastElement ) { // Replace element at lower boundary with an element guaranteed to be // first in a sorted list. int lowerBoundary = data[ firstElement-1 ]; data[ firstElement-1 ] = SORT_MIN; /* The elements in positions firstElement through sortBoundary-1 are always sorted. In each pass through the loop, sortBoundary is increased, and the element at the position of the new sortBoundary probably isn't in its sorted place in the array, so it's inserted into the proper place somewhere between firstElement and sortBoundary. */ for ( int sortBoundary = firstElement + 1; sortBoundary <= lastElement; sortBoundary++ ) { int insertVal = data[ sortBoundary ]; int insertPos = sortBoundary; while ( insertVal < data[ insertPos - 1 ] ) { data[ insertPos ] = data[ insertPos - 1 ]; insertPos = insertPos - 1; } data[ insertPos ] = insertVal; } // Replace original lower-boundary element data[ firstElement - 1 ] = lowerBoundary; }

31.1. Layout Fundamentals  The Fundamental Theorem of Formatting  Human and Computer Interpretations of a Program x = 3+4 * 2+7;  How Much Is Good Layout Worth? “Exploratory Experiments in Programmer Behavior” by Ben Shneiderman (1976).

31.1. Layout Fundamentals  Layout as Religion  Objectives of Good Layout How to Put the Layout Objectives to Use

31.2. Layout Techniques  White Space  Usewhitespacetoenhancereadability Grouping Blank lines Indentation  Parentheses

31.3. Layout Styles  Pure Blocks  Emulating Pure Blocks  Using begin-end Pairs (Braces) to Designate Block Boundaries

31.3. Layout Styles  Endline Layout  Which Style Is Best? While ( pixelColor = Color_Red ) statement1; statement2;... Wend

31.4. Laying Out Control Structures  Fine Points of Formatting Control- Structure Blocks  Other Considerations

31.5. Laying Out Individual Statements  Statement Length  Using Spaces for Clarity  Formatting Continuation Lines  Using Only One Statement Per Line  Laying Out Data Declarations

31.6. Laying Out Comments  Indent a comment with its corresponding code  Set off each comment with at least one blank line For transactionId = 1 To totalTransactions ' get transaction data GetTransactionType( transactionType ) GetTransactionAmount( transactionAmount ) ' process transaction based on transaction type If transactionType = Transaction_Sale Then AcceptCustomerSale( transactionAmount ) // comment zero CodeStatementZero; CodeStatementOne; // comment one CodeStatementTwo; CodeStatementThree;

31.7. Laying Out Routines  Use blank lines to separate parts of a routine  Use standard indentation for routine arguments public bool ReadEmployeeData( int maxEmployees, EmployeeList *employees, EmployeeFile *inputFile, int *employeeCount, bool *isInputError )... public void InsertionSort( SortArray data, int firstElement, int lastElement )

31.8. Laying Out Classes  Laying Out Class Interfaces  Laying Out Class Implementations  Laying Out Files and Programs

Conclusion  Software complexity  Simplicity is achieved in two general ways  Design is heuristic  Good design is iterative  Information hiding  The first priority of visual layout  Looking good is secondary  Pure blocks and Pure-block emulation  Structuring code is important  Religious issues