Lecture 3 - Functions, Scoping and Software Development Flashcards
Advantages of creating functions
Constructing - does only one thing
Testing - does only one thing
Debugging - does only one thing
Maintenance - less duplication, modificiations easy to make
Expansion/enhancement - improving a function makes improvement available to all code using function
Re-use - general functions can built into warehouse of tools
Disadvantages of creating functions
More planning required before coding
Slight execution time cost
What are environments?
Structures that organise objects in an R-programme
What do environments do?
Associates a set of names to a set of values, perhaps pointing to same object address
What are the two types of environments?
Global and current environments
What happens to the environment when packages are loaded?
They are added as parents of the global environment
What are the scoping rules?
Name making
Function making
Fresh start
Where to look for values associated with objects
What happens if a name isn’t defined in an environment?
R looks up one level in the environment structure
What happens to a functions environment for each new use?
It is wiped clean
When does a lookup of names happen?
At the time the code is executed, not created
Why should you test code?
Nobody writes perfect code
Testing can demonstrate sections of code working properly
Reduces possible suspects for further debugging
What are three different debugging methods?
Compile time
Batch debugging
Interactive debugging
Compile time debugging method
Only errors found here are syntax or for some languages, whether variables have been initialised for use.
What is batch debugging?
Peppering code with print( ) statements.
Run code, examine output to find unexpected results. Clumsy approach as code needs to be sanitised of print( ) after errors found)
What is interactive debugging?
Set breakpoints, step through code, examine and alter variables while code pauses.
What are the stages of statistical software
specification definition implementation verification delivery and usage maintenance
What are two different types of approach to software development?
Plan drive
Agile
What is the waterfall model for software development?
specification/definition/implementation done in unwavering order.
Agreement between user and programmers from the beginning
Documentation and verification of each stage of the process
Advantages of waterfall model
End result agreed at beginning
Lots of documentation
Works well for large projects and large organisations
Disadvantages of waterfall model
Inflexible
Struggles when project requirements change
What is the iterative model for software development?
Planning a project is incremental
Do a bit of specification, bit of coding, bit of verification
Start simple, modify design, enhance capabilities.
Advantages of iterative model
Can respond to changing circumstances
Less time agreeing and documenting decisions
Disadvantages of iterative model
End result of code is undefined until the end
Less documentation of decisions
What to do if you use code written by someone else?
Acknowledge them
Test it actually performs for your purpose
Take time to understand and learn from it
R code in packages might not be examples of good practice or easy to comprehend.