Develop robust code with PHP: Introduction to the advanced architecture-PHP Tutorial

Source: Internet
Author: User
Use PHP to develop robust code: Introduction to the advanced architecture. Using php (as the mainstream development language) to develop robust code series articles is about solving practical problems in large and medium-sized applications. This series of articles focuses on php (as a mainstream development language) to develop robust code series articles about solving practical problems in large and medium-sized applications. This series of articles focuses on the new functions available in php (as the mainstream development language) 4, and focuses on a lot of tips and tricks to make development easier. In this series of articles, you will find a lot of examples and technologies to learn, and a lot of sample code is attached. In this first article, php (as the mainstream development language) master Amol Hatwar introduces how to design and compile error-free and maintainable code for medium to large Web applications from a higher perspective.
  
If you are a Web application developer and need platform-independence, php (as the mainstream development language) is suitable for you. Moreover, php (as the mainstream development language) is free and easy to learn and deploy. These are the biggest advantages that make php (as the mainstream development language) so popular. However, these advantages can also become disadvantages. Since php (as the mainstream development language) is easy to use, developers often put the code into the editor when they should have planned and designed it. In addition, in php (as the mainstream development language), there are more than one solution to the problem, and it is easy to make that kind of painful mistake, which is difficult to be corrected later.
  
In this series of articles, you will learn how to avoid many mistakes. If you do not stick to it, you will find that you can write error-free code once or twice. Don't be surprised. I will also point out the new features available in php (as the current mainstream development language) 4, which make development easier. Most examples I will introduce are used to handle actual problems such as script configuration and installation, file processing, and database usage. Even if you are not familiar with all this, you will find it easy to understand. However, I suppose you have a preliminary understanding of php (as a mainstream development language. If you need to study again, you will find that the references listed at the end of this article will be helpful to you. (See references .)
  
   Lay a strong foundation
Writing code using php (as the mainstream development language) is very similar to writing code in a language similar to C. Because they are syntactically similar, similar code maintenance problems may occur. When you need to develop large applications, you may need to write a lot of code. As time passes, these codes may become difficult to manage, and errors will soon be passed in. Do not believe this statement wherever you hear it-at least not all. However, the more important fact is that if you find that your code is maintained too frequently, your application may be poorly designed first.
  
   Correct code design
Your initial choice affects your freedom to write code later. This makes correct design an important prerequisite. Although the design will become an additional ceremony when you solve a trivial problem, you must at least know that it should be done. Many people regard design and planning as additional expenses. But starting with a bad design, or there is no design at all, the results will always lead to sloppy code. Remember, clever coding cannot make up for bad design. Although how to design applications is beyond the scope of this series of articles, I will still be prompted with some questions that should be kept in mind when designing Web applications.
  
   Split and conquer
Designing and writing large applications with small loosely coupled components is always more desirable. In this way, each part is maintainable. For example, a Content Management System (CMS) may be distributed in many smaller modules, such as user authentication, display, Content parsing, and statistics viewing. In addition, if your module is common enough, you can reuse the code in other applications you develop. Programmers often do this, but they still complain. The coding technique is to make each module have the functions that it absolutely requires and so far. It is just right to assign more functions to a module.
  
   Never consider
If you are interested in using php (as the mainstream development language) to make your HTML page more dynamic, this part will be suitable for you. When you want to display the date and time on each page to make it look the latest, it is usually the beginning of this habit. Every HTML page becomes a small php script with only a few lines (as the mainstream development language), and the date function is hidden somewhere. If this is what you want, you must acknowledge that this is the easiest way to implement this job. However, imagine what changes you must make to change the date format displayed on the page. You will have to change the code on each page.
  
Obviously, there is a better way to achieve this goal. My favorite method is to use the configuration file and define a constant in the configuration file. this constant retains the format string of the date () function. Then, you can use the date () function as needed. Each page still ends with a script, but you need to minimize the places where you must make changes to a single line of code.

Development of robust code series articles in php (as the mainstream development language) is about solving practical problems in large and medium-sized applications. This series of articles focuses on php (...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.