Some questions for Coding Style

Marcus

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:
PHP:
  public static function load_class($class, array &$extend)
   {
     static $classes = array(
       'XenForo_BbCode_Formatter_Base',
       'XenForo_ControllerPublic_Thread',
       'XenForo_DataWriter_DiscussionMessage_Post',
       'XenForo_Model_Post',
       'XenForo_ViewPublic_Thread_View',
       'XenForo_ViewPublic_Thread_ViewPosts',
     );
     
     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.
 
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_AddonName_X_Y_Z

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.
 
Top Bottom