Specification 2_PHP Tutorial
If Then Else Format Layout This is decided by the programmer. Different brace styles will produce slightly different looks. A common way is: if (condition 1) // comment { } else if (condition 2) // comment { } else // comment { } If you use an else if statement, it is usually best to have an else block to use it To handle other unhandled situations. If possible, put a record information comment in else, even if there is no action in else. Conditional formatting always puts the constant to the left of the equal/inequality sign, for example: if ( 6 == $errorNum ) ... One reason is that if you leave out an equal sign in the equation, the syntax checker will report an error for you . The second reason is that you can find the value immediately instead of finding it at the end of your expression. It takes a little time to get used to the format, but it works really well. -------------------------------------------------- ------------------------------- switch format Falling through a case statement into the next case statement shall be permitted as long as a comment is included. The default case should always exist, it should not be reached, but if it is reached it will trigger an error. If you are creating a variable, put all the code in a block. For example switch (...) { case 1: ... // FALL THROUGH case 2: { $v = get_week_number(); ... } break; default: } ------------ -------------------------------------------------- ------------------ Use of continue, break and ?: Continue and Break Continue and break are actually hidden goto methods in disguise. Continue and break are like goto, they work magic in your code, so use them sparingly (as little as possible). Using this simple magic, readers will be directed, for some undisclosed reason, to places only God knows. Continue has two main problems: It can bypass test conditions. It can bypass equality/inequality expressions. Look at the following example and consider where the problems occur: while (TRUE) { ... // A lot of code ... if (/* some condition */) { continue; } ... // A lot of code ... if ( $i++ > STOP_VALUE) break; } Note: "A lot of code" is required so that programmers cannot find errors so easily. From the above examples, we can draw a further rule: mixing continue and break is the right way to cause disaster. ?: The trouble is that people tend to try to cram a lot of code between ? and :. Here are some clear linking rules: Put the condition in parentheses to separate it from the rest of the code. If possible, actions can use simple functions. Put the actions, "?", and ":" on different lines, unless they can clearly be placed on the same line. For example (condition) ? funct1() : func2(); or (condition) ? long statement : another long statement; ----------------------- -------------------------------------------------- ----- Positioning of declaration blocks Declaration code blocks need to be aligned. Justification is clear. A similar block of code for variable initialization should be listed. The ??token should be adjacent to the type, not the name. For example var $mDate var& $mrDate var& $mrName var $mName $mDate = 0; $mrDate = NULL; $mrName = 0; $mName = NULL; -- -------------------------------------------------- ---------------------------- One statement per line Write only one statement per line unless the statements are closely related. -------------------------------------------------- ----------------------------- Short method code should be limited to one page. Rationale The idea is that each method represents a technique that accomplishes a separate purpose. Too many invalid arguments are a mistake in the long run. Calling a function is slower than not calling it at all, but this decision requires careful consideration (see premature optimization). -------------------------------------------------- -------------------------- Record all empty statements. Always record the empty block statements of for or while for clarity. I don’t know whether this piece of code was missed or was deliberately not written. while ($dest++ = $src++); // VOID ---------------------------------------------- ------------------------------------------ Do not use the default method to test for non-zero Do not use the default value to test non-zero values, that is, use: if (FAIL != f()) is better than the following method: if (f()) Even FAIL can contain a value of 0, which is what PHP considers false. . When someone decides to use -1 instead of 0 as a failure return value, an explicit test can help. Explicit comparison should be used even if the comparison value will not change; for example: if (!($bufsize % strlen($str))) should be written as: if (($bufsize % strlen($str)) == 0) A numeric (not Boolean) type representing the test. A common problem is using strcmp to test a character equation, and the result will never equal the default value. Non-zero tests are based on default values, so other functions or expressions will be subject to the following restrictions: they can only return 0 to indicate failure, and cannot have other values. Named so that a true return value is absolutely obvious, call the function IsValid() instead of Checkvalid().-------------------------------------------------- -------------------------- Most functions of the Boolean logic type return 0 when FALSE, but when a non-0 value is used, it means TRUE, so instead of testing a Boolean value with an equality of 1 (TRUE, YES, etc.), use an inequality of 0 (FALSE, NO, etc.) instead: if (TRUE == func()) { ... should be written as : if (FALSE != func()) { ... ---------------------------------------- ----------------------------------------------- Generally avoid embedded assignments Sometimes in some places we can see embedded assignment statements. Those structures are not a better method with less redundancy and strong readability. while ($a != ($c = getchar())) { process the character } The ++ and -- operators are similar to assignment statements. Therefore, for many purposes, side effects can occur when using functions. It is possible to improve runtime performance using embedded assignment. Regardless, programmers need to consider the tradeoff between increased speed and reduced maintainability when using embedded assignment statements. For example: a = b + c; d = a + r; Do not write: d = (a = b + c) + r; although the latter saves one cycle. But in the long run, as the maintenance costs of the program gradually increase and the program writers gradually forget about the code, the optimization gains in the mature period will be reduced. -------------------------------------------------- ----------------------------- Reuse yours and others' hard work Reuse across projects without a common structure Almost impossible. Objects conform to their existing service requirements. Different processes have different service requirements environments, which makes object reuse difficult. Developing a common structure requires a lot of design effort up front. When efforts are unsuccessful, no matter for whatever reason, there are several methods recommended: Ask for advice! Send an email to the group for help. This simple method is rarely used. Because some programmers feel that if they ask other people for help, they will look inferior. How stupid is this! Do new and interesting work, don't do what others have done over and over again. If you need source code for something, if someone has already done it, email the group for help. The results will be surprising! In many large groups, individuals often have no idea what others are doing. You might even find someone looking for something to do and volunteer to write code for you, and if people work together there's always a gold mine out there. Tell! When you do something, tell everyone about it. If you make something reusable, let others know. Don’t be shy, and don’t hide your work away to protect your pride. Once you get into the habit of sharing your work, everyone will gain more. Dont be Afraid of Small Libraries A common problem with code reuse is that people don't build libraries from the code they've worked on. A reusable class may be hiding in a program directory and will never be shared because the programmer won't split the class out and add it to the library. One of the reasons for this is that people don't like to make a small library and have some incorrect feelings about small libraries. Get over this feeling, the computer doesn't care how many libraries you have. If you have some code that can be reused and can't be put into an existing library, then make a new library. If people really thought about reuse, the library wouldn't stay that small for a long time.If you are afraid of having to update makefiles when libraries are recomposed or added then dont include libraries in your makefiles, include the idea of services. Base level makefiles define services that are each composed of a set of libraries. Higher level makefiles specify the services they want. When the libraries for a service change only the lower level makefiles will have to change. Keep a Repository Most companies have no idea what code they have. And most programmers still dont communicate what they have done or ask for what currently exists. The solution is to keep a repository of whats available. In an ideal world a programmer could go to a web page, browse or search a list of packaged libraries, taking what they need. If you can set up such a system where programmers voluntarily maintain such a system, great. If you have a librarian in charge of detecting reusability, even better. Another approach is to automatically generate a repository from the source code. This is done by using common class, method, library, and subsystem headers that can double as man pages and repository entries. -------------------------------------------------------------------------------- 评价注释 注释应该是讲述一个故事 Consider your comments a story describing the system. Expect your comments to be extracted by a robot and formed into a man page. Class comments are one part of the story, method signature comments are another part of the story, method arguments another part, and method implementation yet another part. All these parts should weave together and inform someone else at another point of time just exactly what you did and why. Document Decisions Comments should document decisions. At every point where you had a choice of what

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to set up keyboard startup on Gigabyte's motherboard. First, if it needs to support keyboard startup, it must be a PS2 keyboard! ! The setting steps are as follows: Step 1: Press Del or F2 to enter the BIOS after booting, and go to the Advanced (Advanced) mode of the BIOS. Ordinary motherboards enter the EZ (Easy) mode of the motherboard by default. You need to press F7 to switch to the Advanced mode. ROG series motherboards enter the BIOS by default. Advanced mode (we use Simplified Chinese to demonstrate) Step 2: Select to - [Advanced] - [Advanced Power Management (APM)] Step 3: Find the option [Wake up by PS2 keyboard] Step 4: This option The default is Disabled. After pulling down, you can see three different setting options, namely press [space bar] to turn on the computer, press group

1. Processor When choosing a computer configuration, the processor is one of the most important components. For playing games like CS, the performance of the processor directly affects the smoothness and response speed of the game. It is recommended to choose Intel Core i5 or i7 series processors because they have powerful multi-core processing capabilities and high frequencies, and can easily cope with the high requirements of CS. 2. Graphics card Graphics card is one of the important factors in game performance. For shooting games such as CS, the performance of the graphics card directly affects the clarity and smoothness of the game screen. It is recommended to choose NVIDIA GeForce GTX series or AMD Radeon RX series graphics cards. They have excellent graphics processing capabilities and high frame rate output, and can provide a better gaming experience. 3. Memory power

QQ email: QQ number@qq.com, English QQ email: English or numbers@qq.com, foxmail email account: set up your own account@foxmail.com, mobile phone email account: mobile phone number@qq.com. Tutorial Applicable Model: iPhone13 System: IOS15.3 Version: QQ Mailbox 6.3.3 Analysis 1QQ mailbox has four formats, commonly used QQ mailbox: QQ number@qq.com, English QQ mailbox: English or numbers@qq.com, foxmail Email account: set up your own account@foxmail.com, mobile phone email account: mobile phone number@qq.com. Supplement: What is qq mailbox? 1 The earliest QQ mailbox was only between QQ users

SPDIFOUT connection line sequence on the motherboard. Recently, I encountered a problem regarding the wiring sequence of the wires. I checked online. Some information says that 1, 2, and 4 correspond to out, +5V, and ground; while other information says that 1, 2, and 4 correspond to out, ground, and +5V. The best way is to check your motherboard manual. If you can't find the manual, you can use a multimeter to measure it. Find the ground first, then you can determine the order of the rest of the wiring. How to connect motherboard VDG wiring When connecting the VDG wiring of the motherboard, you need to plug one end of the VGA cable into the VGA interface of the monitor and the other end into the VGA interface of the computer's graphics card. Please be careful not to plug it into the motherboard's VGA port. Once connected, you can

On March 3, 2022, less than a month after the birth of the world's first AI programmer Devin, the NLP team of Princeton University developed an open source AI programmer SWE-agent. It leverages the GPT-4 model to automatically resolve issues in GitHub repositories. SWE-agent's performance on the SWE-bench test set is similar to Devin, taking an average of 93 seconds and solving 12.29% of the problems. By interacting with a dedicated terminal, SWE-agent can open and search file contents, use automatic syntax checking, edit specific lines, and write and execute tests. (Note: The above content is a slight adjustment of the original content, but the key information in the original text is retained and does not exceed the specified word limit.) SWE-A

Glodon Software is a software company focusing on the field of building informatization. Its products are widely used in all aspects of architectural design, construction, and operation. Due to the complex functions and large data volume of Glodon software, it requires high computer configuration. This article will elaborate on the computer configuration recommendations of Glodon Software from many aspects to help readers choose a suitable computer configuration processor. Glodon Software requires a large amount of data calculation and processing when performing architectural design, simulation and other operations. Therefore, the requirements for the processor are higher. It is recommended to choose a multi-core, high-frequency processor, such as Intel i7 series or AMD Ryzen series. These processors have strong computing power and multi-thread processing capabilities, and can better meet the needs of Glodon software. Memory Memory is affecting computing

The Charm of Learning C Language: Unlocking the Potential of Programmers With the continuous development of technology, computer programming has become a field that has attracted much attention. Among many programming languages, C language has always been loved by programmers. Its simplicity, efficiency and wide application make learning C language the first step for many people to enter the field of programming. This article will discuss the charm of learning C language and how to unlock the potential of programmers by learning C language. First of all, the charm of learning C language lies in its simplicity. Compared with other programming languages, C language

Guide to solving misaligned WordPress web pages In WordPress website development, sometimes we encounter web page elements that are misaligned. This may be due to screen sizes on different devices, browser compatibility, or improper CSS style settings. To solve this misalignment, we need to carefully analyze the problem, find possible causes, and debug and repair it step by step. This article will share some common WordPress web page misalignment problems and corresponding solutions, and provide specific code examples to help develop
