Home > Backend Development > PHP Tutorial > If PHP was written in British English_PHP Tutorial

If PHP was written in British English_PHP Tutorial

WBOY
Release: 2016-07-20 10:58:15
Original
858 people have browsed it

Rasmus Lerdorf, the father of PHP, was very wise when he created PHP not in Greenlandic or Danish (although he has Greenlandic and Danish ancestry). Although writing in English is not as easy for him as writing in his native language. Since he had spent time in Canada before, he chose the local dialect. It’s not French, nor is it a dialect that doesn’t conform to the standard of pure English, which we usually call “American English.”

Since then, British PHP developers have been particularly dissatisfied with this matter. What was Rasmus thinking? More importantly, how do we change this fait accompli? How do we developers ensure that the fine traditions of the British Empire continue to flourish even in the digital age?

One note Slap

<ol class="dp-xml"><li class="alt"><span><span>$variable_name </span></span></li></ol>
Copy after login

The most necessary change is to delete some symbols that are loved by Americans and replace them with some more refined symbols to make PHP more elegant.

<ol class="dp-c"><li class="alt"><span><span>£variable_name </span></span></li></ol>
Copy after login

Let’s get started

<ol class="dp-xml"><li class="alt"><span><span class="tag"><?</span><span class="tag-name">php</span><span> </span></span></li><li><span>echo 'Hello World!';  </span></li><li class="alt"><span class="tag">?></span><span> </span></span></li></ol>
Copy after login

How many of today’s British programmers were first exposed to the typical American “Hello World” program, simple but offensively old-fashioned and vulgar? A more formal introduction would promote the use of the language by most of the young British geniuses, thus providing a more urbane atmosphere to a wider user base.

<ol class="dp-xml"><li class="alt"><span><span class="tag"><?</span><span class="tag-name">php</span><span> </span></span></li><li><span>announce 'Good morrow, fellow subjects of the Crown.';  </span></li><li class="alt"><span class="tag">?></span><span> </span></span></li></ol>
Copy after login

Acronyms

There is nothing the British hate more than unnecessary abbreviations. "Abbreviations" were unheard of on the streets of London, just as the native English grammarian refused to deign to send "c u soon traffic kthxbye" and other messages, preferring to use some more elegant-looking phrases instead: "Dear Sir or ma'am. I hope to arrive as soon as possible, within an hour. I assure you that your horses will be well accommodated." (Slower input, yes, but not in a hurry).

On the other hand, PHP contains a lot of unnecessary abbreviations and acronyms.

<ol class="dp-xml">
<li class="alt"><span><span>str_replace()  </span></span></li>
<li><span>is_int()  </span></li>
<li class="alt"><span>var_dump()  </span></li>
<li><span>preg_match()  </span></li>
<li class="alt"><span>json_encode()  </span></li>
<li><span>mysql_connect() </span></li>
</ol>
Copy after login

should be changed to the following:

<ol class="dp-xml">
<li class="alt"><span><span>string_replace()  </span></span></li>
<li><span>is_integer()  </span></li>
<li class="alt"><span>variable_dump()  </span></li>
<li><span>perl_regular_expression_match()  </span></li>
<li class="alt"><span>javascript_object_notation_encode()  </span></li>
<li><span>my_structured_query_language_connect() </span></li>
</ol>
Copy after login

Correction: I have corrected the expansion of "preg_match" - thanks to the friend who pointed it out.

Eloquence

<ol class="dp-c">
<li class="alt"><span><span class="keyword">if</span><span> (</span><span class="vars">$condition</span><span>) {  </span></span></li>
<li>
<span>    </span><span class="comment">// Code here </span><span> </span>
</li>
<li class="alt">
<span>} </span><span class="keyword">else</span><span> {  </span>
</li>
<li>
<span>    </span><span class="comment">// Code here </span><span> </span>
</li>
<li class="alt"><span>} </span></li>
</ol>
Copy after login

Shakespeare would not have liked to see his native language twisted into this monster. Simplicity is popular in the right circumstances - not necessarily in some remote places - but not here. The "if ... else" module is the most commonly used conditional code in PHP, so it must be as safe and harmless as possible when used. There are many alternatives, but this conditional statement is perhaps the most robust.

<ol class="dp-c">
<li class="alt"><span><span>perchance (£condition) {  </span></span></li>
<li>
<span>    </span><span class="comment">// Code here </span><span> </span>
</li>
<li class="alt"><span>} otherwise {  </span></li>
<li>
<span>    </span><span class="comment">// Code here </span><span> </span>
</li>
<li class="alt"><span>} </span></li>
</ol>
Copy after login

The above modules are also suitable for Americanized, which can only be said to be bulky and disgusting switch... case concepts,

<ol class="dp-c">
<li class="alt"><span><span class="keyword">switch</span><span> (</span><span class="vars">$variable</span><span>) {  </span></span></li>
<li>
<span>    </span><span class="keyword">case</span><span> </span><span class="vars">$option1</span><span>:  </span>
</li>
<li class="alt">
<span>        </span><span class="comment">//Code here </span><span> </span>
</li>
<li>
<span>        </span><span class="keyword">break</span><span>;  </span>
</li>
<li class="alt">
<span>    </span><span class="keyword">case</span><span> </span><span class="vars">$option2</span><span>:  </span>
</li>
<li>
<span>        </span><span class="comment">//Code here </span><span> </span>
</li>
<li class="alt">
<span>        </span><span class="keyword">break</span><span>;  </span>
</li>
<li>
<span>    </span><span class="keyword">default</span><span>:  </span>
</li>
<li class="alt">
<span>        </span><span class="comment">//Code here </span><span> </span>
</li>
<li>
<span>        </span><span class="keyword">break</span><span>;  </span>
</li>
<li class="alt"><span>} </span></li>
</ol>
Copy after login

like "switch", "break" Keywords like ” and “default” are difficult for readers and lack connection. This American usage really needs improvement. (People who use American usage have some interesting ideas and hope to use statements like i_might_be_partial_to() instead of include() to show their programming genius):

<ol class="dp-c">
<li class="alt"><span><span>what_about (£variable) {  </span></span></li>
<li><span>    perhaps £possibility:  </span></li>
<li class="alt">
<span>        </span><span class="comment">//Code here </span><span> </span>
</li>
<li><span>        splendid;  </span></li>
<li class="alt"><span>    perhaps £other_possibility:  </span></li>
<li>
<span>        </span><span class="comment">//Code here </span><span> </span>
</li>
<li class="alt"><span>        splendid;  </span></li>
<li><span>    on_the_off_chance:  </span></li>
<li class="alt">
<span>        </span><span class="comment">//Code here </span><span> </span>
</li>
<li><span>        splendid;  </span></li>
<li class="alt"><span>} </span></li>
</ol>
Copy after login

Spelling

<ol class="dp-c">
<li class="alt"><span><span>imagecolorallocate()  </span></span></li>
<li><span>serialize()  </span></li>
<li class="alt"><span>newt_centered_window()  </span></li>
<li><span>connection_status() </span></li>
</ol>
Copy after login

At this point, words have made me suffer a lot. How can a self-respecting gentleman understand these "words"? It undermines anyone's belief in accepting the distorted meanings of words in programming languages. These "words," and numerous similar errors, should be immediately restored to their proper form.

<ol class="dp-c">
<li class="alt"><span><span>imagecolourallocate()  </span></span></li>
<li><span>serialise()  </span></li>
<li class="alt"><span>newt_centred_window()  </span></li>
<li><span>connexion_status() </span></li>
</ol>
Copy after login

Habit

<ol class="dp-c">
<li class="alt"><span><span>try {  </span></span></li>
<li>
<span>    </span><span class="comment">// Code here </span><span> </span>
</li>
<li class="alt">
<span>} catch (Exception </span><span class="vars">$e</span><span>) {  </span>
</li>
<li>
<span>    </span><span class="comment">// Handle exception </span><span> </span>
</li>
<li class="alt">
<span>    </span><span class="keyword">die</span><span>(</span><span class="string">'Message'</span><span>);  </span>
</li>
<li><span>} </span></li>
</ol>
Copy after login

try … catch block is a good example of PHP’s lack of features. The new PHP allows the use of this module too directly and lacks the restrictions it should have. Also, the word "die" is very depressing. This new module, although more lengthy, is more elegant and upbeat.

<ol class="dp-c">
<li class="alt"><span><span>would_you_mind {  </span></span></li>
<li>
<span>    </span><span class="comment">// Code here </span><span> </span>
</li>
<li class="alt"><span>} actually_i_do_mind (Exception £e) {  </span></li>
<li>
<span>    </span><span class="comment">// Politely move on </span><span> </span>
</li>
<li class="alt">
<span>    cheerio(</span><span class="string">'Message'</span><span>);  </span>
</li>
<li><span>} </span></li>
</ol>
Copy after login

Classes

In the hearts of British people, nothing is as important and deep-rooted as the concept of classes, and this part of PHP rarely changes , unless there are important changes made here.

<ol class="dp-c">
<li class="alt"><span><span class="keyword">class</span><span> Republic {  </span></span></li>
<li>
<span>    </span><span class="keyword">public</span><span> </span><span class="vars">$a</span><span>;  </span>
</li>
<li class="alt">
<span>    </span><span class="keyword">private</span><span> </span><span class="vars">$b</span><span>;  </span>
</li>
<li>
<span>    </span><span class="keyword">protected</span><span> </span><span class="vars">$c</span><span>;  </span>
</li>
<li class="alt"><span>}  </span></li>
<li>
<span class="vars">$example</span><span> = </span><span class="keyword">new</span><span> Republic; </span>
</li>
</ol>
Copy after login

First of all, there is no room for class hierarchy in popular systems, which is unacceptable. So we should first give the class a specific level - upper, middle, working - so that the class cannot use the methods of a higher-level class without explicit permission from the higher-level directive class (of course , even if it has subsequently accessed a higher-level class, it is not a formal member of the higher-level directive and cannot grant itself access to higher-level directives of other lower-level directive classes). "public" and "private" are synonymous in the British class system (e.g., school system naming), so these must be adjusted, as is the property visibility of "protected". The word "new", while feasible, needs to be replaced by a more appropriate word in class problems.

<ol class="dp-c">
<li class="alt"><span><span>upper_class Empire {  </span></span></li>
<li><span>    state £a;  </span></li>
<li class="alt">
<span>    </span><span class="keyword">private</span><span> £b;  </span>
</li>
<li><span>    hereditary £c;  </span></li>
<li class="alt"><span>}  </span></li>
<li><span>£example = nouveau Empire; </span></li>
</ol>
Copy after login

The sun never sets...

Hope these few simple changes can enhance PHP's reputation and status among many programming languages. It’s no longer a distant relative of crappy Americana. Instead, it falls back into the lap of the British as kings of scripting languages.

English original text:

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445711.htmlTechArticleWhen Rasmus Lerdorf, the father of PHP, created PHP, he did not write it in Greenlandic or Danish (although he With Greenlandic and Danish ancestry), this is very sensible. Although English is used for him...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template