SlideShare une entreprise Scribd logo
1  sur  25
Function Design
Michael Heron
Introduction
• The syntax of functions is something we have already
discussed in an earlier lecture.
• In this lecture we are going to talk about the steps that we go
through to write them.
• Like anything in programming, we can do this well or we can do
this badly.
• Our goal is to end up with a program that is a maintainable
whole.
• Something we can easily make changes to later.
Coding Tradeoffs
• In code, we are constantly making trade-offs for the programs
we write.
• We must choose between CPU, memory and the hard-drive
• We must choose between maintainability, efficiency, and size.
• The point where we decide on which of these will vary from
application to application.
• No answer works for all programs.
Efficiency
• The first metric people apply to code is that of efficiency.
• How fast does it run.
• Modern processor speeds have made this less important.
• Computers are just so fast these days that many efficiency
problems are simply gone.
• However, still important for some applications.
• Highly processor intensive applications.
Efficiency
• We’ll talk more about efficiency tomorrow.
• When we discuss algorithms.
• However, it is a measure of how fast your code is.
• Many ways to have efficiency problems.
• Mostly due to code being executed when it doesn’t need to.
• Or using a complex way to perform a task rather than a simple
way.
Efficiency
• Efficiency is prized in many applications.
• Games
• Frame rates are important
• Simulations
• Responsiveness is important
• Artificial intelligence
• Speed of processing determines outputs
• Very efficient code is often difficult to read.
Maintainability
• Maintainability relates to how easily a piece of software can
be changed after it is written.
• Hugely important for most programs.
• Maintainable programs are highly prized
• By the people who have to maintain them!
• Some simple ways exist to ensure maintainability.
• Comments
• Self documenting code
Maintainability
• However, developing a maintainable program needs a certain
structure to the code as well.
• Important to separate things out into as small a chunk as
possible.
• Functions are important for this.
• Various things act against maintainability:
• Monolithic code
• Global scope
• Good program design encourages maintainability.
How To Write A Function
• A function should do one thing, and only that.
• Tempting to make functions very powerful.
• That also makes them, usually, very specific.
• Functions should be small.
• The smaller the function, the better the function (usually)
• Functions should make use of other functions.
• This keeps them small.
How To Write A Function
• Repetition in your code is a good sign that adjustments are
needed.
• Create a loop
• Separate out into a function
• Whenever you are doing the same thing more than one time,
consider adopting a function.
• Consider what information will go in
• This gives you the parameters
• Consider what information must come out
• This gives you the return type.
How To Write A Function
• Functions should do one thing only.
• Consider your assessment.
• One function to print a number of stars
• One function to print stars in a loop
• One function to print the loops in a loop
• The more precisely defined the function, the easier it is to
maintain.
• Don’t need to understand complex logic.
Program Logic
• Program logic is the flow of execution through the code.
• It can very easily become extremely difficult to understand.
• Functions help manage that by separating out functionality
into logical blocks.
• Can concentrate on the high level interaction and not the low
level.
Abstraction
• This is a process called abstraction.
• Ignore the little details, just focus on the big picture.
• Very important in programming.
• Big part of pattern recognition.
• Functions aid in abstraction.
• We don’t need to know when they’re called how they work.
• Just need to know what they do.
Maintenance
• Most programming work is maintenance.
• Fixing broken code
• Adding in new features
• Adjusting new features.
• Around 80% of all programming time is spent on this task.
• Eeek
• Hugely important to design maintainable programs.
Designing a Function
• Various ways exist to help design functions.
• Common way known as top down design.
• Concentrate on the main steps of the program.
• Leave out the details.
• Like a higher level pseudocode.
• This is known as procedural abstraction.
• We pretend each function is a black box.
• Doesn’t matter how it works, just what it does.
Document Driven Functions
• Good way to do this is write the documentation for functions
first.
• Functions should be commented for high level understanding.
• What do they do
• What are their parameters
• What do they mean
• What is the return type
Function Commenting
/*
*
* This function takes in two parameters and returns the power of
* the first to the second.
*
* param num The number we wish to raise
* param power The power to which we raise it
* returns The number which is num^power.
*
*/
Don’t need to know how it does it.
We just need to know what information it needs, and what information it gives us.
Adding Functionality
• How do we add new functionality to a program?
• New functions
• Alterations in the user interface
• Relatively straight-forward for completely new features.
• My program calculates the power, now have it calculate the root
• More complicated for other situations.
• It no longer deals with pure integers, now handles floating point
numbers.
Fixing
• There is an informal metric in software engineering.
• For every two bugs you fix, you probably introduced a third in the
process.
• Fixing software is an ongoing process.
• Only really find out when people are using software where the really
obscure bugs are.
• Big part of maintenance focused on ensuring bug-free software.
• Never ending goal!
Changes
• It is when we change functionality that we really benefit from
high maintainability.
• Many reasons why we may want to do this:
• Laws change
• Procedures change
• Data structures change
• A good program is one that permits us to keep it up to date
with requirements.
How?
• Good functions hide their implementation details.
• We know what goes in and comes out
• That is not necessarily related to how they are handled internally.
• We call the exposed details of a function its interface.
• Return type
• Name
• Parameters
• Everything else is its implementation.
Function Interface
• The interface to a function cannot be changed if we do not
wish to make more work for ourselves.
• There are some rules that help us deal with this, which we will
talk about in a later week.
• When working with multiple developers, we must be
respectful of our fellow coders.
• Our function interface represents an informal contract with our
colleagues.
Function Interface
• Provided we were sensible, this is not especially limiting.
• We can overload functions if necessary, for example.
• What happens inside the function is entirely our business.
• We can make changes largely on a whim, provided the external
behaviour remains unchanged.
• This is actually a very common process.
Refactoring
• Refactoring is the process of taking code we wrote in the past,
and rewriting it the way we would have if we had the time.
• As developers, we never write code as well as we can all of the
time.
• External constraints limit us.
• It’s a good idea to refactor code.
• It solves problems before they occur.
• Must be done carefully though.
Summary
• Maintainability is important for good programs.
• Functions help us ensure that our code is well designed for this
purpose.
• Many ways in which functions should be written.
• Important to separate out the interface from the implementation.
• Procedural abstraction as a process aids in function design.
• Write what they do, not how they do it.

Contenu connexe

Tendances

What when and why Automation
What when and why Automation What when and why Automation
What when and why Automation Ranjeet Sharma
 
Extreme Programming Deployed
Extreme Programming DeployedExtreme Programming Deployed
Extreme Programming DeployedSteve Loughran
 
DevOps Days Vancouver 2014 Slides
DevOps Days Vancouver 2014 SlidesDevOps Days Vancouver 2014 Slides
DevOps Days Vancouver 2014 SlidesAlex Cruise
 
Agile Testing
Agile Testing Agile Testing
Agile Testing VersionOne
 
Functional Programming Introduction
Functional Programming IntroductionFunctional Programming Introduction
Functional Programming IntroductionRoberto Lopez
 

Tendances (7)

What when and why Automation
What when and why Automation What when and why Automation
What when and why Automation
 
Bowtie finals
Bowtie finalsBowtie finals
Bowtie finals
 
Extreme Programming Deployed
Extreme Programming DeployedExtreme Programming Deployed
Extreme Programming Deployed
 
DevOps Days Vancouver 2014 Slides
DevOps Days Vancouver 2014 SlidesDevOps Days Vancouver 2014 Slides
DevOps Days Vancouver 2014 Slides
 
Agile Testing
Agile Testing Agile Testing
Agile Testing
 
Convert olm to pst
Convert olm to pstConvert olm to pst
Convert olm to pst
 
Functional Programming Introduction
Functional Programming IntroductionFunctional Programming Introduction
Functional Programming Introduction
 

En vedette

Topic 2 Innovation
Topic 2 InnovationTopic 2 Innovation
Topic 2 Innovationguest5dc00b
 
Intro to product design
Intro to product designIntro to product design
Intro to product designPaula Te
 
Product Design in Operations Management
Product Design in Operations ManagementProduct Design in Operations Management
Product Design in Operations ManagementSemih Gümüşbaş
 
Lecture 5 - Indicators of innovation and technological change: R&D and patents
Lecture 5 - Indicators of innovation and technological change: R&D and patentsLecture 5 - Indicators of innovation and technological change: R&D and patents
Lecture 5 - Indicators of innovation and technological change: R&D and patentsUNU.MERIT
 
CPP02 - The Structure of a Program
CPP02 - The Structure of a ProgramCPP02 - The Structure of a Program
CPP02 - The Structure of a ProgramMichael Heron
 
Representation of geometric figuers in Braille
Representation of  geometric figuers in BrailleRepresentation of  geometric figuers in Braille
Representation of geometric figuers in BrailleBIJIT GHOSH
 
CPP01 - Introduction to C++
CPP01 - Introduction to C++CPP01 - Introduction to C++
CPP01 - Introduction to C++Michael Heron
 
Secure communication in Networking
Secure communication in NetworkingSecure communication in Networking
Secure communication in Networkinganita maharjan
 
PHAME: Principles of Hierarchy Abstraction Modularization and Encapsulation
PHAME: Principles of Hierarchy Abstraction Modularization and EncapsulationPHAME: Principles of Hierarchy Abstraction Modularization and Encapsulation
PHAME: Principles of Hierarchy Abstraction Modularization and EncapsulationTushar Sharma
 
Refactoring for Design Smells - ICSE 2014 Tutorial
Refactoring for Design Smells - ICSE 2014 TutorialRefactoring for Design Smells - ICSE 2014 Tutorial
Refactoring for Design Smells - ICSE 2014 TutorialTushar Sharma
 

En vedette (20)

Topic 2 Innovation
Topic 2 InnovationTopic 2 Innovation
Topic 2 Innovation
 
Intro to product design
Intro to product designIntro to product design
Intro to product design
 
Product Design in Operations Management
Product Design in Operations ManagementProduct Design in Operations Management
Product Design in Operations Management
 
Lecture 5 - Indicators of innovation and technological change: R&D and patents
Lecture 5 - Indicators of innovation and technological change: R&D and patentsLecture 5 - Indicators of innovation and technological change: R&D and patents
Lecture 5 - Indicators of innovation and technological change: R&D and patents
 
CPP07 - Scope
CPP07 - ScopeCPP07 - Scope
CPP07 - Scope
 
CPP09 - Testing
CPP09 - TestingCPP09 - Testing
CPP09 - Testing
 
CPP08 - Pointers
CPP08 - PointersCPP08 - Pointers
CPP08 - Pointers
 
CPP02 - The Structure of a Program
CPP02 - The Structure of a ProgramCPP02 - The Structure of a Program
CPP02 - The Structure of a Program
 
Representation of geometric figuers in Braille
Representation of  geometric figuers in BrailleRepresentation of  geometric figuers in Braille
Representation of geometric figuers in Braille
 
CPP19 - Revision
CPP19 - RevisionCPP19 - Revision
CPP19 - Revision
 
CPP04 - Selection
CPP04 - SelectionCPP04 - Selection
CPP04 - Selection
 
CPP01 - Introduction to C++
CPP01 - Introduction to C++CPP01 - Introduction to C++
CPP01 - Introduction to C++
 
CPP03 - Repetition
CPP03 - RepetitionCPP03 - Repetition
CPP03 - Repetition
 
CPP10 - Debugging
CPP10 - DebuggingCPP10 - Debugging
CPP10 - Debugging
 
CPP12 - Algorithms
CPP12 - AlgorithmsCPP12 - Algorithms
CPP12 - Algorithms
 
Secure communication in Networking
Secure communication in NetworkingSecure communication in Networking
Secure communication in Networking
 
CPP05 - Arrays
CPP05 - ArraysCPP05 - Arrays
CPP05 - Arrays
 
CPP06 - Functions
CPP06 - FunctionsCPP06 - Functions
CPP06 - Functions
 
PHAME: Principles of Hierarchy Abstraction Modularization and Encapsulation
PHAME: Principles of Hierarchy Abstraction Modularization and EncapsulationPHAME: Principles of Hierarchy Abstraction Modularization and Encapsulation
PHAME: Principles of Hierarchy Abstraction Modularization and Encapsulation
 
Refactoring for Design Smells - ICSE 2014 Tutorial
Refactoring for Design Smells - ICSE 2014 TutorialRefactoring for Design Smells - ICSE 2014 Tutorial
Refactoring for Design Smells - ICSE 2014 Tutorial
 

Similaire à CPP11 - Function Design

Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem slovingMani Kandan
 
Deep Dive into the Idea of Software Architecture
Deep Dive into the Idea of Software ArchitectureDeep Dive into the Idea of Software Architecture
Deep Dive into the Idea of Software ArchitectureMatthew Clarke
 
An Introduction To Software Development - Implementation
An Introduction To Software Development - ImplementationAn Introduction To Software Development - Implementation
An Introduction To Software Development - ImplementationBlue Elephant Consulting
 
Project Life Cycle and Effort Estimation
Project Life Cycle andEffort EstimationProject Life Cycle andEffort Estimation
Project Life Cycle and Effort Estimationssuserb7c8b8
 
OOP -interface and objects.pptx
OOP -interface and objects.pptxOOP -interface and objects.pptx
OOP -interface and objects.pptxEdFeranil
 
classVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxclassVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxssusere336f4
 
Introducing systems analysis, design & development Concepts
Introducing systems analysis, design & development ConceptsIntroducing systems analysis, design & development Concepts
Introducing systems analysis, design & development ConceptsShafiul Azam Chowdhury
 
Overview of Software Engineering Principles - SCPS311.pptx
Overview of Software Engineering Principles - SCPS311.pptxOverview of Software Engineering Principles - SCPS311.pptx
Overview of Software Engineering Principles - SCPS311.pptxBypassFrp
 
Effective cplusplus
Effective cplusplusEffective cplusplus
Effective cplusplusMark Veltzer
 
Agile Software Development
Agile Software DevelopmentAgile Software Development
Agile Software DevelopmentAhmet Bulut
 
Introducing Systems Analysis Design Development
Introducing Systems Analysis Design DevelopmentIntroducing Systems Analysis Design Development
Introducing Systems Analysis Design Developmentbsadd
 
CHAPTER 1 Creating a ProgramOBJECTIVES· Analyze some of the i.docx
CHAPTER 1 Creating a ProgramOBJECTIVES· Analyze some of the i.docxCHAPTER 1 Creating a ProgramOBJECTIVES· Analyze some of the i.docx
CHAPTER 1 Creating a ProgramOBJECTIVES· Analyze some of the i.docxwalterl4
 
Gearman: A Job Server made for Scale
Gearman: A Job Server made for ScaleGearman: A Job Server made for Scale
Gearman: A Job Server made for ScaleMike Willbanks
 
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptxCOMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptxSherinRappai1
 
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptxCOMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptxSherinRappai
 
Patterns of enterprise application architecture
Patterns of enterprise application architecturePatterns of enterprise application architecture
Patterns of enterprise application architectureChinh Ngo Nguyen
 

Similaire à CPP11 - Function Design (20)

C- language Lecture 4
C- language Lecture 4C- language Lecture 4
C- language Lecture 4
 
OOSE UNIT-1.pdf
OOSE UNIT-1.pdfOOSE UNIT-1.pdf
OOSE UNIT-1.pdf
 
Algorithmic problem sloving
Algorithmic problem slovingAlgorithmic problem sloving
Algorithmic problem sloving
 
Deep Dive into the Idea of Software Architecture
Deep Dive into the Idea of Software ArchitectureDeep Dive into the Idea of Software Architecture
Deep Dive into the Idea of Software Architecture
 
An Introduction To Software Development - Implementation
An Introduction To Software Development - ImplementationAn Introduction To Software Development - Implementation
An Introduction To Software Development - Implementation
 
Project Life Cycle and Effort Estimation
Project Life Cycle andEffort EstimationProject Life Cycle andEffort Estimation
Project Life Cycle and Effort Estimation
 
OOP -interface and objects.pptx
OOP -interface and objects.pptxOOP -interface and objects.pptx
OOP -interface and objects.pptx
 
classVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxclassVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptx
 
Introducing systems analysis, design & development Concepts
Introducing systems analysis, design & development ConceptsIntroducing systems analysis, design & development Concepts
Introducing systems analysis, design & development Concepts
 
Overview of Software Engineering Principles - SCPS311.pptx
Overview of Software Engineering Principles - SCPS311.pptxOverview of Software Engineering Principles - SCPS311.pptx
Overview of Software Engineering Principles - SCPS311.pptx
 
Effective cplusplus
Effective cplusplusEffective cplusplus
Effective cplusplus
 
Agile Software Development
Agile Software DevelopmentAgile Software Development
Agile Software Development
 
Introducing Systems Analysis Design Development
Introducing Systems Analysis Design DevelopmentIntroducing Systems Analysis Design Development
Introducing Systems Analysis Design Development
 
CHAPTER 1 Creating a ProgramOBJECTIVES· Analyze some of the i.docx
CHAPTER 1 Creating a ProgramOBJECTIVES· Analyze some of the i.docxCHAPTER 1 Creating a ProgramOBJECTIVES· Analyze some of the i.docx
CHAPTER 1 Creating a ProgramOBJECTIVES· Analyze some of the i.docx
 
C programming
C programmingC programming
C programming
 
Gearman: A Job Server made for Scale
Gearman: A Job Server made for ScaleGearman: A Job Server made for Scale
Gearman: A Job Server made for Scale
 
Coding
CodingCoding
Coding
 
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptxCOMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
 
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptxCOMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
 
Patterns of enterprise application architecture
Patterns of enterprise application architecturePatterns of enterprise application architecture
Patterns of enterprise application architecture
 

Plus de Michael Heron

Meeple centred design - Board Game Accessibility
Meeple centred design - Board Game AccessibilityMeeple centred design - Board Game Accessibility
Meeple centred design - Board Game AccessibilityMichael Heron
 
Musings on misconduct
Musings on misconductMusings on misconduct
Musings on misconductMichael Heron
 
Accessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS FrameworkAccessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS FrameworkMichael Heron
 
ACCESS: A Technical Framework for Adaptive Accessibility Support
ACCESS:  A Technical Framework for Adaptive Accessibility SupportACCESS:  A Technical Framework for Adaptive Accessibility Support
ACCESS: A Technical Framework for Adaptive Accessibility SupportMichael Heron
 
Authorship and Autership
Authorship and AutershipAuthorship and Autership
Authorship and AutershipMichael Heron
 
Text parser based interaction
Text parser based interactionText parser based interaction
Text parser based interactionMichael Heron
 
GRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and RadiosityGRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and RadiosityMichael Heron
 
GRPHICS07 - Textures
GRPHICS07 - TexturesGRPHICS07 - Textures
GRPHICS07 - TexturesMichael Heron
 
GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)Michael Heron
 
GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)Michael Heron
 
GRPHICS03 - Graphical Representation
GRPHICS03 - Graphical RepresentationGRPHICS03 - Graphical Representation
GRPHICS03 - Graphical RepresentationMichael Heron
 
GRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D GraphicsGRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D GraphicsMichael Heron
 
GRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D GraphicsGRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D GraphicsMichael Heron
 
GRPHICS09 - Art Appreciation
GRPHICS09 - Art AppreciationGRPHICS09 - Art Appreciation
GRPHICS09 - Art AppreciationMichael Heron
 

Plus de Michael Heron (20)

Meeple centred design - Board Game Accessibility
Meeple centred design - Board Game AccessibilityMeeple centred design - Board Game Accessibility
Meeple centred design - Board Game Accessibility
 
Musings on misconduct
Musings on misconductMusings on misconduct
Musings on misconduct
 
Accessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS FrameworkAccessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS Framework
 
ACCESS: A Technical Framework for Adaptive Accessibility Support
ACCESS:  A Technical Framework for Adaptive Accessibility SupportACCESS:  A Technical Framework for Adaptive Accessibility Support
ACCESS: A Technical Framework for Adaptive Accessibility Support
 
Authorship and Autership
Authorship and AutershipAuthorship and Autership
Authorship and Autership
 
Text parser based interaction
Text parser based interactionText parser based interaction
Text parser based interaction
 
SAD04 - Inheritance
SAD04 - InheritanceSAD04 - Inheritance
SAD04 - Inheritance
 
GRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and RadiosityGRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and Radiosity
 
GRPHICS07 - Textures
GRPHICS07 - TexturesGRPHICS07 - Textures
GRPHICS07 - Textures
 
GRPHICS06 - Shading
GRPHICS06 - ShadingGRPHICS06 - Shading
GRPHICS06 - Shading
 
GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)
 
GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)
 
GRPHICS03 - Graphical Representation
GRPHICS03 - Graphical RepresentationGRPHICS03 - Graphical Representation
GRPHICS03 - Graphical Representation
 
GRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D GraphicsGRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D Graphics
 
GRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D GraphicsGRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D Graphics
 
GRPHICS09 - Art Appreciation
GRPHICS09 - Art AppreciationGRPHICS09 - Art Appreciation
GRPHICS09 - Art Appreciation
 
2CPP18 - Modifiers
2CPP18 - Modifiers2CPP18 - Modifiers
2CPP18 - Modifiers
 
2CPP17 - File IO
2CPP17 - File IO2CPP17 - File IO
2CPP17 - File IO
 
2CPP16 - STL
2CPP16 - STL2CPP16 - STL
2CPP16 - STL
 
2CPP15 - Templates
2CPP15 - Templates2CPP15 - Templates
2CPP15 - Templates
 

Dernier

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 

Dernier (20)

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 

CPP11 - Function Design

  • 2. Introduction • The syntax of functions is something we have already discussed in an earlier lecture. • In this lecture we are going to talk about the steps that we go through to write them. • Like anything in programming, we can do this well or we can do this badly. • Our goal is to end up with a program that is a maintainable whole. • Something we can easily make changes to later.
  • 3. Coding Tradeoffs • In code, we are constantly making trade-offs for the programs we write. • We must choose between CPU, memory and the hard-drive • We must choose between maintainability, efficiency, and size. • The point where we decide on which of these will vary from application to application. • No answer works for all programs.
  • 4. Efficiency • The first metric people apply to code is that of efficiency. • How fast does it run. • Modern processor speeds have made this less important. • Computers are just so fast these days that many efficiency problems are simply gone. • However, still important for some applications. • Highly processor intensive applications.
  • 5. Efficiency • We’ll talk more about efficiency tomorrow. • When we discuss algorithms. • However, it is a measure of how fast your code is. • Many ways to have efficiency problems. • Mostly due to code being executed when it doesn’t need to. • Or using a complex way to perform a task rather than a simple way.
  • 6. Efficiency • Efficiency is prized in many applications. • Games • Frame rates are important • Simulations • Responsiveness is important • Artificial intelligence • Speed of processing determines outputs • Very efficient code is often difficult to read.
  • 7. Maintainability • Maintainability relates to how easily a piece of software can be changed after it is written. • Hugely important for most programs. • Maintainable programs are highly prized • By the people who have to maintain them! • Some simple ways exist to ensure maintainability. • Comments • Self documenting code
  • 8. Maintainability • However, developing a maintainable program needs a certain structure to the code as well. • Important to separate things out into as small a chunk as possible. • Functions are important for this. • Various things act against maintainability: • Monolithic code • Global scope • Good program design encourages maintainability.
  • 9. How To Write A Function • A function should do one thing, and only that. • Tempting to make functions very powerful. • That also makes them, usually, very specific. • Functions should be small. • The smaller the function, the better the function (usually) • Functions should make use of other functions. • This keeps them small.
  • 10. How To Write A Function • Repetition in your code is a good sign that adjustments are needed. • Create a loop • Separate out into a function • Whenever you are doing the same thing more than one time, consider adopting a function. • Consider what information will go in • This gives you the parameters • Consider what information must come out • This gives you the return type.
  • 11. How To Write A Function • Functions should do one thing only. • Consider your assessment. • One function to print a number of stars • One function to print stars in a loop • One function to print the loops in a loop • The more precisely defined the function, the easier it is to maintain. • Don’t need to understand complex logic.
  • 12. Program Logic • Program logic is the flow of execution through the code. • It can very easily become extremely difficult to understand. • Functions help manage that by separating out functionality into logical blocks. • Can concentrate on the high level interaction and not the low level.
  • 13. Abstraction • This is a process called abstraction. • Ignore the little details, just focus on the big picture. • Very important in programming. • Big part of pattern recognition. • Functions aid in abstraction. • We don’t need to know when they’re called how they work. • Just need to know what they do.
  • 14. Maintenance • Most programming work is maintenance. • Fixing broken code • Adding in new features • Adjusting new features. • Around 80% of all programming time is spent on this task. • Eeek • Hugely important to design maintainable programs.
  • 15. Designing a Function • Various ways exist to help design functions. • Common way known as top down design. • Concentrate on the main steps of the program. • Leave out the details. • Like a higher level pseudocode. • This is known as procedural abstraction. • We pretend each function is a black box. • Doesn’t matter how it works, just what it does.
  • 16. Document Driven Functions • Good way to do this is write the documentation for functions first. • Functions should be commented for high level understanding. • What do they do • What are their parameters • What do they mean • What is the return type
  • 17. Function Commenting /* * * This function takes in two parameters and returns the power of * the first to the second. * * param num The number we wish to raise * param power The power to which we raise it * returns The number which is num^power. * */ Don’t need to know how it does it. We just need to know what information it needs, and what information it gives us.
  • 18. Adding Functionality • How do we add new functionality to a program? • New functions • Alterations in the user interface • Relatively straight-forward for completely new features. • My program calculates the power, now have it calculate the root • More complicated for other situations. • It no longer deals with pure integers, now handles floating point numbers.
  • 19. Fixing • There is an informal metric in software engineering. • For every two bugs you fix, you probably introduced a third in the process. • Fixing software is an ongoing process. • Only really find out when people are using software where the really obscure bugs are. • Big part of maintenance focused on ensuring bug-free software. • Never ending goal!
  • 20. Changes • It is when we change functionality that we really benefit from high maintainability. • Many reasons why we may want to do this: • Laws change • Procedures change • Data structures change • A good program is one that permits us to keep it up to date with requirements.
  • 21. How? • Good functions hide their implementation details. • We know what goes in and comes out • That is not necessarily related to how they are handled internally. • We call the exposed details of a function its interface. • Return type • Name • Parameters • Everything else is its implementation.
  • 22. Function Interface • The interface to a function cannot be changed if we do not wish to make more work for ourselves. • There are some rules that help us deal with this, which we will talk about in a later week. • When working with multiple developers, we must be respectful of our fellow coders. • Our function interface represents an informal contract with our colleagues.
  • 23. Function Interface • Provided we were sensible, this is not especially limiting. • We can overload functions if necessary, for example. • What happens inside the function is entirely our business. • We can make changes largely on a whim, provided the external behaviour remains unchanged. • This is actually a very common process.
  • 24. Refactoring • Refactoring is the process of taking code we wrote in the past, and rewriting it the way we would have if we had the time. • As developers, we never write code as well as we can all of the time. • External constraints limit us. • It’s a good idea to refactor code. • It solves problems before they occur. • Must be done carefully though.
  • 25. Summary • Maintainability is important for good programs. • Functions help us ensure that our code is well designed for this purpose. • Many ways in which functions should be written. • Important to separate out the interface from the implementation. • Procedural abstraction as a process aids in function design. • Write what they do, not how they do it.