Over the last few decades we've been bombed with anti-pattern warnings carrying ear-appealing neologisms, such as Primitive Obsession, Object Orgy and Feature Envy. This phenomenon is making us live in a constant fear of life-threatening situations. In the act of self-preservation we don't only avoid anti-patterns, but we make sure we drive away from them as far as we possibly could. However, this is 2016 and a lot has changed. Maybe we drove away a bit too far. Let's start an anti movement: anti anti-patterns. In this talk we motivate our theory that some code smells can now safely be reinterpreted and become the astonishing scent of a fabulous ripe cheese.
2. @nickvdh @Hypernation#Devoxx #junior2professional
Anti anti patterns
Nick : The professional with several successful projects
Jeroen : The anti pattern advocate whose project just failed
All code samples are modifications of real code
3. @nickvdh @Hypernation#Devoxx #junior2professional
Anti anti patterns
Nick : The professional with several successful projects
Jeroen : The anti pattern advocate whose project just failed
All code samples are modifications of real code
4. @nickvdh @Hypernation#Devoxx #junior2professional
Big ball of mud
● To avoid this
○ 256 maven modules
○ 6 levels of poms
○ Every bounded context has
■ An Api
■ An enum module
■ A build module
■ A domain module
■ A ...
11. @nickvdh @Hypernation#Devoxx #junior2professional
Blind faith
The crazy blind typer
● Even better is to not write the lines yourself
○ Testing is important
○ Test first is even better
○ Don’t overdo it
@Getter
@Builder
@ToString
@EqualsAndHashCode
@AllArgsConstructor
public class Option {
private String label;
private Boolean active;
}
13. @nickvdh @Hypernation#Devoxx #junior2professional
Diaper pattern
Diaper Genie
● Right handling on the right level
● Frameworks can help you (spring)
● In some cases, just let it go
@Override
@SneakyThrows
public Result <T> find(String id) {
List<Account> accounts = repository.find(id);
return accounts;
}
15. @nickvdh @Hypernation#Devoxx #junior2professional
Nih (Not Invented Here)
The Boiler Plater
● business value > boilerplate
○ A custom annotation is not a crime
○ Reflection is not evil, but use it wisely
○ Aspects can help you out
16. @nickvdh @Hypernation#Devoxx #junior2professional
Base bean
No god classes on my watch
public class SomeImportantIntegrationTest{
@Rule
public ApplicationLoadingRule applicationRule = new ApplicationLoadingRule ();
@Rule
public RestServiceStubRule restStubRule = new RestServiceStubRule();
@Rule
public DataSourceCreatingRule datasourceRule = new DataSourceCreatingRule();
@Rule
public DataPreparationRule cleanRule = new DataPreparationRule();
@Rule
public DataCreationRule dataRule = new DataCreationRule();
@Rule
public MakeItAllWorkRule workRule = new MakeItAllWorkRule();
18. @nickvdh @Hypernation#Devoxx #junior2professional
KISS
● Your code should focus on business value anyway
● Anti patterns are not a silver bullet
● As with normal patterns use it wisely
● Let frameworks help you out
● Refactor at the right time
19. @nickvdh @Hypernation#Devoxx #junior2professional
KISS
The anti pattern troll
● Your code should focus on business value anyway.
● Anti patterns are not a silver bullet.
● As with normal patterns use it wisely.
● Let frameworks help you out
● Refactor at the right time