Has anyone written an Apex or VisualForce code style guide, in the way of the Ruby Style Guide or jslint, or PEP-8, or any number of Java guides? I'm in the process on creating one for internal use but would love to base it off existing work, either by SFDC or a colleague.

In an ideal world, MavensMate and Eclipse can use the style guide for linting, but I'm happy with simply a programmer-readable textual version.

If no one has one and is considering employing one, would anyone be interested in collaborating?

up vote 14 down vote accepted

Okay, no one has responded with anything real, so I'm posting this answer.

I started on this style guide months ago, made it open source. I finally got it to v0.1.

The Apex guide is based on Google's Java style guide as mentioned by Peter Knolle.

The Visualforce styleguide does not yet exist.

The Salesforce admin style guide also does not yet exist.

The ant migration styleguide does not exist, but I'm not sure it ought to.

Are there other aspects that I should consider?

Please start forking, making pull requests and help out!

  • 5
    Nice start. One thing I'd like to mention. SFDC being an online platform counts whitespaces. Your indentation of 2 spaces literally uses double the space if you used tabs. Over a lot of code this really adds up. Normally I'd agree over the 2 space (or other arbitrary spaces #) but not on this platform. My old company I worked for agreed that for this reason tabs is far superior and I also brought this belief into my current company. You don't have to agree but I wanted to make sure the character count was something you thought about and were aware of. – dphil Nov 3 '14 at 18:16
  • @dphil that's a great point. (I would rather pay that price in my small org, but I can see it being a problem in a larger one). – Charles Koppelman Nov 3 '14 at 19:06
  • And what's to say your small org won't grow one day to become a large one? Even if not large in data, large in code. I always try to build based on the assumption that things will grow. Sort of the same reason I bulkify triggers. Sure we might only insert those records 1 at a time, but what if some day the process changes and we insert in bulk? I mean I definitely understand the reason you have for the 2 spaces, just adding a separate view on it. – dphil Nov 3 '14 at 21:12
  • 1
    @dphil I agree entirely. That's why I wantinput from folks with more than my 12 months Salesforce experience. – Charles Koppelman Nov 3 '14 at 22:02
  • 1
    @smohyee How about an Admin style guide that focuses on naming conventions? – Charles Koppelman Jul 20 '15 at 16:41

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.