Lecture 3 - Functions, Scoping and Software Development Flashcards

1
Q

Advantages of creating functions

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Disadvantages of creating functions

A

More planning required before coding

Slight execution time cost

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are environments?

A

Structures that organise objects in an R-programme

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What do environments do?

A

Associates a set of names to a set of values, perhaps pointing to same object address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the two types of environments?

A

Global and current environments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What happens to the environment when packages are loaded?

A

They are added as parents of the global environment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the scoping rules?

A

Name making
Function making
Fresh start
Where to look for values associated with objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What happens if a name isn’t defined in an environment?

A

R looks up one level in the environment structure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What happens to a functions environment for each new use?

A

It is wiped clean

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When does a lookup of names happen?

A

At the time the code is executed, not created

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why should you test code?

A

Nobody writes perfect code
Testing can demonstrate sections of code working properly
Reduces possible suspects for further debugging

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are three different debugging methods?

A

Compile time
Batch debugging
Interactive debugging

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Compile time debugging method

A

Only errors found here are syntax or for some languages, whether variables have been initialised for use.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is batch debugging?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is interactive debugging?

A

Set breakpoints, step through code, examine and alter variables while code pauses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the stages of statistical software

A
specification
definition
implementation
verification
delivery and usage
maintenance
17
Q

What are two different types of approach to software development?

A

Plan drive

Agile

18
Q

What is the waterfall model for software development?

A

specification/definition/implementation done in unwavering order.
Agreement between user and programmers from the beginning
Documentation and verification of each stage of the process

19
Q

Advantages of waterfall model

A

End result agreed at beginning
Lots of documentation
Works well for large projects and large organisations

20
Q

Disadvantages of waterfall model

A

Inflexible

Struggles when project requirements change

21
Q

What is the iterative model for software development?

A

Planning a project is incremental
Do a bit of specification, bit of coding, bit of verification
Start simple, modify design, enhance capabilities.

22
Q

Advantages of iterative model

A

Can respond to changing circumstances

Less time agreeing and documenting decisions

23
Q

Disadvantages of iterative model

A

End result of code is undefined until the end

Less documentation of decisions

24
Q

What to do if you use code written by someone else?

A

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.

25
Q

Programming style

A

Implement principle of least privilege
Working code preferable to fast, broken codes
seek out redundant code and convert to module

26
Q

Coding practice within modules

A

Initialise object used in module at beginning
Include error checks - arguments
Resist temptation to make code terribly dense
Do not nest conditional/looping structures beyond 3 levels deep.

27
Q

Coding conventions

A

Rationale - decrease coding errors, increase readability, enhance possible reuse.
All functions begin with comments proving information on purpose, input/output, implementation details.
Use indentation for control structures
Meaningful variable names
Consistency of spacing