I don't feel this is discussed too often and I am by no means an expert, but I wanted to begin a discussion about what naming convention to use and where.

Formats

To get started, I want to lay out all of the different formats a name can take and where i've seen them used:

  • alllowercase (Pretty rare but mostly in database schemas)
  • camelCaps (Instance names in Objective-C, Swift and Javascript)
  • with-a-dash-in-the-middle(CSS Class names or id attributes)
  • seperatedbyunderscores (PHP Methods)
  • ALLCAPS (Constants in a variety of languages)
  • LeadingCaps (Class names in Objective-C and Swift)
  • rEVERSElEADINGcAPS (Never)

The PSR-1 coding standards have specific guidelines for PHP:
http://www.php-fig.org/psr/psr-1/

However, you still have the choice of using camelCaps or lower_case_underscore for method names.

Apple recommends using camelCaps for instance names or methods (functions) and LeadingCaps for class names.

I think it's obvious to say that sticking with the particular practices and common guidelines for each language is the best way to go - for two reasons:
1. Your code will be more accessible to other developers.
2. When writing in different languages, it serves as a reminder to see a different format in the naming convention (you may laugh but I get confused between different languages!).

What name to use

Ok, this is where a lot more personal touch comes into play.

Once again, let's look at the native libraries for a couple of languages and how they differ:

PHP

  • Abbreviates words (i.e: str_replace)

CocoaTouch (Main library used in iOS development)

  • Uses full words, and lots of them (i.e: UIGuidedAccessRestrictionStateForIdentifier)
  • Prefixes Classes with two Uppercase characters based on the framework they are from (UI, NS, HM, CK, etc)
    • Writes ID in all caps

JavaScript

  • Writes Id in leading caps (i.e: getElementById)

With all this in mind, here are some simple tips:

  1. USE FULL WORDS
    I much prefer using full words - it's really annoying when you inherit a project with instance names like: 'v' or 'slImage'. I used to use abbreviated instance / variable names like this but I forgot what the names meant!

  2. USE PREFIXES FOR CLASSES
    This is good in iOS development to distinguish your code from other frameworks, OR if your project is a framework itself! Use your name if you like but I would suggest basing the prefix off of the project. Oh yes, and you CAN use abbreviations for the prefix (heaven forbid that I start forgetting that!). If you are coding for Wordpress then this is vital - you are sharing a namespace with the world!
    If you your project name changes (if you work for a company, this happens all the time) keep your original prefix, most likely your classes aren't public facing.

  3. PREFIX YOUR PROPERTIES WITH SOMETHING
    Personally I prefix all of my properties (and I should probably do this with methods too) in iOS development with the word 'my'. This means that I can take advantage of XCode's auto-complete and find the properties I created - fast!

Final thought...

I wonder if Apple had the chance would they prefer to use 'AF' (Apple Foundation) instead of 'NS' (Next Step)...


I hope that you found this helpful!