Your SlideShare is downloading. ×
Why your code sucks and how to fix it
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Why your code sucks and how to fix it

775

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 …

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
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
775
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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. AgendaRefactoring: Why, WhenWhy your code sucksHow to fix itRefactoring cheat list
  • 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. 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. 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. 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. 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. Your code sucks if it doesnt work
  • 9. Your code sucks if it isnt testable
  • 10. Your code sucks if its hard to read
  • 11. Your code sucks if its not understandable
  • 12. Your code sucks if overuse a trendy framework at the cost of followinggood design/implementation practices
  • 13. Your code sucks if it has duplication
  • 14. Your code sucks if your function names suck
  • 15. Your code sucks if your variable names suck
  • 16. Your code sucks if your class names suck
  • 17. Your code sucks if your abstractions suck
  • 18. Your code sucks if a method is larger than the screen
  • 19. Your code sucks if you are reusing variables
  • 20. Your code sucks if you need to use comments to explain the code
  • 21. Your code sucks if an exceptions stack trace doesnt return the original problem
  • 22. How to fix itDuplicated codeLong methodPrimitive obsessionSwitch statementsLong Parameter List
  • 23. Duplicate codeCreate a new common methodUse inheritanceUse template methods
  • 24. Create a new common method
  • 25. Use inheritance
  • 26. Use template methods
  • 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. Long method
  • 29. Primitive obsessionOveruse of primitive types in classes instead of creating domain entitiesReplace primitives with classes
  • 30. Primitive obsession
  • 31. Switch statementsUse command pattern to replace switch logic
  • 32. Long Parameter ListReplace long param list with a class
  • 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. Replace Conditional withPolymorphism
  • 35. Remove Double Negative
  • 36. Reverse Conditional
  • 37. Replace Nested Conditional with Guard Clauses
  • 38. Replace Magic Number with Symbolic Constant
  • 39. Replace Exception with Test
  • 40. Encapsulate Downcast
  • 41. Consolidate Duplicate Conditional Fragments
  • 42. Consolidate Conditional Expression
  • 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…

×