Before, today and proofread again, but also when they have to review again, and have a new feeling.
Worthy of a prestigious open source project, coding norms simple and concise, to the point.
Hope to be helpful to everyone, welcome to exchange views.
Standard specification for PhpBB coding
If you have comments or suggestions on the contents of the original manual, please send an email to nate@phpbb.com;
If you have any comments or suggestions for this translation, please contact QQ78045595 or email to gaogan at gmail dot com.
Editor settings
tab vs Spaces: For this to be as simple as possible, we use tabs without spaces. You can configure how many spaces the editor uses to display tabs, but you must make sure that when you save the file, it keeps tabs instead of spaces. In this way, each of us can make the code appear the way we like, without destroying the actual file layout.
Wrapping: Make sure the editor saves the file in Unix format. This means terminating a line with a newline character, rather than using a cr/lf in Win32, or a way that MAC does. Any specification of the Win32 editor should do this, but this is not always the default. You need to be familiar with your editor. If you need advice on using a Windows text editor, you should consult its developers. Some of them are doing editorial work in Win32.
Naming conventions
In our naming convention, we will not use any form of Hungarian naming. Many of us believe that Hungarian naming is one of the main tricks that leads to code chaos.
Variable name: The variable name should be all lowercase, and the words are separated by a single underline.
For example: $current _user is correct, but $currentuser and $currentUser are incorrect.
The name should be descriptive and concise. We naturally do not want to use lengthy sentences as variable names, but it is better to enter a few characters than to wonder what a variable is for.
Loop counter: The only case where a single character variable name is allowed is when it is used as a loop counter. In this case, the counter of the outer loop should always be $i. If there is a loop inside the loop, its counter should be $j, $k, and so on. This specification does not apply if the loop counter is a variable that already exists and has a meaningful name.
For example:
1 for ($i = 0; $i < $outer _size; $i + +)
2 {
3 for ($j = 0; $j < $inner _size; $j + +)
4 {
5 foo ($i, $j);
6}
7}
View Plain | Print | Copy to Clipboard |?
Function Name: A function should also be named in a descriptive way. Here we are not programming with C, we do not want to write a function such as "STRISTR ()". Ditto, use the lowercase names separated by a single underline between the words. There is a better verb somewhere in the name of the function. Better function names such as Print_login_status (), Get_user_data (), and so on.
Function arguments: parameters follow the same conventions as variable names. We don't want a bunch of such functions: Do_stuff ($a, $b, $c). In most cases, we want to just look at the declaration of a function and know how to use it.
Conclusion: The basic philosophy here is not to hurt the clarity of the code in order to be lazy. However, there must be some common sense to grasp this balance; for example, Print_login_status_for_a_given_user () has gone overboard-this function is named Print_user_login_status () better, or just print _login_status ().
Code layout
New file's standard head: Here is a template for the head, it should be included in each PhpBB file start
1/***************************************************************************
2 &NB