
5 tricks that make life easier for a PHP teapot
Since I am not a programmer, but sometimes I torment WordPress a little , it turns out that I program. Of course, I'm confused. You also have to read someone else's code and understand it. And remember what I wrote there myself. Gradually, while studying someone else’s code and rubbing stuffed cones, I came to a list of techniques that make life easier for a PHP teapot.
1. Before each function write what this function does. Still write comments in front of all sorts of complex pieces and regular expressions. Well, at the beginning of the file, write what kind of file it is, what it is for, what it contains. With version and date of change.
2. Name the functions so that it is clear what it does. Better with the use of verbs. For example, if a function kills a squirrel, call it kill_the_squirrel (), and if it saves the world, then save_the_world (). Well, variables can be called nouns, only so that it is also clear what it is about. For example, a counter might be called $ counter.
3. After each command, put a semicolon. Even if in this case it can be omitted. And write new commands from a new line. Then, when adding commands, it is less likely that you forget to put this same semicolon.
4. If a variable is compared with a value, it is better to write the value first, then the variable. For example, if (100 == $ counter) ... and so on. I often put one equals instead of two characters. If you write the value first (a constant, as smart people told me), then PHP will throw a parse error with a line number. This will help to quickly find the joint.
5. Use padding and braces. Put the opening bracket after the name of the function or operator, such as if, and the closing bracket in the position corresponding to the first letter of the operator. It’s easier to find where what begins and ends.
1. Before each function write what this function does. Still write comments in front of all sorts of complex pieces and regular expressions. Well, at the beginning of the file, write what kind of file it is, what it is for, what it contains. With version and date of change.
2. Name the functions so that it is clear what it does. Better with the use of verbs. For example, if a function kills a squirrel, call it kill_the_squirrel (), and if it saves the world, then save_the_world (). Well, variables can be called nouns, only so that it is also clear what it is about. For example, a counter might be called $ counter.
3. After each command, put a semicolon. Even if in this case it can be omitted. And write new commands from a new line. Then, when adding commands, it is less likely that you forget to put this same semicolon.
4. If a variable is compared with a value, it is better to write the value first, then the variable. For example, if (100 == $ counter) ... and so on. I often put one equals instead of two characters. If you write the value first (a constant, as smart people told me), then PHP will throw a parse error with a line number. This will help to quickly find the joint.
5. Use padding and braces. Put the opening bracket after the name of the function or operator, such as if, and the closing bracket in the position corresponding to the first letter of the operator. It’s easier to find where what begins and ends.