Home  >  Article  >  Backend Development  >  Developing Robust Code with PHP: An Introduction to the High Level_PHP Tutorial

Developing Robust Code with PHP: An Introduction to the High Level_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:33:42794browse


Using PHP (as the current mainstream development language) The series of articles on developing robust code is about solving practical problems in large and medium-sized applications. This series of articles focuses on the new features available in PHP 4, highlighting a number of tips and tricks that make development work easier. In this series of articles, you'll find many examples and techniques to learn, complete with plenty of sample code. In this first article, php(as the current mainstream development language) expert Amol Hatwar introduces from a higher perspective how to design and write error-free and maintainable web applications for medium to large-scale web applications. code.   If you are a developer building web applications and need speed, functionality and platform-independence, then PHP
(as the current mainstream development language)
will suit you. And php(as the current mainstream development language) is free and easy to learn and deploy. These are the biggest advantages that make php(as the current mainstream development language) so popular. But these advantages can also turn into disadvantages. Because php(as the current mainstream development language) is easy to use, developers often force code into the editor when they should be planning and designing. Moreover, in php(as the current mainstream development language), there is more than one way to solve the problem, and it is easier to make tragic mistakes that are difficult to correct later.   In this series of articles, you will learn how to avoid many mistakes. If you stick to it one step at a time, don't be surprised if you find yourself writing error-free code in one or two attempts. I will also point out the new features available in php
(as the current mainstream development language)
4 that make development work easier. Most of the examples I'll cover deal with real-world issues such as script configuration and installation, file handling, and database usage. Even if you're new to all this, you'll find it easy to understand. However, I assume that you have a preliminary understanding of php(as the current mainstream development language). If you need a refresher, you may find the references listed at the end of this article helpful. (See Resources.)   
Lay a strong foundation
Use PHP(as the current mainstream development language)
Write code with something like C Languages ​​for writing code are very similar. Because they are syntactically similar, they also lead to similar code maintenance issues. When you have to develop a large application, you may have to write a lot of code. Over time, this code can become unmanageable, and bugs can quickly creep in. No matter where you hear this statement, don't believe it—at least not entirely. However, the more important fact is that if you find yourself maintaining code too often, your application is probably poorly designed in the first place.   
Design your code correctly
  The choices you make initially will affect the freedom you have when writing code later. This makes correct design an important prerequisite. Although design can become an extra ritual when you solve a trivial problem, you must at least know that this is what you should do. Many people view design and planning as additional overhead. But starting with a poor design, or no design at all, always results in sloppy code. Remember, no amount of clever coding can make up for poor design. Although how to design applications is beyond the scope of this series of articles, I will suggest some issues that you should keep in mind when designing web applications.  
 
Divide and Conquer
  It is always preferable to design and write large applications through smaller, loosely coupled components. This way, every part is maintainable. For example, a Content Management System (CMS) may be distributed across many smaller modules such as user authentication, display, content parsing, and viewing statistics. And, if your module is general enough, you can reuse the code in other applications you develop. Programmers do this all the time, but they still complain. As for coding, the trick is to give each module the functionality it absolutely needs and call it a day. The functions assigned to a module should be just right.  
 
Never consider
 If you are interested in using php(as the current mainstream development language)
to make your HTML page more dynamic If you are interested, this section will be suitable for you. This habit usually starts when you want to display the date and time on every page to make it look up to date. Each HTML page becomes a small php(as the current mainstream development language) script with only a few lines, and the date function is hidden somewhere.If this is what you want, you must agree that this is the easiest way to make the job happen. However, imagine what changes you would have to make to change the date format presented on the page. You will have to change the code within each page.
 
 Obviously, there is a better way to achieve this. My favorite way is to use a config file and define a constant in the config file that holds the format string for the date() function. You can then use the date() function wherever needed. Each page still ends with a script, but you'll want to minimize the number of changes you have to make to a single line of code.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508603.htmlTechArticleUsing PHP (as the current mainstream development language) to develop robust code series of articles is about solving large and medium-sized applications of practical problems. This series of articles mainly focuses on php (as...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn