Implementation best practices Flashcards

1
Q

What is implementation?

A

Implementation:
- Writing the source code that is needed
to realize the architecture and design
- Comes with its own set of challenges

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

How to manage the implementation process

A

Version management (e.g., Git)
- Coordinate development progress
- Code changes become easily reversible
Build system (e.g., Ant)
- Automate the process of assembling the
system from its sources
Issue tracking (e.g., GitHub Issues)
- Keep track of bug reports and requests for
new system features

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

What is the key implementation concepts?

A
  • Understandability: A universally valid code quality measure
    Keep in mind:
    Code is read by humans!
  • Code describes what a computer should do
  • Yet it is still mainly read by people
  • Thus it should be written with people in mind
  • Testability
  • Reusability
  • Efficiency
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Name the understandability tips!

A
  1. Use meaningful identifier names!
  2. Add comments that complement the code!
    Comments explain “why” not “what”:
    - Code explains what is being done
    - Useless comments repeat what is being
    done, e.g.:
  3. Follow a coding style convention!
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the NASA JPL coding standard for
Java?

A

Purpose:
- To help Java programmers reduce the
probability of run-time errors
- To improve readability and maintainability
of code
Contents:
- 53 rules
- Programming patterns to avoid
- Processes that are useful
- Treat as “guidelines
Process rules:
- R01: Compile with checks turned on
- R02: Apply static analysis (e.g.,
http://findbugs.cs.umd.edu/eclipse/)
- R03: Document public elements
- R04: Write unit tests
Process rules:
- R05: Use the standard naming convention
- http://www.oracle.com/technetwork/java/c
odeconventions-135099.html
- R06: Do not override field or class names
- “Hiding an entity with an entity of the
same name may lead to mistaken
assumptions about the entity being
referred to”
Field rules:
- R17: Make fields private
- R18: Do not use static mutable fields
- R19: Declare immutable fields final
- R20: Initialize fields before use

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

What is a design anti-pattern?

A

Anti-patterns/“code smells”:
- Are the opposite of a design
pattern
- Identify poor solutions to
recurring design problems
- Are symptoms of poor design
choices

The Code Duplication anti-pattern
Problem description:
- Useful pieces of code are
copy-pasted throughout the
codebase
Solution description:
- Use an abstraction technique
(e.g., method, inheritance) to
refactor the code

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

What is the The Schizophrenic Class
anti-pattern?

A

Problem description:
- A class that contains disjoint sets of public
methods that are used by disjoint sets of
client classes
Solution description:
- Refactor each set of methods into
individual classes

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

What is the The Blob anti-pattern?

A

Problem description:
- A large class that is
lacking cohesion or
makes most of the
processing decisions
Solution description:
- Refactor Blob classes
into a series of more
cohesive classes

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

What is the The Data Clump anti-pattern?

A

Problem description:
- Large group of parameters appear
together in the signature of many
operations
Solution description:
- Introduce a new class that encapsulates
the parameter group to simplify the
operations with the data clump

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

What is the The Feature Envy anti-pattern?

A

Problem description:
- A method that manipulates
the data of other classes
more than its own data
Solution description:
- Method was likely misplaced
- Move to class whose data is
manipulated

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

The Tradition Breaker anti-pattern

A

Problem description:
- A class breaks the API inherited from its
superclass by either overriding an inherited
method with an empty method or reducing
the visibility of a method
Solution description:
- Inheritance structure is flawed and needs
to be fixed, because subclass does not
properly substitute its superclass

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

What do you need to keep in mind for testability?

A

More execution paths, more tests!
- The complexity of a method determines
how many tests are required
- More complex methods require more tests

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

What are the testability tips?

A
  • Follow Test-Driven Development (TDD):
    Strict TDD approach:
  • New code may only be written in order to
    make a failing test case pass
  • Hence, tests must exist before the code
    can be written
  • Tests must be written and shown to fail
    before code can be added

Test early and test often
Invest effort in testing:
- As code is updated to add new features or
fix bugs, tests should be kept in sync
- If following strict TDD, tests should be
updated first!
Rely on your safety net!
- Get in the habit of executing tests often

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

What advantages does reusibility have?

A

Code reuse simplifies maintenance:
- Bugs only need to be fixed in one common
location
Code reuse accelerates development
- Less time is spent “reinventing the wheel”

ex:
Program libraries
* Application frameworks
* Architectural patterns
* Service-oriented systems
* Design patterns
* Model-driven engineering
* Program generators

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

What are the reusability tips?

A

Apply design patterns!
Why design patterns:
- Design patterns increase code reuse by
using common abstraction techniques

Follow the DRY principle!
Don’t Repeat Yourself (DRY):
- As much as possible, avoid repeating
yourself when writing code
- Instead, use abstractions (methods,
classes) to reuse solutions rather than
repeating them

Using generics
What is a generic?
- A programming construct to allow types to
vary, while code structure stays constant
- Allows the Java compiler to check for
errors that would usually leak through to
run-time

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

When can programming errors appear?

A

Compile-time:
- Programming errors that an analysis of the
code can reveal
- For example, missing semi-colon
Run-time:
- Mistakes with program logic that are
discovered after the program is launched
- For example, dividing by zero

Generics help us to catch bugs at
compile time

public class Box {
private Object object;
public void set(Object object) {
this.object = object;
}
public Object get() {
return object;
}
}
vs
public class Box<T> {
private T t;
public void set(T t) {
this.t = t;
}
public T get() {
return t;
}
}</T>

17
Q

What are the naming conventions for type parameter?

A

E—Element
- Used extensively by the Java Collections
Framework
K—Key
N—Number
T—Type
V—Value

18
Q

What are the bounds of generics?

A

Generic types cannot be instantiated with
primitive types
- Box<int> // not allowed
- Box<Integer> // allowed
Instances of type parameters cannot be
created:
- E elem = new E(); // not allowed</Integer></int>

Static fields cannot be declared of the
type of a type parameters
public class Box<T> {
private static T t; //not allowed

}</T>

Arrays of parameterized types cannot be
created
Box<Integer>[] boxes =
new Box<Integer>[2]; // not allowed</Integer></Integer>

19
Q

What are the efficiency tips?

A
  1. Avoid recursion where possible!!!