Пишет Dave ([info]dagbrown)
@ 2004-04-18 21:34:00
Previous Entry  Add to memories!  Next Entry
Настроение:accomplished

Yaywoo!

I'm now in the process of un-PHP-ing my web site. Now it uses eruby as its back end, and now all these little entries are stashed in YAML files (after being processed with a tiny script that uses REXML instead of being little snatches of PHP.

Here is an example of the reason I don't like PHP, incidentally. It seems to be put together by people who aren't really sure what they're doing.

First of all, PHP's system() only takes a string. It can't take an array, so you can't guarantee that the shell isn't going to find something objectionable in it (like a carriage return followed by "rm -rf $HOME"). That's just a little bit dumb. That little bit dumb is horribly compounded by the fact that there doesn't even exist a way to do a safe exec! If you were coding in C, instead of system(), you could do fork() and then execv() yourself, to guarantee what arguments the program gets. You can't do this in PHP at all. Instead, they turn this into an XY problem (<purl> They ask how to do X, but that's because they really want to do Y but think X will get them there and most of the time they are WRONG) and give you a helpful escapeshellarg() function. And another escapeshellcmd() function! The huge proliferation of different functions to do more-or-less the same thing with minor variations is the subject of a different rant about PHP.

Second, there's that crazy second parameter! Why arbitrarily take the thing that you normally expect to be the return value from system() and put that into a second parameter that gets set by system()? Why not just make system() return that? That's crazy.

But system() does return something! It returns...the last line of output from whatever you just ran. How could that possibly be useful? It'd be useful if you wanted to capture all of the output (but that's a different function--passthru(). Bad spelling in the API is yet another rant).

I'm trying to imagine the sort of programming that would result in capturing only the very last line of output from a command. It seems to be, "Well, we could capture all of the output, but the command might print out a lot of output, and use a lot of memory! And then we'd have to spend a lot of time growing an array or something! Why not just capture a line at a time and then overwrite that line each time, and then return the last capture?" It's just programmer laziness.

While I was poking around, I also found this.



(Добавить комментарий)


[info]superherobear
2004-04-19 06:39 am (local) (ссылка)
This..

was not a good example of things to try and read while drunk. For the record.

(Ответить)


[info]gonoph
2005-11-18 01:25 am (local) (ссылка)
hah! I found your LJ via this link chain:

http://www.bitstorm.org/edwin/en/php-sucks/ ->
http://tnx.nl/php

I'm thinking about converting some php stuff into perl myself. I just need to find a good templating system. Any suggestions?

(Ответить)


(Добавить комментарий)

Привет, [info]anonymous!
Стань платным пользователем