Why your code sucks and how to fix it

1,248 views

Published on

We all "know" how to setup a new project architecture. The real challenge is in fixing the existing one. The presentation is going to show us how to clean and organize our existing project's code into patterns with a sequence of low-level refactorings.
We are going to learn to:
- Identify the best candidates for refactor;
- Improve the design of the existing code - with solution to recurring design problems;
- To refactor or not to refactor to a pattern
- Become a better software engineers by making important changes safely and effectively;

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,248
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Why your code sucks and how to fix it

  1. 1. Why your code sucks and how to fix it Marjan Nikolovski Senior Software Engineer, Seavus Co-Owner, EmitKnowledgeemitknowledge.com/@mnikolovskimk.linkedin.com/in/marjannikolovski
  2. 2. AgendaRefactoring: Why, WhenWhy your code sucksHow to fix itRefactoring cheat list
  3. 3. RefactoringA change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior
  4. 4. Why refactoring – Technical factorsMake your code easier to understandMake it easier to add new codeImprove the design of the codebaseRemove unused codeBetter understanding of your codebaseEvolve your architecture instead of over engineering it
  5. 5. Why refactoring – Psychological factorsLearn to embrace the changeRefactors are result of code reviews. Accept that sometimes your code sucks !Loose your fear to change existing codebase
  6. 6. When to refactorAdd new functionality – Refactor existing code to make the change with easeFind bugs – Refactor to understand the codeCode reviews – Immediate results of the code reviewEnd of a development iteration – Fix what is shitty
  7. 7. Why your code sucks Your code sucks if it doesnt work Your code sucks if it isnt testable Your code sucks if its hard to read Your code sucks if its not understandable Your code sucks if overuse a trendy framework at the cost of following good design/implementation practices Your code sucks if it has duplication Your code sucks if your function names suck Your code sucks if your variable names suck Your code sucks if your class names suck Your code sucks if your abstractions suck Your code sucks if a method is larger than the screen Your code sucks if you are reusing variables Your code sucks if you need to use comments to explain the code Your code sucks if an exceptions stack trace doesnt return the original problem
  8. 8. Your code sucks if it doesnt work
  9. 9. Your code sucks if it isnt testable
  10. 10. Your code sucks if its hard to read
  11. 11. Your code sucks if its not understandable
  12. 12. Your code sucks if overuse a trendy framework at the cost of followinggood design/implementation practices
  13. 13. Your code sucks if it has duplication
  14. 14. Your code sucks if your function names suck
  15. 15. Your code sucks if your variable names suck
  16. 16. Your code sucks if your class names suck
  17. 17. Your code sucks if your abstractions suck
  18. 18. Your code sucks if a method is larger than the screen
  19. 19. Your code sucks if you are reusing variables
  20. 20. Your code sucks if you need to use comments to explain the code
  21. 21. Your code sucks if an exceptions stack trace doesnt return the original problem
  22. 22. How to fix itDuplicated codeLong methodPrimitive obsessionSwitch statementsLong Parameter List
  23. 23. Duplicate codeCreate a new common methodUse inheritanceUse template methods
  24. 24. Create a new common method
  25. 25. Use inheritance
  26. 26. Use template methods
  27. 27. Long methodUse extract to methodMinimize code nesting to maximum 1 level with method extractionExtract each iteration as a methodExtract multiple conditions as method
  28. 28. Long method
  29. 29. Primitive obsessionOveruse of primitive types in classes instead of creating domain entitiesReplace primitives with classes
  30. 30. Primitive obsession
  31. 31. Switch statementsUse command pattern to replace switch logic
  32. 32. Long Parameter ListReplace long param list with a class
  33. 33. Refactoring cheat list Replace Conditional with Polymorphism Remove Double Negative Replace Nested Conditional with Guard Clauses Reverse Conditional Replace Magic Number with Symbolic Constant Replace Exception with Test Encapsulate Downcast Consolidate Duplicate Conditional Fragments Consolidate Conditional Expression
  34. 34. Replace Conditional withPolymorphism
  35. 35. Remove Double Negative
  36. 36. Reverse Conditional
  37. 37. Replace Nested Conditional with Guard Clauses
  38. 38. Replace Magic Number with Symbolic Constant
  39. 39. Replace Exception with Test
  40. 40. Encapsulate Downcast
  41. 41. Consolidate Duplicate Conditional Fragments
  42. 42. Consolidate Conditional Expression
  43. 43. Questions?• Complete electronic evaluation forms on the computers in the hall and enter to win! – Telerik Ultimate Collection – CodeSmith Tools Generator Pro Personal – JetBrains ReSharper – Seavus EDC training vouchers – Pluralsight subscriptions – and many more…

×