SlideShare a Scribd company logo
4.5 Developing complex programs
To develop and use more complex procedures it will be useful to learn some
helpful techniques for understanding what is going on when procedures are evaluated.
It is very rare for a first version of a program to be completely correct, even for an expert
programmer.
Wise programmers build programs incrementally, by writing and testing
small components one at a time.
The process of fixing broken programs is known as debugging.
The key to debugging effectively is to be systematic and thoughtful. It is a good idea to
take notes to keep track of what you have learned and what you have tried.
Thoughtless debugging can be very frustrating, and is unlikely to lead to a
correct program.
A good strategy for debugging is to:
1. Ensure you understand the intended behavior of your procedure. Think of
a few representative inputs, and what the expected output should be.
2. Do experiments to observe the actual behavior of your procedure. Try your
program on simple inputs first. What is the relationship between the actual outputs and
the desired outputs? Does it work correctly for some inputs but not others?
3. Make changes to your procedure and retest it. If you are not sure what to
do, make changes in small steps and carefully observe the impact of each change.
First actual bug. Grace Hopper’s notebook, 1947
For more complex programs, follow this strategy at the level of sub-
components.
For example, you can try debugging at the level of one expression before trying
the whole procedure.
Break your program into several procedures so you can test and debug each procedure
independently. The smaller the unit you test at one time, the easier it is to understand
and fix problems.
DrRacket provides many useful and powerful features to aid debugging, but the most
important tool for debugging is using your brain to think carefully about what
your program should be doing and how its observed behavior differs from the
desired behavior. Next, we describe two simple ways to observe program behavior.
4.5.1 Printing
One useful procedure built-in to DrRacket is the display. It takes one input, and
produces no output.
Instead of producing an output, it prints out the value of the input (it will
appear in purple in the Interactions window). We can use displayto observe what a
procedure is doing as it is evaluated.
For example, if we add a (display n) expression at the beginning of ourfactorial procedure
we can see all the intermediate calls.
To make each printed value appear on a separate line, we use the newline.
The newline procedure prints a new line; it takes no inputs and produces no output.
(define (factorial n)
") (display n)(display "Enter
(newline) (if (= n 0) 1 (* n (factorial (- n 1)))))
factorial:
printingprintf The built-in printf procedure makes it easier to print out many values at
once. It takes one or more inputs.
The first input is a string (a sequence of characters enclosed in double quotes).
The string can include special ~amarkers that print out values of objects inside the
string.
Evaluating (factorial 2) produces:
Enter factorial: 2
Enter factorial: 1
Enter factorial: 0
Each ~a marker is matched with a corresponding input, and the value of that input is
printed in place of the ~a in the string. Another special marker, ~n, prints out a new line
inside the string.
Using printf, we can define our factorial procedure with printing as:
(define (factorial n)
(printf "Enter factorial: a n" n)
(if (= n 0) 1 (* n (factorial (- n 1)))))
The display, printf, and newline procedures do not produce output values.
Instead, they are applied to produce side effects. A side effect is something that changes
the state of a computation.
In this case, the side effect is printing in the Interactions window. Side effects
make reasoning about what programs do much more complicated since the order
in which events happen now matters.
We will mostly avoid using procedures with side effects until Chapter 9, but
printing procedures are so useful that we introduce them here.

More Related Content

What's hot

Flowchart and algorithem
Flowchart and algorithemFlowchart and algorithem
Flowchart and algorithem
ehsanullah786
 
2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem
Frankie Jones
 
Algorithm and Flowcharts
Algorithm and FlowchartsAlgorithm and Flowcharts
Algorithm and Flowcharts
Sabik T S
 
Introduction to flowchart
Introduction to flowchartIntroduction to flowchart
Introduction to flowchart
Jordan Delacruz
 
Flowcharts and pseudocodes
Flowcharts and pseudocodesFlowcharts and pseudocodes
Flowcharts and pseudocodes
Dr Piyush Charan
 
Algorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo codeAlgorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo code
hamza javed
 
Flowcharting and Algorithm
Flowcharting and Algorithm Flowcharting and Algorithm
Flowcharting and Algorithm
Zeinna Belle Desamito
 
Algorithms & flowcharts
Algorithms & flowchartsAlgorithms & flowcharts
Problem solving and design
Problem solving and designProblem solving and design
Problem solving and design
Renée Howard-Johnson
 
Pseudocode algorithim flowchart
Pseudocode algorithim flowchartPseudocode algorithim flowchart
Pseudocode algorithim flowchart
fika sweety
 
phases of algorithm
phases of algorithmphases of algorithm
phases of algorithm
sti meycauayan
 
Introduction to Algorithms & flow charts
Introduction to Algorithms & flow chartsIntroduction to Algorithms & flow charts
Introduction to Algorithms & flow charts
Yash Gupta
 
Lesson 2....PPT 1
Lesson 2....PPT 1Lesson 2....PPT 1
Lesson 2....PPT 1
bhushan Nehete
 
Flowcharts and algorithms
Flowcharts and algorithmsFlowcharts and algorithms
Flowcharts and algorithms
Student
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
 

What's hot (20)

Flowchart and algorithem
Flowchart and algorithemFlowchart and algorithem
Flowchart and algorithem
 
2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem
 
Unit 3
Unit 3Unit 3
Unit 3
 
Algorithm and Flowcharts
Algorithm and FlowchartsAlgorithm and Flowcharts
Algorithm and Flowcharts
 
Introduction to flowchart
Introduction to flowchartIntroduction to flowchart
Introduction to flowchart
 
Debugging
DebuggingDebugging
Debugging
 
Flowcharts and pseudocodes
Flowcharts and pseudocodesFlowcharts and pseudocodes
Flowcharts and pseudocodes
 
Algorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo codeAlgorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo code
 
Flowcharting and Algorithm
Flowcharting and Algorithm Flowcharting and Algorithm
Flowcharting and Algorithm
 
Algorithms & flowcharts
Algorithms & flowchartsAlgorithms & flowcharts
Algorithms & flowcharts
 
Problem solving and design
Problem solving and designProblem solving and design
Problem solving and design
 
Pseudocode algorithim flowchart
Pseudocode algorithim flowchartPseudocode algorithim flowchart
Pseudocode algorithim flowchart
 
phases of algorithm
phases of algorithmphases of algorithm
phases of algorithm
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
Introduction to Algorithms & flow charts
Introduction to Algorithms & flow chartsIntroduction to Algorithms & flow charts
Introduction to Algorithms & flow charts
 
Lesson 2....PPT 1
Lesson 2....PPT 1Lesson 2....PPT 1
Lesson 2....PPT 1
 
Flowcharts and algorithms
Flowcharts and algorithmsFlowcharts and algorithms
Flowcharts and algorithms
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Scope of variables
Scope of variablesScope of variables
Scope of variables
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 

Viewers also liked

languages
languageslanguages
languages
Rajendran
 
recursive transition_networks
recursive transition_networksrecursive transition_networks
recursive transition_networks
Rajendran
 
modeling computing
modeling computingmodeling computing
modeling computing
Rajendran
 
mutable pairs_and_lists
mutable pairs_and_listsmutable pairs_and_lists
mutable pairs_and_lists
Rajendran
 
Regular expressions h1
Regular expressions h1Regular expressions h1
Regular expressions h1
Rajendran
 
parser
parserparser
parser
Rajendran
 
inheritance
inheritanceinheritance
inheritance
Rajendran
 
1.3 applications, issues
1.3 applications, issues1.3 applications, issues
1.3 applications, issues
Rajendran
 
decisions
decisionsdecisions
decisions
Rajendran
 
processes
processesprocesses
processes
Rajendran
 
histry of_computing_machines
histry of_computing_machineshistry of_computing_machines
histry of_computing_machines
Rajendran
 
expressions
expressionsexpressions
expressions
Rajendran
 
measuring computing_power
measuring computing_powermeasuring computing_power
measuring computing_power
Rajendran
 
Quicksort
QuicksortQuicksort
Quicksort
Rajendran
 
Normal forms cfg
Normal forms   cfgNormal forms   cfg
Normal forms cfg
Rajendran
 
TM - Techniques
TM - TechniquesTM - Techniques
TM - Techniques
Rajendran
 
Pumping lemma for regular set h1
Pumping lemma for regular set h1Pumping lemma for regular set h1
Pumping lemma for regular set h1
Rajendran
 
Basics of data structure
Basics of data structureBasics of data structure
Basics of data structure
Rajendran
 

Viewers also liked (19)

languages
languageslanguages
languages
 
recursive transition_networks
recursive transition_networksrecursive transition_networks
recursive transition_networks
 
modeling computing
modeling computingmodeling computing
modeling computing
 
mutable pairs_and_lists
mutable pairs_and_listsmutable pairs_and_lists
mutable pairs_and_lists
 
Regular expressions h1
Regular expressions h1Regular expressions h1
Regular expressions h1
 
parser
parserparser
parser
 
inheritance
inheritanceinheritance
inheritance
 
1.3 applications, issues
1.3 applications, issues1.3 applications, issues
1.3 applications, issues
 
decisions
decisionsdecisions
decisions
 
processes
processesprocesses
processes
 
histry of_computing_machines
histry of_computing_machineshistry of_computing_machines
histry of_computing_machines
 
expressions
expressionsexpressions
expressions
 
measuring computing_power
measuring computing_powermeasuring computing_power
measuring computing_power
 
Binary trees
Binary treesBinary trees
Binary trees
 
Quicksort
QuicksortQuicksort
Quicksort
 
Normal forms cfg
Normal forms   cfgNormal forms   cfg
Normal forms cfg
 
TM - Techniques
TM - TechniquesTM - Techniques
TM - Techniques
 
Pumping lemma for regular set h1
Pumping lemma for regular set h1Pumping lemma for regular set h1
Pumping lemma for regular set h1
 
Basics of data structure
Basics of data structureBasics of data structure
Basics of data structure
 

Similar to developing complex_programs

Procedural programming
Procedural programmingProcedural programming
Procedural programming
Ankit92Chitnavis
 
S D D Program Development Tools
S D D  Program  Development  ToolsS D D  Program  Development  Tools
S D D Program Development Toolsgavhays
 
265 ge8151 problem solving and python programming - 2 marks with answers
265   ge8151 problem solving and python programming - 2 marks with answers265   ge8151 problem solving and python programming - 2 marks with answers
265 ge8151 problem solving and python programming - 2 marks with answers
vithyanila
 
PCCF UNIT 1.pptx
PCCF UNIT 1.pptxPCCF UNIT 1.pptx
PCCF UNIT 1.pptx
DivyaKS12
 
Introduction to computer science
Introduction to computer scienceIntroduction to computer science
Introduction to computer science
umardanjumamaiwada
 
lecture 5
 lecture 5 lecture 5
lecture 5
umardanjumamaiwada
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)
praveena p
 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c language
kamalbeydoun
 
Debugging and optimization of multi-thread OpenMP-programs
Debugging and optimization of multi-thread OpenMP-programsDebugging and optimization of multi-thread OpenMP-programs
Debugging and optimization of multi-thread OpenMP-programs
PVS-Studio
 
Introduction to Computer Programming
Introduction to Computer ProgrammingIntroduction to Computer Programming
Introduction to Computer ProgrammingProf. Erwin Globio
 
Module 1 python.pptx
Module 1 python.pptxModule 1 python.pptx
Module 1 python.pptx
AnuragJoshi813963
 
Debugger & Profiler in NetBeans
Debugger & Profiler in NetBeansDebugger & Profiler in NetBeans
Debugger & Profiler in NetBeans
Huu Bang Le Phan
 
Cpp Homework Help
Cpp Homework Help Cpp Homework Help
Cpp Homework Help
C++ Homework Help
 
Program understanding: What programmers really want
Program understanding: What programmers really wantProgram understanding: What programmers really want
Program understanding: What programmers really wantEinar Høst
 
Book management system
Book management systemBook management system
Book management system
SHARDA SHARAN
 
debugging-for-functional-consultants_compress.pdf
debugging-for-functional-consultants_compress.pdfdebugging-for-functional-consultants_compress.pdf
debugging-for-functional-consultants_compress.pdf
ssuserd257fb
 
Programming_Lecture_1.pptx
Programming_Lecture_1.pptxProgramming_Lecture_1.pptx
Programming_Lecture_1.pptx
shoaibkhan716300
 
What is algorithm
What is algorithmWhat is algorithm
What is algorithm
mshoaib15
 
Testing parallel programs
Testing parallel programsTesting parallel programs
Testing parallel programs
PVS-Studio
 

Similar to developing complex_programs (20)

Procedural programming
Procedural programmingProcedural programming
Procedural programming
 
S D D Program Development Tools
S D D  Program  Development  ToolsS D D  Program  Development  Tools
S D D Program Development Tools
 
265 ge8151 problem solving and python programming - 2 marks with answers
265   ge8151 problem solving and python programming - 2 marks with answers265   ge8151 problem solving and python programming - 2 marks with answers
265 ge8151 problem solving and python programming - 2 marks with answers
 
PCCF UNIT 1.pptx
PCCF UNIT 1.pptxPCCF UNIT 1.pptx
PCCF UNIT 1.pptx
 
Introduction to computer science
Introduction to computer scienceIntroduction to computer science
Introduction to computer science
 
lecture 5
 lecture 5 lecture 5
lecture 5
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)
 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c language
 
Debugging and optimization of multi-thread OpenMP-programs
Debugging and optimization of multi-thread OpenMP-programsDebugging and optimization of multi-thread OpenMP-programs
Debugging and optimization of multi-thread OpenMP-programs
 
Introduction to Computer Programming
Introduction to Computer ProgrammingIntroduction to Computer Programming
Introduction to Computer Programming
 
Module 1 python.pptx
Module 1 python.pptxModule 1 python.pptx
Module 1 python.pptx
 
Debugger & Profiler in NetBeans
Debugger & Profiler in NetBeansDebugger & Profiler in NetBeans
Debugger & Profiler in NetBeans
 
Cpp Homework Help
Cpp Homework Help Cpp Homework Help
Cpp Homework Help
 
Program understanding: What programmers really want
Program understanding: What programmers really wantProgram understanding: What programmers really want
Program understanding: What programmers really want
 
C++ ppt
C++ pptC++ ppt
C++ ppt
 
Book management system
Book management systemBook management system
Book management system
 
debugging-for-functional-consultants_compress.pdf
debugging-for-functional-consultants_compress.pdfdebugging-for-functional-consultants_compress.pdf
debugging-for-functional-consultants_compress.pdf
 
Programming_Lecture_1.pptx
Programming_Lecture_1.pptxProgramming_Lecture_1.pptx
Programming_Lecture_1.pptx
 
What is algorithm
What is algorithmWhat is algorithm
What is algorithm
 
Testing parallel programs
Testing parallel programsTesting parallel programs
Testing parallel programs
 

More from Rajendran

Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower bounds
Rajendran
 
Scheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsScheduling with Startup and Holding Costs
Scheduling with Startup and Holding Costs
Rajendran
 
Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower bounds
Rajendran
 
Red black tree
Red black treeRed black tree
Red black tree
Rajendran
 
Hash table
Hash tableHash table
Hash table
Rajendran
 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statistics
Rajendran
 
Proof master theorem
Proof master theoremProof master theorem
Proof master theorem
Rajendran
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
Rajendran
 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theorem
Rajendran
 
Master method
Master method Master method
Master method
Rajendran
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
Rajendran
 
Hash tables
Hash tablesHash tables
Hash tables
Rajendran
 
Lower bound
Lower boundLower bound
Lower bound
Rajendran
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
Rajendran
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
Rajendran
 
Longest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisLongest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm Analysis
Rajendran
 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm Analysis
Rajendran
 
Average case Analysis of Quicksort
Average case Analysis of QuicksortAverage case Analysis of Quicksort
Average case Analysis of Quicksort
Rajendran
 
Np completeness
Np completenessNp completeness
Np completeness
Rajendran
 
computer languages
computer languagescomputer languages
computer languages
Rajendran
 

More from Rajendran (20)

Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower bounds
 
Scheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsScheduling with Startup and Holding Costs
Scheduling with Startup and Holding Costs
 
Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower bounds
 
Red black tree
Red black treeRed black tree
Red black tree
 
Hash table
Hash tableHash table
Hash table
 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statistics
 
Proof master theorem
Proof master theoremProof master theorem
Proof master theorem
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theorem
 
Master method
Master method Master method
Master method
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Hash tables
Hash tablesHash tables
Hash tables
 
Lower bound
Lower boundLower bound
Lower bound
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Longest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisLongest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm Analysis
 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm Analysis
 
Average case Analysis of Quicksort
Average case Analysis of QuicksortAverage case Analysis of Quicksort
Average case Analysis of Quicksort
 
Np completeness
Np completenessNp completeness
Np completeness
 
computer languages
computer languagescomputer languages
computer languages
 

Recently uploaded

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 

Recently uploaded (20)

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 

developing complex_programs

  • 1. 4.5 Developing complex programs To develop and use more complex procedures it will be useful to learn some helpful techniques for understanding what is going on when procedures are evaluated. It is very rare for a first version of a program to be completely correct, even for an expert programmer. Wise programmers build programs incrementally, by writing and testing small components one at a time. The process of fixing broken programs is known as debugging. The key to debugging effectively is to be systematic and thoughtful. It is a good idea to take notes to keep track of what you have learned and what you have tried. Thoughtless debugging can be very frustrating, and is unlikely to lead to a correct program. A good strategy for debugging is to: 1. Ensure you understand the intended behavior of your procedure. Think of a few representative inputs, and what the expected output should be. 2. Do experiments to observe the actual behavior of your procedure. Try your program on simple inputs first. What is the relationship between the actual outputs and the desired outputs? Does it work correctly for some inputs but not others?
  • 2. 3. Make changes to your procedure and retest it. If you are not sure what to do, make changes in small steps and carefully observe the impact of each change. First actual bug. Grace Hopper’s notebook, 1947 For more complex programs, follow this strategy at the level of sub- components. For example, you can try debugging at the level of one expression before trying the whole procedure. Break your program into several procedures so you can test and debug each procedure independently. The smaller the unit you test at one time, the easier it is to understand and fix problems. DrRacket provides many useful and powerful features to aid debugging, but the most important tool for debugging is using your brain to think carefully about what your program should be doing and how its observed behavior differs from the desired behavior. Next, we describe two simple ways to observe program behavior.
  • 3. 4.5.1 Printing One useful procedure built-in to DrRacket is the display. It takes one input, and produces no output. Instead of producing an output, it prints out the value of the input (it will appear in purple in the Interactions window). We can use displayto observe what a procedure is doing as it is evaluated. For example, if we add a (display n) expression at the beginning of ourfactorial procedure we can see all the intermediate calls. To make each printed value appear on a separate line, we use the newline. The newline procedure prints a new line; it takes no inputs and produces no output. (define (factorial n) ") (display n)(display "Enter (newline) (if (= n 0) 1 (* n (factorial (- n 1))))) factorial: printingprintf The built-in printf procedure makes it easier to print out many values at once. It takes one or more inputs. The first input is a string (a sequence of characters enclosed in double quotes). The string can include special ~amarkers that print out values of objects inside the string. Evaluating (factorial 2) produces: Enter factorial: 2 Enter factorial: 1 Enter factorial: 0
  • 4. Each ~a marker is matched with a corresponding input, and the value of that input is printed in place of the ~a in the string. Another special marker, ~n, prints out a new line inside the string. Using printf, we can define our factorial procedure with printing as: (define (factorial n) (printf "Enter factorial: a n" n) (if (= n 0) 1 (* n (factorial (- n 1))))) The display, printf, and newline procedures do not produce output values. Instead, they are applied to produce side effects. A side effect is something that changes the state of a computation. In this case, the side effect is printing in the Interactions window. Side effects make reasoning about what programs do much more complicated since the order in which events happen now matters. We will mostly avoid using procedures with side effects until Chapter 9, but printing procedures are so useful that we introduce them here.