Personal Holiday Programming
In this 2 weeks I have been writting PHP4 frequently. Here are some of my thoughts and feels:
The basic:
- IMPO, A hybrid of C, Perl and JavaScript.
- Control structures and operators from C.
- Predefined functions from Perl.
- Weak typing, function/class structures from JavaScript.
The good:
- Easy to learn for C family (C/C++/Java/JavaScript/C#) programmers. Should be easy to Perl programmer too... not sure though as I'm not. :-P
- Easy to output strings. Even that I didn't use the C-like printf, echo can be pretty amazing already:
$word = "Hello World"; echo "<p>I want to say $word to all of you</p>";
- Amazing "array":
As you can see, array is not just an "array", but a rather complex data structure (ordered map).$arr = array( "firstName" => "Martin", "lastName" => "Ng" ); echo "<p>I'm $arr['firstName'] $arr['lastName'].</p>";
The bad:
- Cannot declare variable before using it: don't PHP guys know implict variables can lead to subtle errors? e.g. mistyping a variable name will create a new variable. When you can "Dim" a variable in ASP and "var" a variable in JavaScript, why can't we do the same in PHP?
- Everything in a class is public! I thought classes are used for information hiding. PHP's class only have encapsulation, but little information hiding. I know the public, protected and private keywords are introduced in PHP5, but PHP5 is not backward compatible with PHP4... While even JavaScript can have private member (thanks to closures), I wonder why PHP can't emulate this. I know putting things private is not good to performance as we need to write lots of get and set functions.
The ugly:
- Weak typing.
- Magic quotes, which escapes single quote, double quote and NULL in GET/POST/Cookies with a backlash, is turned on by default. I think this is a big mistake.
- The member accessor in C family languages are well known as the dot operator (or "->" if the class is defined as pointer). e.g.
document.createElement( "hr" );
. However, PHP uses "->" only (because everything is called by reference? I'm not sure...). - The dollar sign for variables. I just hate it. Frequently forget to type "$" when using variables.
- The $this pointer. Why do I need to type $this->something when I'm just referencing some member variables/functions?
- While all C family languages use "else if", PHP uses "elseif".
- String concatenation operator is ". (a dot)", rather than "+" in C family languages.
- I prefer "<% ... %>" (as seem in ASP and JSP) over <?php ... ?>.
Look like I hate it more. Anyway, can't complain too much to a free software...
0 Comments:
Note that troll and spam comments will be deleted without any notification.
Post a Comment
<< Home