Resource icon

Development Best Practices

Jeremy

in memoriam 1991-2020
Jeremy submitted a new resource:

Development Best Practices - Practices are your friends.

When developing for XenForo, there are some best practices that should be followed, which will prevent possible issues down the road or protect your users from further updates.

Prefix everything.
Prefixing your data and information is the one thing that every developer should do. By not prefixing your data, you run the risk of conflicting with add-ons and updates to the core. When coming up with a prefix, you should use something unique. "jeremy" is not unique and could easily be...

Read more about this resource...
 
I don't mean to bump this, but here are some other practices I'd like to get consistency on.

1) I assume IF/ENDIF code practice is frowned upon, using brackets such as
Code:
if ($something)
{
    $this->do($something);
}
else
{
    $this->(null);
}

2) Is there a best practice for using lowercase booleans vs. uppercase booleans, I'm of the understanding that lowercase booleans can be parsed faster?

3) Is there a best practice on versioning?

4) I suppose PHPDoc should be stated as a best practice for comments and documentation?

5) Any guidelines on packaging add-ons, what to include in them, etc.?
 
For 3 I use:

Major version A
Second point B
Minor version C
Status X
Patch level Y

Status X
1 Alpha
3 Beta
5 RC
7 Stable

Examples
1.0.4 Beta 4 1000434
1.3.0 RC 2 1030052
1.4.2 1040270
1.5.0 Alpha 1 1050011
2.0.0 Beta 3 2000033
 
1) I assume IF/ENDIF code practice is frowned upon, using brackets such as
Code:
if ($something)
{
    $this->do($something);
}
else
{
    $this->(null);
}

There is nothing wrong with using if/else's as long as they are appropriate. Doing:
PHP:
if (false) {
  // do nothing
} else { 
  $this->do($something);
}
is bad practice.

2) Is there a best practice for using lowercase booleans vs. uppercase booleans, I'm of the understanding that lowercase booleans can be parsed faster?
I'm not sure you gain anything. I stick to lower case myself.

3) Is there a best practice on versioning?
What Paul said, it is how XF does it.

4) I suppose PHPDoc should be stated as a best practice for comments and documentation?
Yes

5) Any guidelines on packaging add-ons, what to include in them, etc.?

You should include everything necessary that you can. If anything, follow your required directory structure *exactly* when packaging.
 
Back
Top Bottom