Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Art of refactoring - Code Smells and Microservices Antipatterns

13 visualizaciones

Publicado el

Refactoring is the process of improving the code without creating new functionality or changing an existing functionality.
Writing simple and avoiding complexity is the key to a good software design, changing the code become easier.
Code smells are undesired patterns that negatively affect software.
A survey about bad smells in Microservices architecture is presented with relevant examples and solutions.

Publicado en: Software
  • Sé el primero en comentar

  • Sé el primero en recomendar esto

Art of refactoring - Code Smells and Microservices Antipatterns

  1. 1. Art Of Refactoring by El Mahdi Benzekri06/2019
  2. 2. Summary • Refactoring for code simplicity • Code smells • Microservices bad smells • Example
  3. 3. Refactoring for code simplicity
  4. 4. Quésaco? • Process of improving code without creating new functionality • Fundamental step of TDD • Fundamental concept in XP
  5. 5. Refactoring for code simplicity • Every code is good until we need to change it • Always write simple code • Simple code = easy to refactor
  6. 6. Refactoring – Why? When? How? • Why? • Technical debt • Dirty code • Lot of bugs • Changes are slow
  7. 7. Refactoring – Why? When? How? • When? • Rule of three • When adding a feature • When fixing a bug • During code review Computer Science is the discipline that believes all problems can be solved with one more layer of indirection. —Dennis DeBruler
  8. 8. Refactoring – Why? When? How? • How? • The code should become cleaner. • New functionality shouldn’t be created during refactoring. • All existing tests must pass after refactoring.
  9. 9. ZENO’s Paradox • Databases • Published interfaces • Refactor vs rebuild • Flexibility vs complexity and cost
  10. 10. Refactoring In Sonar • SonarQube version 5.5 introduces the concept of Code Smell
  11. 11. Large-Scale Automated Refactoring Using ClangMR • https://ai.google/research/pubs/pub41342 • refactor large C++ codebases • combination of the Clang compiler framework and the MapReduce parallel processor
  12. 12. Code smells
  13. 13. Code Smells Psychology: • a piece of code contains some issues VS a piece of code contains some smells, that it is "smelly"
  14. 14. Code Smells – The Dispensables • Comments/duplicate code/dead code • P: uncessary, less clarity • S: Rename Method, Extract Method • Payoff: Simplification + shortness = code that’s easier to simplify and cheaper to support.
  15. 15. Code Smells – The Bloaters • Data Clumps • P: poor program structure • S: Introduce Parameter Object, Preserve Whole Object. • Payoff: Operations on particular data are now gathered in a single place, reduced code size. Warning: undesirable dependency between the classes.
  16. 16. Code Smells – Object-Orientation Abusers • Switch Statements • P: poor program structure • S: Polymorphism, Replace Type Code with State/Strategy, Introduce Null Object. • Payoff: Improved code organization. Ignore when: simple actions, factory method/Abstract factory.
  17. 17. Code Smells – Change Preventers • Data Clumps • P: poor program structure • S: Introduce Parameter Object, Preserve Whole Object. • Payoff: Operations on particular data are now gathered in a single place, reduced code size. Warning: undesirable dependency between the classes.
  18. 18. Code Smells – Couplers • Feature Envy • P: A method accesses the data of another object more than it’s own. • S: Move Method, Extract Method, Move Field. • Payoff: Less code duplication, higher cohesion. Warning: intentionnally keeping data away, e.g : Strategy, Visitor...
  19. 19. Refactoring and Performance • != school of thought that ignores performance in favor of design purity or in hopes of faster hardware. • If you optimize all the code equally, you end up with 90 percent of the optimizations wasted • Profiling ensures you focus that time on the right place
  20. 20. Microservices Bad Smells
  21. 21. Microservice Bad Smells - Survey • Microservice Smells: indicators of situations—such as undesired patterns, antipatterns, or bad practices—that negatively affect software quality attributes such as understandability, testability, extensibility, reusability, and maintainability of the system under development. • Interviewed 72 experienced developers • Duration of the survey: two years • Detected 11 bad smells
  22. 22. Microservice Bad Smells - Survey results • Very harmful: • Wrong Cuts, Hard-Coded Endpoints, and Shared Persistency • Difficult to remove: • Wrong Cuts, Microservice Greedy, and Too Many Standards
  23. 23. Microservice Bad Smells - Why • lack of experience • most problems in the early stage (6 months to year) • Architecture & Design issues, e.g ESB
  24. 24. Wrong Cuts • Desc: wrong split • Problem: wrong separation of concerns and increased data-splitting complexity • Solution: clear analysis of business, DDD
  25. 25. Hard-Coded Endpoints • Desc: Hardcoded IP addresses and ports • Problem: locations need to be changed • Solution: service discovery
  26. 26. Shared Persistency • Desc: same relational database or worst same entities • Problem: reducing team and service independence • Solution: private database or private schema
  27. 27. Microservice Greedy • Desc: needless microservices • Problem: useless huge system that will easily become unmaintainable • Solution: clear analysis of the need, DDD
  28. 28. Too Many Standards • Desc: many development languages, protocols, frameworks.. • Problem: lot of required skills, developer turnover.. • Solution: use carefully, don’t follow the latest hype.
  29. 29. Example https://github.com/emilybache/GildedRose-Refactoring-Kata
  30. 30. References • Refactoring: Improving the Design of Existing Code - Book • Microservices AntiPatterns and Pitfalls - Book • On the Definition of Microservice Bad Smells – Research • Refactoring: Improving the Design of Existing Code – Book • https://refactoring.guru

×