java clean code - sergeyzolotukhin/learn-java-gradle GitHub Wiki
Object pass/return to/form method
advantages
disadvantages
ClassCastException
summary:
if you're using a statically typed language, object should be avoided.
Map key String
advantages
String is human readable
disadvantages
Strings are easy to mistype/misspell.
String have lower and upper case
summary:
string should be avoided as the key to a function/dictionary.
Use DTO
advantages
disadvantages
Use Map
advantages
disadvantages
DTO or Map
summary:
If the format of your incoming data is fixed (ie always has the same data items), you use a DTO.
This allows to fail fast if the expected format is not matched.
If the incoming data has variable entries, you can use a map.
Hard coding vs configuration file
SIMPLICITY VS AGILITY is a classic dilemma.
CONFIGURATION HELL - In an extreme case, you might end up having tens or even hundreds of configurable parameters,
which make it utterly hard to maintain the application.
summary:
Make hard-coding your default choice
YAGNI - You aren’t gonna need it
YAGNI stands for "You aren’t gonna need it" and basically means that you shouldn’t do anything that is not needed right now,
While this approach is an advisable way to develop an in-house software, you shouldn’t adhere to it with library development.
With library development, you should always think at least a little bit ahead of current needs
We use frameworks, libraries, solutions, design patterns, etc. that worked well for others,
without understanding why we do so, or how said technologies exactly work.
Hard coding - antipattern
Hard coding is the unfortunate practice in which we store configuration or input data, such as a file path or a remote host name,
in the source code rather than obtaining it from a configuration file, a database, a user input, or another external source.
The main problem with hard code is that it only works properly in a certain environment,
and at any time the conditions change, we need to modify the source code, usually in multiple separate places.
soft coding - antipattern
In soft coding, we put things that should be in the source code into external sources
In extreme cases, a soft coded program can become so abstract and convoluted
that it is almost impossible to comprehend it, and extremely hard to maintain and debug.
final local variable
pros
if we have a long method and we don't use the file keyword then we need to check do we change it or not manualy.