the real ugly parts of PHP (ZZ)

来源:https://www.amazon.com/gp/customer-reviews/R2D9T7KNTHFC5A

 

I should warn the reader that I never was a PHP enthousiast in spite of being able, though, to recognize a well written book about it.

I will first comment on PHP as a language, as to give a general background, then on the book itself.

1. PHP
======
Though I often came to use PHP as a software engineer within my own company (Client is the "king" and business is business), and was regularly asked to teach it in a university CS bachelor degree, I always disliked PHP as a programming language.

I am not afraid to state and to show that PHP is probably today's sloppiest language in the same sense BASIC was a sloppy language in the late seventies eventhough wonderful languages long already existed by that time (Lisp, Modula, C, Pascal, Smalltalk, only to name a few).

Born from a quick and dirty hack by a hurried programmer (Rasmus Lerdorf), and initially the acronym for "Pretty Home Page" (nothing fancier), PHP as evolved eratically along the years not only to fix numerous bugs and security issues (like BASIC in its era), but also to constantly adapt the more and more demanding programmer by throwing-in, as is, important concepts that were seriously missing from the start (arrays, object oriented layer, anonymous functions, closures, ...), so to become today nothing more than a bloated language lacking all the minimal aspects of a serious language ("serious" not meaning "difficult" by the way ;) ) :

- Poor overall semantics, often leading to nonsense and or convoluted syntax, for instance :

. No proper arrays per se (in the well respected traditional sense of an array data structure) but mere "ordered hash maps" that can lead to unexpected results since PHP programmers are made to believe they are dealing with proper arrays...

. Convoluted "by-value" versus "by-reference" semantics, along with the awful syntax to express it :
" function &foo(&$a,$b){...}; $x=& foo($a,$b); $x=foo($c,$d); "

. "Construct functions" versus "1st-class functions", with some functions being neither one or the other!

. "$n=func_num_args(); foo($n)" works, but "foo(func_num_args())" does not!

. Initializers most often allow only simple literals instead of full-blown expressions!

. Nested functions pollute the global space and can lead to runtime errors when the parent functions run more than once.

. Funny closure construct that forces the programmer to manually build his own closure through the construct "use()" ! Enhancement or regression ?
...

- Poor orthogonality. For instance :

. "print()" is neither what PHP calls a "construct" (like echo) nor a real function!

. "str_split()" is defined , but no "str_join()" is not (ok there is a join()...)!

. "str_xxx()" versus "strxxx()" function naming scheme : underscore or not ?

. "array_merge()" is defined, but "array_split()" is not !

. "array_filter(array,callback)" takes an array as its 1st argument, and a callback function as its second argument. "array_map(callback,array)" does the opposite !

. (?:) is presented to be usable either as a statement construct ($tea_time ? echo "Tea time!" : echo "Arghh!") or as an expression operator (echo $a ? "Tea time!" : "Arghh!")...

...

The list could go on! But the point here is not to make it exhaustive nor to start a flame, only to point out the mysteries behind PHP's wide adoption, when so many powerful alternatives actually do exist which are no more difficult to master than PHP, even often easier, and which lead to much more powerful web development frameworks, for instance (in lexicographic order) : Erlang/Nitrogen, Haskell/Yesod, Java/{Server faces, Struts, Spring MVC}, Node.js (Javascript), Perl/Dancer, Python/Django, Ruby/{Rails,Sinatra}.

In its own era, BASIC, despite being an awful language, had won a large crowd of new-comers intimidated by alternative superior languages as the direct result of Microsoft's amazing marketing falsly convincing users of the superiority of this language which has led to an entire generation of bad programming practices.

20 years later, in the context of Web development, PHP has gained a respectful momentum through the same strange phenomenon of word-of-mouth, and this is most worrying. Please notice, though, that the Big Web players like Amazon, Google, Microsoft, Yahoo, EBay, PayPal, Facebook, Twitter to name a few, do not use PHP for their major activities.

 

posted @ 2022-11-17 11:52  profesor  阅读(21)  评论(0编辑  收藏  举报