Just Another Blog

Are you thinking what I'm thinking?

Monday, June 14, 2004

Personal Holiday Programming

In this 2 weeks I have been writting PHP4 frequently. Here are some of my thoughts and feels:

The basic:

  1. IMPO, A hybrid of C, Perl and JavaScript.
  2. Control structures and operators from C.
  3. Predefined functions from Perl.
  4. Weak typing, function/class structures from JavaScript.

The good:

  1. 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
  2. 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>";
  3. Amazing "array":
    $arr = array(
        "firstName" => "Martin",
        "lastName" => "Ng"
    );
    echo "<p>I'm $arr['firstName'] $arr['lastName'].</p>";
    As you can see, array is not just an "array", but a rather complex data structure (ordered map).

The bad:

  1. 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?
  2. 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:

  1. Weak typing.
  2. 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.
  3. 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...).
  4. The dollar sign for variables. I just hate it. Frequently forget to type "$" when using variables.
  5. The $this pointer. Why do I need to type $this->something when I'm just referencing some member variables/functions?
  6. While all C family languages use "else if", PHP uses "elseif".
  7. String concatenation operator is ". (a dot)", rather than "+" in C family languages.
  8. 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