I am new to your blog and have really enjoyed taking my knowledge beyond the declarative skill set I used to have.
As we grow to learn how to code in Apex, without a pure coding background, I am ever mindful that the code I am creating performs correctly, efficiently and wont be laughed out of town if ever viewed by seasoned coder.
Therefore what are your top tips for coding best practice to ensure the code looks and performs just right?
Thanks a lot,
Best Practice Bob
Dear Best Practice Bob,
This is the type of question that many great coders ask themselves every day! A good coder always asks him or herself how they can write better, more efficient, scalable code.
A few tips here for you:
1. Read a lot of code! The key here is recognizing the patterns that are riddled in almost every block of code you’ll find. Luckily, there are tons of Apex code samples across StackExchange, YouTube, AppExchange un-managed packages, Github, etc. Keep an open mind!
2. Minimize lines of code. This can be a good indication of how simple and understandable your code is, especially for newer coders. There are tons of objects/functions in Apex that’ll make your life easier – most people just aren’t aware of them. There’s too many to teach however so a good coder will proactively discover these tools just like an Excel user might search to see if there’s a Standard Deviation function before attempting to calculate it manually.
3. Write a lot of comments in your code! Many lines of code dedicated to comments is a good thing! The truth is, 10 master programmers might all code a simple program very differently. As long as the next person reading your code doesn’t get out of this world confused, your code is likely good enough. Comments will go a long way to helping others understand what you’re trying to do, and worst case scenario, your comments will make it easier for others to give you tips!
4. Google everything! Most people don’t realize that ~70% of code that a great coder writes is plagiarized from the internet. Why reinvent the wheel when someone else has already written it better and put it up online! Make sure to brush up on advanced Google search methods too!
5. Stay tuned for my next post!
Hope this helps!
Join the discussion in the comments section below! Got a question? Send it to the mailbag: email@example.com