Some questions for Coding Style


Well-known member
1. In XenForos code you always access the model from a controller through a $abcModel = getModelFromCache() function. Is it to display which models are accessed by the controller in the function list?

2. There are always {} embracing statements, even if there is just one single one.

3. Some addons use Name_XenForo_ControllerPublic_Thread, some use Name_ControllerPublic_Thread and some even use CoderName_Name_ControllerPublic_Thread. I got an addon from xfrocks and he used the first option, and I see its value at the former lacking of using hints for extending:
  public static function load_class($class, array &$extend)
     static $classes = array(
     if (in_array($class, $classes))
       $extend[] = 'PostCache_' . $class;
I'd like to hear about what you do and if you like to do so you could give some arguments for and against it.


Well-known member
1. $this->getModelFromCache('ModelName'); is easier than having to write XenForo_Model::create('ModelName');, nothing more than a short cut.
2. Most people find blocking code using the braces easier, myself included. You also get into explicitness with them and can more easily determine code blocks (some editors also allow you to close blocks with braces)
4. This is personal preference, I personally use:

ContainingFolder keeps any add-ons I write together, the add-on name replaces XenForo in whatever I'm extending and X_Y_Z is the folder structure identical to XF.