● Increase Maintainability == Reduce maintenance cost ● Reduce onboarding time for new developer ● Reduce tech debt ● Reduce time to add or modify existing features ● Happy developer
Meaningful Names for Variables, Methods, Classes, Arguments ● Should be sufficient enough to understand the purpose or context ● One should not have to read the whole code to figure out what a function does or what a class represents or to understand why a variable exists ● No need comments
Other naming best practices ● Name functions as verbs. Ex: save, create, deductBalance ● Name classes as nouns. Ex: User, UserController ● Use pronounceable names. Ex: modificationTimestamp, isActive, createAndSave
Do we need comments? ● No. Your code should be self explain ● Only put comment if necessary ○ Some trade off ○ Deprecation warning ○ What point or process needs to be aware
DRY - Don’t Repeat Yourself “Every piece of knowledge must have a single, unambiguous, authoritative representation within a system” ● Actually duplication is fine* ● Extract part of code that can be reused to a class or function
YAGNI - You Aren't Gonna Need It ● “Maybe we need use that in the future” ● Only code what you need to build ● Avoid adding unnecessary dependencies or complexity ● Leads to over engineering
Design Pattern & System Design ● Understanding design patterns can help us to make decision with our code ○ Creational pattern ○ Structural pattern ○ Behavioral pattern ● Understanding system design to prevent tech debt or over engineering ○ Monolith Design ○ Domain Driven Design ○ Microservices ○ Architectural Pattern
● Do not judge it ● Understand how it runs ● Understand the structure & pattern ● Understand the business context ● Raise your empathy ● Leave better than you found it
Working on new or modifying features ● Follow current structure with better approach ● Plan and communicate if you are proposing approach that might totally different with current structure ● Add unit tests or automated tests if possible ● Do pair programming or code review ● Done is better than perfect
Clean Code is a Journey ● Remember, your first code must be awful. Keep practice ● Learn design patterns and system designs ● Get more insight, find mentor or developer fellows, contribute to open source