Xin Xing talks about PHP's chaotic coding style, and Xin Xing talks about php

Source: Internet
Author: User

Xin Xing talks about PHP's chaotic coding style, and Xin Xing talks about php

We all know that various programming languages have their own styles, even languages like C and C ++ (C ++ is fully compatible with C syntax ), there are still some differences in programming style. For example, it is typical that single-line comments in the C ++ style and multi-line comments in the C style.

Although Java draws on the C syntax to a large extent, it is undeniable that the classical braces of Java are left braces that are equivalent to a row in the class name or function name, the C ++ style is a line starting with braces. Some Java programmers and C ++ programmers may use these two styles. However, if you look at the Masters' encoding styles, we will find that another line of braces is a typical C ++ style, while another line of braces is a typical Java style. Although there is no essential difference, it is like modern people like to shake hands, ancient people like to hold their fists. These habits are very deep-rooted in the hearts of people.

The following is the PHP programming style. I think many people have learned a lot of programming languages and have their own opinions on the encoding style. Yes, PHP's programming style is so messy. First, PHP is written in C language. Many functions use the C style directly, such as braces and semicolons. This is also a good thing, after all, C programmers are very gray and suitable for their learning. Then PHP draws on a lot of Perl styles. The most classic one is the $ symbol. In my opinion, apart from perl and php, I did not find any language that I like to add such a symbol before the variable name. The next step is its annotation style. The typical Shell, C, and C ++ styles are all supported. This is good, not to mention confusion, at least classic.

What I have to say is the encoding style of the PHP function name, a word: Messy. If this function is located in the class, we need to consider the hump naming method, such as getName. For built-in functions, it may be connected by underlines, such as error_reporting, such as html_entity_decode, it may also be directly connected by letters, such as htmlentities, or some shorthand rules, such as rtirm and ltrim. It has brought some confusion to PHP's learning and use.

Finally, let's talk about PHP's object-oriented approach. PHP's object-oriented approach is Java-style to a large extent and draws on the idea of Java's single inheritance and interfaces. Therefore, it is particularly suitable for Java programmers to switch to PHP and PHP programmers to Java.

For a moment, I can't think of anything more. In short, the PHP encoding style is a hodgedge and requires programmers to constantly adapt to it.




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.