SlideShare une entreprise Scribd logo
1  sur  32
Télécharger pour lire hors ligne
JAX Mainz
09.05.2017
Andreas Günzel
Kenne deinen Feind
Top 10 der täglichen Anti-Patterns
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 2
Meine Person
Andreas Günzel
Team Manager Java Enterprise Solutions
EXXETA AG
@leichtundkross
Andreas.Guenzel@EXXETA.com
www.EXXETA.com
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 3
Wer ist eigentlich unser Feind?
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 4
Big Hairy Object
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 5
Testabdeckung
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 6
Testabdeckung
public class Calculator {
public int mode(int a[]) {
int maxValue = 0, maxCount = 0;
for (int i = 0; i < a.length; ++i) {
int count = 0;
for (int j = 0; j < a.length; ++j) {
if (a[j] == a[i])
++count;
}
if (count > maxCount) {
maxCount = count;
maxValue = a[i];
}
}
return maxValue;
}
}
Zyklomatische
Komplexitat: 5
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 7
Testabdeckung
public class Calculator {
public int mode(int a[]) {
int maxValue = 0, maxCount = 0;
for (int i = 0; i < a.length; ++i) {
int count = 0;
if (count > maxCount) {
maxCount = count;
maxValue = a[i];
}
}
return maxValue;
}
}
Zyklomatische
Komplexitat: 3
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 8
Testabdeckung
public class Calculator {
public int mode(int a[]) {
int maxValue = 0, maxCount = 0;
int count = 0;
if (count > maxCount) {
maxCount = count;
maxValue = a[i];
}
return maxValue;
}
}
Zyklomatische
Komplexitat: 2
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 9
Testabdeckung
public class Calculator {
public int mode(int a[]) {
int maxValue = 0, maxCount = 0;
return maxValue;
}
}
Zyklomatische
Komplexitat: 1
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 10
Testabdeckung
public abstract class Calculator {
public abstract int mode(int a[]);
}
Zyklomatische
Komplexitat: ?
100% Testabdeckung ist nicht realisierbar!!
Test GOs
• Definition ab wann ein Test Pflicht ist (DoD)
• Test Coverage lokal prüfen (EclEmma)
• Arrange – Act – Assert
Test No-GOs
• Lange Testlaufzeiten
• Tests ignorieren (@Ignore)
• // Tests auskommentieren
• Tests löschen
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 11
Testabdeckung
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 12
Shotgun Surgery
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 13
Maven Dependencies
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 14
“If all you have is a hammer, everything looks like a nail.”
Golden Hammer
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 15
“Nothing good happens after 2:00 a.m.”
public Date getDefaultDate() {
String date = "0001-01-01";
String[] cal = date.split("-");
int year = Integer.parseInt(cal[0]);
int month = Integer.parseInt(cal[1]) - 1;
int day = Integer.parseInt(cal[2]);
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DATE, day);
DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date defaultdate = null;
try {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
defaultdate = formatter.parse(format.format(calendar.getTimeInMillis()));
} catch (ParseException e) {
}
return defaultdate;
}
return new GregorianCalendar(0, 0, 1)
.getTime();
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 16
Onion Pattern
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 17
Mikro Optimierungen
Nano Optimierungen
Piko Optimierungen
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 18
Mikro Optimierungen
if (counter < X || getXYZ()) {
// ...
}
if (getXYZ() || counter < X) {
// ...
}
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 19
Mikro Optimierungen
StringBuilder sb = new StringBuilder();
sb.append("Hello").append(" ").append("World");
return sb.toString();
String s = "Hello" + " " + "World";
return s;
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 20
Mikro Optimierungen
if (x > -1) {
// ...
}
if (x >= 0) {
// ...
}
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 21
Mikro Optimierungen
if (value != null) {
// ..
}
if (null != value) {
// ..
}
Was sind die tatsächlichen Probleme?
Datenbank
• Fehlender oder falscher Index
• Schlechter SQL Query
• Konfiguration (Connection Pools, Partitionierung, …)
Datenübertragung
• Große Datenmengen
• Zu viele Requests
• Schlechte (keine) Request Timeouts
Logging
GC, Thread Pools, …
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 22
Code Optimierung
Wann sollte der Code optimiert werden?
Informatik ist keine Wissenschaft der Konjunktive!
Optimiere Schrittweise
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 23
Code Optimierung
“The First Rule of Program Optimisation: Don't do it.
The Second Rule of Program Optimisation (for experts only!): Don't do it yet.”
Michael A. Jackson
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 24
Object Orgy
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 25
Kollaboration
AKA wie mache ich es meinen Mitmenschen besonders schwer
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 26
Kollaboration
„Removed unused imports“
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 27
Kollaboration
„Renamed column in database“
Coding Conventions fangen bereits bei der Formatierung an
Einheitliche Code Formatierung…
• führt zu leichter lesbaren Code
• reduziert Merge Aufwände erheblich
• verbessert die Wartbarkeit von Software
Lösungsansätze
• Wiki Dokumentation
• Konfigurationsdatei
• Vorkonfigurierte IDE Distribution
• IDE unabhängige Ansätze
→Maven Plugin
→SCM Hook
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 28
Kollaboration
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 29
Warm Body
1. Read the Error Message
2. Seriously, Read the Error Message!
3. Check your notes of previously solved
problems
4. Google the “error you are getting”
5. Read the results you find
6. Seriously, read the results!
7. Ask your rubber duck
8. Ask a peer
9. Ask an expert
10.Record your solution
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 30
Stuck in the Muck
https://8thlight.com/blog/doug-bradbury/2013/10/08/stuck-in-the-muck.html
11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 31
Big Ball of Mud
“Everyone has a plan until they get punched in the mouth”
Mike Tyson
EXXETA AG
Albert-Nestler-Straße 19
76131 Karlsruhe
tel +49 721 50994-5000
e-mail info@EXXETA.com
EXXETA.com
EXXETA Standorte
Karlsruhe | Berlin | Bratislava | Frankfurt | Leipzig | Mannheim | München | Stuttgart | Zürich
I think we could build a better one.
William Boeing

Contenu connexe

En vedette

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

En vedette (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

Kenne deinen Feind - Top 10 der täglichen Anti-Patterns

  • 1. JAX Mainz 09.05.2017 Andreas Günzel Kenne deinen Feind Top 10 der täglichen Anti-Patterns
  • 2. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 2 Meine Person Andreas Günzel Team Manager Java Enterprise Solutions EXXETA AG @leichtundkross Andreas.Guenzel@EXXETA.com www.EXXETA.com
  • 3. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 3 Wer ist eigentlich unser Feind?
  • 4. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 4 Big Hairy Object
  • 5. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 5 Testabdeckung
  • 6. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 6 Testabdeckung public class Calculator { public int mode(int a[]) { int maxValue = 0, maxCount = 0; for (int i = 0; i < a.length; ++i) { int count = 0; for (int j = 0; j < a.length; ++j) { if (a[j] == a[i]) ++count; } if (count > maxCount) { maxCount = count; maxValue = a[i]; } } return maxValue; } } Zyklomatische Komplexitat: 5
  • 7. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 7 Testabdeckung public class Calculator { public int mode(int a[]) { int maxValue = 0, maxCount = 0; for (int i = 0; i < a.length; ++i) { int count = 0; if (count > maxCount) { maxCount = count; maxValue = a[i]; } } return maxValue; } } Zyklomatische Komplexitat: 3
  • 8. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 8 Testabdeckung public class Calculator { public int mode(int a[]) { int maxValue = 0, maxCount = 0; int count = 0; if (count > maxCount) { maxCount = count; maxValue = a[i]; } return maxValue; } } Zyklomatische Komplexitat: 2
  • 9. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 9 Testabdeckung public class Calculator { public int mode(int a[]) { int maxValue = 0, maxCount = 0; return maxValue; } } Zyklomatische Komplexitat: 1
  • 10. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 10 Testabdeckung public abstract class Calculator { public abstract int mode(int a[]); } Zyklomatische Komplexitat: ?
  • 11. 100% Testabdeckung ist nicht realisierbar!! Test GOs • Definition ab wann ein Test Pflicht ist (DoD) • Test Coverage lokal prüfen (EclEmma) • Arrange – Act – Assert Test No-GOs • Lange Testlaufzeiten • Tests ignorieren (@Ignore) • // Tests auskommentieren • Tests löschen 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 11 Testabdeckung
  • 12. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 12 Shotgun Surgery
  • 13. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 13 Maven Dependencies
  • 14. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 14 “If all you have is a hammer, everything looks like a nail.” Golden Hammer
  • 15. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 15 “Nothing good happens after 2:00 a.m.” public Date getDefaultDate() { String date = "0001-01-01"; String[] cal = date.split("-"); int year = Integer.parseInt(cal[0]); int month = Integer.parseInt(cal[1]) - 1; int day = Integer.parseInt(cal[2]); Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DATE, day); DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date defaultdate = null; try { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); defaultdate = formatter.parse(format.format(calendar.getTimeInMillis())); } catch (ParseException e) { } return defaultdate; } return new GregorianCalendar(0, 0, 1) .getTime();
  • 16. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 16 Onion Pattern
  • 17. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 17 Mikro Optimierungen Nano Optimierungen Piko Optimierungen
  • 18. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 18 Mikro Optimierungen if (counter < X || getXYZ()) { // ... } if (getXYZ() || counter < X) { // ... }
  • 19. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 19 Mikro Optimierungen StringBuilder sb = new StringBuilder(); sb.append("Hello").append(" ").append("World"); return sb.toString(); String s = "Hello" + " " + "World"; return s;
  • 20. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 20 Mikro Optimierungen if (x > -1) { // ... } if (x >= 0) { // ... }
  • 21. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 21 Mikro Optimierungen if (value != null) { // .. } if (null != value) { // .. }
  • 22. Was sind die tatsächlichen Probleme? Datenbank • Fehlender oder falscher Index • Schlechter SQL Query • Konfiguration (Connection Pools, Partitionierung, …) Datenübertragung • Große Datenmengen • Zu viele Requests • Schlechte (keine) Request Timeouts Logging GC, Thread Pools, … 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 22 Code Optimierung
  • 23. Wann sollte der Code optimiert werden? Informatik ist keine Wissenschaft der Konjunktive! Optimiere Schrittweise 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 23 Code Optimierung “The First Rule of Program Optimisation: Don't do it. The Second Rule of Program Optimisation (for experts only!): Don't do it yet.” Michael A. Jackson
  • 24. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 24 Object Orgy
  • 25. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 25 Kollaboration AKA wie mache ich es meinen Mitmenschen besonders schwer
  • 26. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 26 Kollaboration „Removed unused imports“
  • 27. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 27 Kollaboration „Renamed column in database“
  • 28. Coding Conventions fangen bereits bei der Formatierung an Einheitliche Code Formatierung… • führt zu leichter lesbaren Code • reduziert Merge Aufwände erheblich • verbessert die Wartbarkeit von Software Lösungsansätze • Wiki Dokumentation • Konfigurationsdatei • Vorkonfigurierte IDE Distribution • IDE unabhängige Ansätze →Maven Plugin →SCM Hook 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 28 Kollaboration
  • 29. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 29 Warm Body
  • 30. 1. Read the Error Message 2. Seriously, Read the Error Message! 3. Check your notes of previously solved problems 4. Google the “error you are getting” 5. Read the results you find 6. Seriously, read the results! 7. Ask your rubber duck 8. Ask a peer 9. Ask an expert 10.Record your solution 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 30 Stuck in the Muck https://8thlight.com/blog/doug-bradbury/2013/10/08/stuck-in-the-muck.html
  • 31. 11.05.2017 Kenne deinen Feind – täglichen Anti-Patterns 31 Big Ball of Mud “Everyone has a plan until they get punched in the mouth” Mike Tyson
  • 32. EXXETA AG Albert-Nestler-Straße 19 76131 Karlsruhe tel +49 721 50994-5000 e-mail info@EXXETA.com EXXETA.com EXXETA Standorte Karlsruhe | Berlin | Bratislava | Frankfurt | Leipzig | Mannheim | München | Stuttgart | Zürich I think we could build a better one. William Boeing