Code Smells Flashcards
Why shouldn’t you use ‘Comments’? ( 3 points )
- Communication.
It’s hard to understand and read the code if comments have another meaning than a method - Flexibility.
It’s hard to support and change( Every time when you update the code you should also update the comment ) - Duplication.
You don’t need to write the same comment if your method name has already explained it.
When can we use ‘Comments’? ( 3 points )
- Explain difficult algorithm
- For some automation tolls ( annotate for example )
- To get the link to the guide which explains core behavior
Why shouldn’t we use ‘Long methods’? ( 2 )
- Flexibility
The long method contains too many responsibilities, that’s why it won’t be flexible for change. - Testability
It may be difficult to set up all initial behavior and test it.
Why shouldn’t we use ‘Long class/modules? ( 2 )
- Flexibility
Too many responsibilities and hard to change - Testability
Hard to test. We need to create too many setups before tests running.
Why shouldn’t we use ‘Long parameter list’?
- Simplicity
It tells us that the method tries to do too much and we should try to group params as an object together. - Flexibility
If we add new params, we need to update all invoke of the method. It’s not flexible - Communication
You should remember lot’s of things
What is ‘embedded in name’ smell?
When you add unnecessary value to the name:
- add_course(course)
When you add type to the name
- animal_string
What is ‘uncommunicative name’ smell?
When you use:
- One or two-character names
- Misleading names
- abbreviations
What is ‘Inconsistent name’ smell?
One name is used in one place, and a different name is used for the same thing somewhere else. For example, in a single application you might see add, store, put, and place for the same basic method.
Sample: ‘Destroy, delete, remove for the same method;’
What is ‘Dead code’ smell?
A variable, parameter, code fragment, method, module, or class is not used anywhere (perhaps other than in tests).
Why should we remove ‘Dead code’?
- Size( adds to the application’s size, and thus to the amount of code that must be understood by developers and maintainers)
- Communication ( hard to understand intentions)
- Flexibility (It’s stupid to support unused code)
What is ‘Speculative generality’ code smell?
The same as You ain’t gonna need it
This code smell describes a situation where people develop a class with all sorts of hooks and special cases just so it will handle things that might be required in the future but not at this stage
What is ‘Greedy Method’ code smell?
When code do more than one job or have several levels of abstraction. ( More than one responsibility )
What is ‘Procedural code’ smell?
Don’t use procedural code ( like loop, while with temp variables) if you can use each
What is ‘Dynamic code creation’ code smell?
Don’t use eval
What is Derived Value
code smell?
When you have code which was defined from scratch instead of getting from another value:
NAME = ‘Nic’
SURNAME = ‘Mil’
FULL_NAME = ‘Nic Mil’
But we can leave this code smell for the tests.