Implementation best practices Flashcards
What is implementation?
Implementation:
- Writing the source code that is needed
to realize the architecture and design
- Comes with its own set of challenges
How to manage the implementation process
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
What is the key implementation concepts?
- 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
Name the understandability tips!
- Use meaningful identifier names!
- 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.: - Follow a coding style convention!
What is the NASA JPL coding standard for
Java?
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
What is a design anti-pattern?
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
What is the The Schizophrenic Class
anti-pattern?
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
What is the The Blob anti-pattern?
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
What is the The Data Clump anti-pattern?
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
What is the The Feature Envy anti-pattern?
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
The Tradition Breaker anti-pattern
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
What do you need to keep in mind for testability?
More execution paths, more tests!
- The complexity of a method determines
how many tests are required
- More complex methods require more tests
What are the testability tips?
- 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
What advantages does reusibility have?
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
What are the reusability tips?
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