We spend more time reading our code than writing it. So doesn’t it make sense that our code is clean, precise, and easy to read? In this session, we discuss how to take a code written in a hurry and apply best practices to refactor it. Join us to learn about how to write Clean Code in Salesforce. We will take a messy piece of code step by step and refactor it.
Why do we need Clean code in Salesforce?
Why do we need clean code? Bad code works too! Don’t fix what is not broken. Let’s understand why we need it in Salesforce.
Best practices to write clean code in Salesforce
Follow the below best practices to write good code in Salesforce.
- Easy to understand by other developers : readable by developers other than the one who developed it.
- Easy to maintain : lower chances of accidentally introducing bugs
- Modified without fear of breaking anything : Lot of developers take great pride in making the code compact – trying to do multiple things on one line – which might be impressive, but makes the code much harder to read and understand
Rules to write Clean Code
- Keep your methods short
- Don’t repeat yourself
- Methods should do just one thing
- Clear, intention revealing names
- Comment to clarify not explain
- Leave everything better than you found it.
Please check this post to learn about Salesforce Naming Conventions Best Practices.
Agreed upon software standards
- Naming conventions
- White space
- Curly Braces – Cuddled or not
- Commit to keeping code clean as a team
- Hold Code reviews to enforce standards
Check the below recording to learn more with Examples.
Best practice and considerations
- Salesforce Naming Conventions Best Practices
- Putting comments in code: the good, the bad, and the ugly.
- Ottinger’s rules for variables and class names
- Curly Braces: To Cuddle or Not
- Kent Beck’s Software Design Rules
Please Subscribe to our YouTube channel to get notification for upcoming recording.