Monday, August 25, 2008

PHP = Python - 12 years

Today, I happened to see that PHP 5.3 Alpha 1 was released a few weeks ago. Some of the things on the feature list made me shake my head and wonder how anyone could deal without them in Python; others made me cringe.

Apparently, PHP will finally be getting C++ style namespaces. While this is a minuscule step in the right direction, it pales compared to Python's beautiful module system.

PHP is also finally getting an optional cyclic garbage collector. I probably wouldn't use PHP long enough to get to making cyclic arrays, but still...

There's also going to be lambdas and basic closures. Too bad PHP function and class declarations aren't as flexible as Python's.

New syntax is being added. This is includes the NOWDOC syntax for writing unparsed strings. (ugly!) The worst, however, is the introduction of goto! Yes, PHP has taken another giant step towards becoming interpreted C.

(sigh)

12 comments:

trombonechamp said...

Oops! I accidentally typed the following into python:

$a =& $b;

I forgot that I CAN'T DO THAT IN PYTHON because it DOESN'T SUPPORT REFERENCES!
Talk about $Python = $PHP - 12 years

Evert Pot said...

Although I agree that goto is scary, I feel like I should explain the original reasoning behind it..

It basically originated from the continue; and break; syntax, which allow breaking out of multiple levels (e.g: break 2; continue 3;)

Now, if code like that should be refactored, you would have to find all your break/continue statements and increase or decrease the number.. hence this goto was introduced as a 'labeled break'.

Still it's goto, which could be quite scary :)

Anonymous said...

@trombonechamp:

You are a fool. Python
supports references
explicitly everywhere!

$ python
Python 2.5.2 (r252:60911, Aug 4 2008, 09:44:44)
[GCC 4.2.4 (CRUX)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = "foo"
>>> id(a)
3083460416L
>>> b = a
>>> id(b)
3083460416L
>>> a == b
True
>>>

The next time you make such a
_STUPID_, _BLATANT_ post, think
again. Go and learn _REAL_
programming. Better yet ...
Go do a course on Programming
Language Implementation.

--JamesMills (prologic)

Anonymous said...

"Now, if code like that should be refactored, you would have to find all your break/continue statements and increase or decrease the number"

So instead of factoring this code into something more maintainable, you reintroduce goto. That's like installing a horse in front of your car to save on gas.

Steve said...

@JamesMills: """You are a fool""".

It takes one to know one. If this is the best outlet you can find for your ego then kindly start using the other Internet (the one in a parallel universe :)

Anonymous said...

As a Python developer just dabbling in PHP, I must say this post is nothing shot of ridiculous. Python is a scripting language. PHP is a templating language. PHP never pretended to be anything more - although some clueless folks have certainly tried as much in the past. PHP solves the web problem, and it solves it well - tell me another language where I can build a complete web application in 3-4 KLOCs and pop it on any $1/month web server. Django's deployment still sucks, and a VPS is not the kind of thing you can demand from a client. (web.py isn't too bad, but it's totally overkill for simple web applications, e.g. dearadobe.com.)

Eric TF Bat said...

The ternary operator has been in PHP since at least version 4, so I'm a little mystified at that reference. What they really need is some kind of Perl-style "or", so you can do the equivalent of Perl's open INPUT, "<foo" or die "Can't open foo!"; but that would require a rewrite of a lot of the language to optionally return failure results from statements, I expect.

Anonymous said...

Don't be so hard on JamesMills, trombonechamp's comment was infuriating.

However Python does lack references in the way tromb means them. Not every body grasps OOP easily.

@tromb, Python avoids cross frame stack rebinding (your "references") on purpose, it causes cancer, we code differently.

You might want to give it a try, your PHP code will be improved this way too.

dougal@dougalmatthews.com said...

The ternary operator is not new... unless its being changed?

trombonechamp, Python implemented references by default. Just like PHP5 does with Objects, with PHP4 you needed the &

ferdhie said...

I kinda like the ternary stuff, make lifes alot easier and makes my code shorter;

I believe python also has ternary-like construct right?

(x == 1 and do1()) or (x == 2 or do2()) ...

anyway, i liked python better, for its "batteries included" ;)

kl said...

PHP was ment to be templating language, but fails at it miserably. For example to have persistent content of forms you need this monstrosity:

[?php echo htmlspecialchars(isset($_POST['var'])?$_POST['var']:'') ?]

and PHP apps are usually vulnerable to XSS, because nobody cares to write htmlspecialcharscouldntgetlongerfunctionname() everywhere.

Geeo said...

$id = $_POST['id'];
translate to python, with one line...

P.S: (php has post and get escaped, shhhhhhhhhht don't say that out loud)