Here is a great article on 15 commandments to Apex best practices, which I think every developer should create as a checklist when writing codes. Do read this as this can transform you from being just a developer to a good developer.
and here is a quick recap of what’s mentioned in the article
- Keep the code simple
- Don’t put queries in loops
- Utilize Map for queries
- Use relationships to reduce queries
- Don’t put DML in loops
- Create only one trigger per object
- Keep logic outside of trigger
- Prefer clicks over code where ever possible
- Aim for 100% code coverage
- Write meaningful tests with asserts
- Write unit tests before developing (i.e test driven development)
- Test all conditions
- Don’t use dummy code coverage
- Never test with existing data
- Don’t introduce extra logic for tests