Static Analysis Flashcards

1
Q

Static Analysis

A

Testing code without executing it.

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

Advantages of Dynamic testing over static

A
  • Doesn’t require special tools.
  • Don’t need special skills.
  • Don’t require source code (blackbox)
  • Testers do not have to be programmers.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Disadvantage of dynamic testing

A
  • Achieving complete code coverage can be hard or impossible.
  • Some failures are hard to trigger, thus hard to find/reproduce.
  • When you find a failure on a larger scale, can be hard to pinpoint.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are some static tools?

A
  1. Typechecking
  2. Code Quality analysis
  3. Contract Verification
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What can we do to typecheck this function?

function onlyWorksOnNumbers(x) {
    return x*10;
}
A

can add (x: number) to parameter.

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

What are some Java typecheck problems

A
  • array index must be int.
  • Java double to float or int fails.
  • Cannot downcast objects.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Static Type Checking

A

Checking source code prior to running to determine whether type rules have been respected.

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

Name some languages with/without static type checking?

A

Java, C++, Go

JS, Python

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

Why don’t all languages use strong static typing?

A
  • Programmers prefer feel of languages without it.
  • Risk of false positives for faults (creates error messages where there shouldn’t be.)
  • Difficult to understand complex type errors.
  • Evidence is inconclusive that it’s useful.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When does strong static typing help?

A

When teams don’t understand language/ system used

Systems used a lot but not changed much (library core components).

Systems needing high integrity (low defects).

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

Code Quality Analysis

A

Automated checking of source code for patterns indicative of errors.

ex. compiler warnings.

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

Give an example of a compiler warning

A

if (a = b)

  • Assignment in place of comparison warning.

if (launchApproved);

  • Empty control flow statement
  • Deprecated methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Why don’t compilers do most of the brunt CQA work?

A

They need to be fast and predictable.

So there are third party applications.

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

Limitations of CQA

A

Can be huge output for large codebases (lots of noise). These can be slightly tuned for use. Need to build from a clean start.

Likely will not help you find serious misbehaviours of code, so perhaps an expensive waste of time.

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

Contract Verification

A

Checks pre-conditions, post conditions and invariants of a class, also signals (exceptions).

Supports design by contracts style.

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

Limitations of some Contract verification applications.

A

Sometimes doesn’t allow:

  • Dynamic memory allocation
  • Pointers
  • Recursion
  • Expression with side effects (print statements?)
17
Q

Where would you use Contract Verification?

A

When you need HIGH confidence of correctness. Like safety Critical systems.

  • Nuclear plant
  • Air Traffic control
18
Q

What are commonalities between Design By Contracts, Static Typing and CQA.

A

Provides a language to express powerful assertions that can be convincingly checked automatically or mostly so. Given the tools and expertises.