Code Documentation. Important!  It’s for you  It’s for others.

Slides:



Advertisements
Similar presentations
C Functions. What are they? In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive.
Advertisements

Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
Functions ROBERT REAVES. Functions  Interface – the formal description of what a subprogram does and how we communicate with it  Encapsulation – Hiding.
Overview Reference parameters Documenting functions A game of craps. Design, code, test and document.
Static Methods Chapter 4. Chapter Contents Objectives 4.1 Introductory Example: Old MacDonald Had a Farm … 4.2 Getting Started with Methods 4.3 Example:
1 Design by Contract Building Reliable Software. 2 Software Correctness Correctness is a relative notion  A program is correct with respect to its specification.
Object Oriented Design An object combines data and operations on that data (object is an instance of class) data: class variables operations: methods Three.
Copyright W. Howden1 Lecture 13: Programming by Contract.
 An important topic: preconditions and postconditions.  They are a method of specifying what a function accomplishes. Preconditions and Postconditions.
Program Commenting CS-212 Dick Steflik. Commentary Commentary are pieces of information included in a program’s source files to provide additional information.
Functions A function is a snippet of code that performs a specific task or tasks. You use a multitude of functions daily when you do such things as store.
Functions in C. Function Terminology Identifier scope Function declaration, definition, and use Parameters and arguments Parameter order, number, and.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
Modular Programming Chapter Value and Reference Parameters t Function declaration: void computesumave(float num1, float num2, float& sum, float&
Lecture 9m: Top-Down Design with Functions COS120 Software Development Using C++ AUBG, COS dept.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
CS Fall 2007 Dr. Barbara Boucher Owens. CS 2 Text –Main, Michael. Data Structures & Other Objects in Java Third Edition Objectives –Master building.
Contract based programming Using pre- and post-conditions, and object invariants Contract based programming1.
Chapter 5 Functions For All Subtasks. Void functions Do not return a value. Keyword void is used as the return type in the function prototype to show.
CS 261 – Data Structures Preconditions, Postconditions & Assert.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
1 Functions Chapter 7 2 Hope you can function! What is R2D2 doing here? What is his function? Who is Nibble? Can he function? IS he a function? Who is.
3-1 Computing Fundamentals with C++ Object-Oriented Programming and Design, 2nd Edition Rick Mercer Franklin, Beedle & Associates, 1999 ISBN
P An important topic: preconditions and postconditions. p They are a method of specifying what a function accomplishes. Preconditions and Postconditions.
Chapter 4: Subprograms Functions for Problem Solving Mr. Dave Clausen La Cañada High School.
Static Methods. 2 Objectives Look at how to build static (class) methods Study use of methods calling, parameters, returning values Contrast reference.
P An important topic: preconditions and postconditions. p They are a method of specifying what a function accomplishes. Illinois State University Department.
Writing JavaScript Functions. Goals By the end of this unit, you should understand … How to breakdown applications into individual, re-usable modules.
 An important topic: preconditions and postconditions.  They are a method of specifying what a method accomplishes. Preconditions and Postconditions.
Pre- and postconditions, Using assertions and exceptions 1 Pre- and postconditions Using assertions and exceptions.
Functions Overview Functions are sequence of statements with its own local variables supports modularity, reduces code duplication Data transfer between.
CSE202: Lecture 11The Ohio State University1 Functions.
Test Driven Development Ben Hoskins. Test Driven Development.
Protocols Software Engineering II Wirfs Brock et al, Designing Object-Oriented Software, Prentice Hall, Mitchell, R., and McKim, Design by Contract,
(3-1) Functions II H&K Chapter 3 Instructor - Andrew S. O’Fallon CptS 121 (September 9, 2015) Washington State University.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Repetition Structures.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 6 Functions.
Functions Chapter 6. Modular Programming Modular programming: breaking a program up into smaller, manageable functions or modules Function: a collection.
Chapter 3 : Top Down Design with Functions By Suraya Alias.
Defensive Programming CNS 3370 Copyright 2003, Fresh Sources, Inc.
A First Book of ANSI C Fourth Edition Chapter 6 Modularity Using Functions: Part I.
Chapter 2 Comments, Conditions, Assertions Comments Preconditions Postconditions Assertions.
1 Introduction 1. Why Data Structures? 2. What AreData Structure? 3. Phases of Software Development 4. Precondition and Postcondition 5. Examples.
“Discipline is the refining fire by which talent becomes ability.” – Roy L. Smith Thought for the Day.
1 Scope Lifetime Functions (the Sequel) Chapter 8.
Variables  A piece of memory set aside to store data  When declared, the memory is given a name  by using the name, we can access the data that sits.
Chapter 1 The Phases of Software Development. Software Development Phases ● Specification of the task ● Design of a solution ● Implementation of solution.
Functions in C++ Top Down Design with Functions. Top-down Design Big picture first broken down into smaller pieces.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Functions Procedural Abstraction Flow of Control INFSY 307 Spring 2003 Lecture 4.
Testing It is much better to have a plan when testing your programs than it is to just randomly try values in a haphazard fashion. Testing Strategies:
Chapter Topics The Basics of a C++ Program Data Types
Chapter 5 Functions for All Subtasks 1
CSE 220 – C Programming C Fundamentals.
Basic Elements of C++.
Specifications What? Not how!.
Topics Introduction to Repetition Structures
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
Basic Elements of C++ Chapter 2.
Function Basics.
Additional Control Structures
A First Book of ANSI C Fourth Edition
Announcements Homework 1 will be assigned this week,
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Topics Introduction to Repetition Structures
Assertions References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 4/25/2019.
Functions Taken from notes by Dr. Neil Moore & Dr. Debby Keen
Unit Testing.
Presentation transcript:

Code Documentation

Important!  It’s for you  It’s for others

The Function Description  Describes what the function does for the user  What resources are needed  It should not need to state how this is done, just what is done

Function Side Effects  A side effect is anything that is a direct consequent of the execution of a function that is not a direct mapping of inputs to outputs (return values)

Pre and Post Conditions  Preconditions  Preconditions state what must be true of the inputs to the function before a function is executed in order to guarantee the postconditions.  Postconditions  Postconditions state what will be true after successful execution of a function including all side effects given that the preconditions are met.

Pre and Post Notes 1.You may think of pre- and postconditions as setting up a contract between you (the programmer) and the user of your function. 2.It is perfectly acceptable that there can be no preconditions on a function.

Pre and Post Notes 3.Preconditions should never contain obvious, irrelevant, or redundant statements. 4.Most often you will find that preconditions will be a statement of the range of values a parameter may take on

Pre and Post Notes 5.When stating postconditions, be sure to include all pertinent information. Beware of reference parameters and other side effects. 6.Don’t state what is not a result of the function being executed.

Pre and Post Notes 7.I CANNOT imagine “none” being a valid postcondition. If the function had no postcondition, then it’s pretty useless. 8.All these comments should be placed just before the prototype of the function in question.

Examples // Description: The greetings() function will output a message to the // screen greeting the user. // Pre: None // Post: Message output to the screen. void greetings (); // The cyl_vol() function will calculate and return the volume of the // right circular cylinder with base radius rad and height ht. // Pre: Both parameters, rad and ht, must be positive values. // Post: Volume of cylinder is returned. float cyl_vol (const float rad, const float ht); // The swap() function will swap the values of the arguments sent to // it. // Pre: none // Post: The values of the arguments sent will be swapped back in the // calling function. void swap (float & val1, float & val2);

Examples // Description: The greetings() function will output a message to the // screen greeting the user. // Pre: None // Post: Message output to the screen. void greetings (); // The cyl_vol() function will calculate and return the volume of the // right circular cylinder with base radius rad and height ht. // Pre: Both parameters, rad and ht, must be positive values. // Post: Volume of cylinder is returned. float cyl_vol (const float rad, const float ht); // The swap() function will swap the values of the arguments sent to // it. // Pre: none // Post: The values of the arguments sent will be swapped back in the // calling function. void swap (float & val1, float & val2);

Examples // Description: The greetings() function will output a message to the // screen greeting the user. // Pre: None // Post: Message output to the screen. void greetings (); // The cyl_vol() function will calculate and return the volume of the // right circular cylinder with base radius rad and height ht. // Pre: Both parameters, rad and ht, must be positive values. // Post: Volume of cylinder is returned. float cyl_vol (const float rad, const float ht); // The swap() function will swap the values of the arguments sent to // it. // Pre: none // Post: The values of the arguments sent will be swapped back in the // calling function. void swap (float & val1, float & val2);

Examples // Description: The greetings() function will output a message to the // screen greeting the user. // Pre: None // Post: Message output to the screen. void greetings (); // The cyl_vol() function will calculate and return the volume of the // right circular cylinder with base radius rad and height ht. // Pre: Both parameters, rad and ht, must be positive values. // Post: Volume of cylinder is returned. float cyl_vol (const float rad, const float ht); // The swap() function will swap the values of the arguments sent to // it. // Pre: none // Post: The values of the arguments sent will be swapped back in the // calling function. void swap (float & val1, float & val2);

End of Session