140 points · by mappu · 12y ago · 157 comments
Well, there were other factors in play there. htmlspecialchars was a
very early function. Back when PHP had less than 100 functions and the
function hashing mechanism was strlen(). In order to get a nice hash
distribution of function names across the various function name lengths
names were picked specifically to make them fit into a specific length
bucket. This was circa late 1994 when PHP was a tool just for my own
personal use and I wasn't too worried about not being able to remember
the few function names.Queue "it's popular and therefore must be good" trolls.
"From the letter Q, abbreviation of Latin quando (“when”), marked on actor's play copy where they were to begin." - http://en.wiktionary.org/wiki/cue
Feels strawman-ish, I've never heard anyone say that. "It's popular therefore it is a legitimate language choice", sure.
I'm more inclined to believe Rasmus is trolling here. Sure, he used strlen, but it's too hard to believe functions were named with this in mind.
So yeah, it's true :).
> I'm not a real programmer. I throw together things until it works then I move on. The real programmers will say "yeah it works but you're leaking memory everywhere. Perhaps we should fix that." I'll just restart apache every 10 requests.
> I was really, really bad at writing parsers. I still am really bad at writing parsers. We have things like protected properties. We have abstract methods. We have all this stuff that your computer science teacher told you you should be using. I don't care about this crap at all.
(from http://axonflux.com/5-quotes-by-the-creator-of-php-rasmus-le...)
Seriously, the PHP hate gets old. It started off very much as a scratch to one man's itch. That man wasn't the best programmer ever (wouldn't even say top 10%, or even close), but he had an idea and executed it to make one of the most successful free products ever that has generated billions and billions of dollars for the world economy.
Can you say the same?
Those sites are popular in spite of PHP, not because of it. If Mark had been proficient in ASP instead of PHP, FB would probably be running .NET. It's not like anything early FB did was particularly impressive and relied on special language features. (Correct me if I'm wrong.)
That's an interesting thought. Has it? I wonder what a lot of websites would have used if PHP has not been around. I wonder if, overall, PHP existing has actually generated billions and billions of dollars in value.
Many of us "web devs" were running desktop windows and had never even used a *nix command line or studied programming beyond BASIC. CGI (perl) scripts were absolutely painful to install, much less write. Dealing with stdin just to get post variables? Python and Ruby were rarely supported as CGI, and there were likely no web frameworks back then that you could manage to install on a shared account. Besides, a lot us back then weren't programmers to being with, we just wanted a web site to scratch an itch. Programming was a means to an end, and I think the rasmus quotes support that.
Enter PHP(&mod_php). Open up your FTP client, rename index.html to index.php, edit to add Hello <?=$name?>, load up index.php?name=Bob in IE, see "Hello Bob", MIND BLOWN! PHP was easy to use, learn, and it came with a huge function library built in. It was a sandbox to play in. The barrier of entrance difference between cgi/perl and PHP was like GIMP to Windows Paint.
The number of web scripts available to use exploded after PHP hit the scene. Message boards, calendars, photo galleries, shopping carts, etc. Sure, a lot of the code written was horrible by today's standards, or even CS standards of then, but that's not the point. Websites were launched, communities were formed, products were sold. Sure phpBB, wordpress, and others code was not properly engineered, but where would the web be without the communities and blogs they allowed to form?
Facebook started on shared PHP hosting. The mediawiki script was created because Magnus Manske wanted to try out PHP. Yahoo actually chose PHP to replace their in-house scripting language over ASP, Coldfusion, and other proprietary options when using open source was a huge risk. Python and ruby were not even on the web radar when yahoo chose PHP. [1]
Now today we may look at the code derived from the era before python, ruby, svn, github, cheap easy VPS/VM access, when shared web hosting was the only PaaS, and look in horror, but the fact remains that PHP powers 75% or more of all websites on the internet today.[2][3]
To ask if PHP has generated value, is to ask if Windows has generated value. They may have been ugly, but they got us where we are today, and the PHP of today is not the PHP of 2000.
[1] http://public.yahoo.com/bfrance/radwin/talks/yahoo-phpcon200... [2] http://venturebeat.com/2013/05/17/google-app-engine-finally-... [3] http://w3techs.com/technologies/overview/programming_languag...
I'd say PHP is and has been popular more because it's easy to hire an army of self-trained "php developers" for peanuts than because it is a "good" language.
It being a "bad language" is irrelevant for someone who's end result requirement is a functional page over technological purity.
Disclosure: I develop mainly in C#
Informal fallacies don't automatically invalidate the argument either. Informal fallacies are rhetorical red flags: they predict problematic logic, because they're generally used in place of actual logic: but unless you're talking about formal fallacies, the argument can still be valid.
In this case, it depends entirely on whether or not you accept popularity as a valid metric for success or quality or whatnot: you're arguing whether or not the "P -> Q" premise is true or false, not whether or not the argument itself is valid. Because P is true.
You have to watch out for arguments from popularity, they don't prove or even suggest anything other than popularity.
We tend to overvalue good design just for good design's sake.
As for its popularity, well, that would be the "got out of hand" part.
I don't have an estimate, but it's an interesting question if you're going to argue in terms of economic impact.
A nice language makes for shorter, more expressive code, sure, but that's like having a fast car that handles well; it still matters more where you're driving it. If someone is making a trip with a caravan of a million rust buckets to a nice place, why would they care about some Porsche owner moaning about how that is all so very wrong?
If PHP developers complained all the time about how programming sucks, then you could maybe tell them to use a better language. But the PHP devs aren't really complaining, rather people who aren't even using it.
People use Wikipedia. I dare say Wikipedia improved a lot of lives a lot. Meanwhile, a gazillion static blog generators written in hip language of the day prove no real benefit over notepad, or this textarea right here. It's like making a trip with a handful of people to a place that's been explored by others decades ago, and then being bitter that nobody cares, and hating on the roaring party going on next door.
If you want to make language A or B more popular and better accessible when it comes to web hosting, write the killer app in it that nobody can do without, and which can't be implemented in PHP. That should be simple, since PHP sucks so much, right?
Lastly, is the HN code nice? I wouldn't even know, it's that irrelevant. The HTML it puts out sure is atrocious, but even that doesn't matter.
Never belittle other's work, especially when striving to discover that magic formula to success. All the posts on HN about "How we made X successful" and we brush off the obvious ones in front of our eyes? Ever stopped to think why a crappy X is popular? Maybe there is something to it.
Also not to mount on irony but keep in mind, you are commenting on a site that has the HTML syntax from the Geocities era (it has its reasons though).
2. ...
Seriously though, I've been trying to find out lately whether CGI is at all useful in this day and age, or whether if some well-designed scripting language that used the PHP style of run-time would be better to avoid using it.
There's not much info on CGI/SCGI in 2013 :'(
It might be better than Perl, but not by much.
Oh come on.
PHP is more evolutionarily fit than Perl in a handful of very important ways (I would illuminate, for example, function signatures and a pre-built object system, syntactically trivial nesting of data structures, and a newcomer-friendly out-of-the-box execution model).
That said, I wrote Perl for years as a hobbyist (still do, now and then), and have spent the last 6 or so primarily writing PHP. There is not a day that passes that I don't miss some aspect of the rich, expressive, elegant, sophisticated, and intellectually delightful environment that is Perl at its best.
It is a doomed and sinking continent, Perl, but if we let the considerable wisdom of its once-great civilization evaporate into trite dismissal, we as a culture stand to lose a great deal.
I always found PHP's insistence on the array() keyword annoying, and the mixing of associative and sequential arrays ambiguous.
Perl's data structures (in their simplest form) and JSON are very similar, and I think JSON is a fine format.
You're mostly right on the other points though. Although I do love Perl's use of signatures in some cases.
You can now write
$numbers = [1,2,3];
Or even $numbers = ['first' => 1, 'second', => 2, 'third' => 3];
I'd think the mixing of associative and sequential arrays are one of the key things that lowers the barrier to entry though.PHP The Right Way (http://www.phptherightway.com/) is a good place to start if you're curious what "modern PHP" looks like.
I guess there won't be much agreement here on HN, but this deserves to be recognized as an amusing and clever solution to a problem. Even if the problem is self created.
PHP is great for doing quick and dirty dynamic web pages. So what if it doesn't scale out to a million line program?
And a lot more besides (subtle plug for http://www.phpbeyondtheweb.com )
> So what if it doesn't scale out to a million line program
I've seen more that one PHP codebase of that size, happily (and maintainably) plodding along.
EDIT: It's true, it's not satire... check out e.g. lex.c in php2/php-1.99s.tar.gz
/* Command hash table
* The hash is extremely simplistic and just based on the length of the
* command.
*/
followed by all top-level functions ordered by string length.void IntFunc(char *fnc_name) { int i=0; int cmdlen = strlen(fnc_name);
while(cmd_table[cmdlen][i].cmd) {
if(!strncasecmp(fnc_name,cmd_table[cmdlen][i].cmd,cmdlen)) {
cmd_table[cmdlen][i].fnc();
break;Hello again, old friend.
Warn initially (few versions) and then raise exception/critical errors after. If developer isn't willing to update, chances are server isnt being updated either anyways.
(I say do it anyway. It's like IE6; give it a long grace period, then tell people they need to get with the program.)
I have switched from php long ago, but remember odd naming conventions and frequent switch of parameters.
For the hash table to be efficient, an algorithm that stores the elements has to evenly distribute them across the buckets. But instead of using a "proper" algorithm, a string length was used to determine in which bucket a function name belongs. To have the names evenly distributed, the names had to be of different lengths, even if that meant abandoning some naming conventions.