Lecture 12 Flashcards
Which two types of quality are there?
internal quality and external quality
What is external quality?
The user experience, quality from the perspective of the user
Which two things influence external quality the most?
No crashes, good performance
What is internal quality
The quality from the developer perspective
Which three things influence internal quality the most?
How understandable the code is, if the code is easy to change and whether the code is testable.
What are 6 basic rules for having high quality code?
- LOC per method rule
- Duplicated code rule
- CC rule
- Rule of parameter list length
- Code Style rule
- Testing rule
What is the LOC per method rule?
The LOC per method rule is that a method should never have more than 40 lines of code, and that if a code has more than 20 lines of code you should review it and consider to change the method. (THESE NUMBERS ARE JAVA)
What is the duplicated code rule?
Never duplicate code, if you need code twice, put it in a method that you can call from multiple places.
What does CC in the CC rule stand for?
Cyclomatic Complexity
How do you calculate the CC of a piece of code?
Counting all conditions and adding 1 (conditions: if, while, for et.c).
What is the CC rule
the rule that a method should not have a Cyclomatic complexity higher than 10, if it is above 5 you should review the method and consider changing it / splitting it up.
What is the rule of parameter list length
The rule that a method should in general not have more parameters than 4.
What is the code style rule?
The code style rule states that you should follow code conventions
What are the 4 conventions of the code style rule?
indentation, whitespace, naming, documentation
What is the test rule?
The test rule states that the amount of unit tests you have for a method should be greater than or equal to the CC of the method.
How do you call the things that split tokens in a inputStream / string
delimiters
What is autoboxing?
Autoboxing is when a primitive data type is changed into a reference data type, because this is necessary for e.g. generics.
What are generics?
Generics are things that the Java compiler sees as “objects” and for which instances of multiple classes can be used.
What are wrapper classes? Give an example of a wrapper class
Wrapper classes are classes that function like the primitive types, but are reference data types. e.g. Integer, Character
Why would you use generics?
To create methods or classes that work with different types of objects (e.g. a NumberList with methods that work both for integers and floating-point number)
How can we use generics?
By using (less-than-bracket) and (greater-than-bracket) in either a class signature or a method signature to specify that we are using generics.
Can we specify generics? How?
Yes, we can specify generics so that only instances of certain classes, and not all classes are excepted. We can do this by adding extends InsertHere to the generic in the signature.