12 ms·
PHP functions originally bucketed by strlen, were renamed to balance length
- mistercow 13y agoSometimes I feel like Rasmus Lerdorf is going to come clean one bright April Fools' Day, and reveal that PHP was just a hilarious joke that sort of got out of hand.
- deleted 13y ago[deleted]
- jtreminio 13y agoYeah! Haha the joke's on Facebook, Wikipedia, Flickr, Yahoo! Answers, Photobucket, Digg (RIP), etc ... Those fools have been using a joke language and didn't even know it! 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?
- cmelbye 13y agoDoes the fact that it's used by large websites change the fact that it's a poorly designed language?
- unavoidable 13y agoDoes the fact that it's a poorly designed language change the fact that it's a useful one?
- koide 13y agoNo, but it certainly puts the importance of good language design in perspective. We tend to overvalue good design just for good design's sake.
- mikeash 13y agoIt puts the importance of good language design in perspective in two completely different ways, though! You're completely correct, but at the same time, PHP also stands as a stark warning not to throw things together with no design, lest your misshapen child end up being immortalized. PHP is simultaneously the best-case outcome and the worst-case outcome for a badly designed language.
- MichaelGG 13y agoIn what perspective? PHP doesn't have to bear the weight of many other programmers dealing with their suboptimal design decisions. A popular DB had an intentional feature that lost data on 32-bit builds. You might not get bitten until you've gotten plenty of data in it - it's still a terrible design that hurts everyone.
- Yver 13y agoYou'd have to qualify what "poorly designed" means or even what language you're talking about. In that mail, Lerdorf recounts his time writing PHP/FI nearly twenty years ago. It's like judging the current Linux kernel based on the early version Linus Torvalds was using in his lab around the same time.
- tptacek 13y agoThe filesystem layout on Linux was never pessimized in order to work around using string length (STRING LENGTH) as a hash function.
- shoyer 13y ago...except PHP still has htmlspecialchars as a core library function. If Linux ever had these some of warts, they were resolved long ago.
- ars 13y agoNo they weren't. Go look at the TTY driver if you need an example. Any place you interface with user code you are stuck.
- Iftheshoefits 13y agoArguments from popularity can be amusing when laden with sarcasm, but that doesn't make them valid arguments. 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.
- eksith 13y agoI'd argue that PHP has been popular because it makes hiring a developer optional for the vast majority of folks who want to put up a website. In the days before Facebook et al. Your options were Geocities and family or a cheap shared host with apache and PHP3-4. When the most sophisticated portions of a site were a gallery and contact form, the "put files here, done" methodology is pretty hard to beat. 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#
- judk 13y agoFacebook itself was PHP website thrown together without design!
- Iftheshoefits 13y agoI don't think we're saying different things. :)
- knieveltech 13y agoThere was a time (and it wasn't terribly long ago) that "self trained" developers garnered additional respect in the community because they had the sand to go in and learn a system under their own power instead of having concepts spoon-fed to them in class. Academically trained developers were known first and foremost for over-engineering otherwise simple tasks and typically required two to four years in industry to break of bad habits.
- saraid216 13y ago> Arguments from popularity can be amusing when laden with sarcasm, but that doesn't make them valid arguments. 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.
- kailuowang 13y agoI don't know if you can say that "those fools have been using it and don't even know it." It's hard to tell if they had a time machine would they go change that decision (to use php). Anyway I agree that there has already been too much time spent on this language, no need to waste more beating the dead horse.
- mehwoot 13y agothat has generated billions and billions of dollars for the world economy. 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.
- eru 13y agoPerhaps not in value, but in GDP?
- protomyth 13y agoNot sure what they would have used because it seems like no other language makes it quite as easy to install and start using. I get the feeling a lot of language designers don't really get that some poor sap has to get the language installed on the web server.
- felipellrocha 13y agoAny of the myriad of good languages available out there? Php is only easy to install because it comes pre-installed in most low-end servers out there. Without that fact, php is just as cumbersome to get started as any other language.
- protomyth 13y ago"Php is only easy to install because it comes pre-installed in most low-end servers out there. Without that fact, php is just as cumbersome to get started as any other language." It comes installed because it is easy to install. Someone had to install it and PHP is sure easy for any SysAdmin to get installed. It is easy to start because the PHP folks made it easy to get started. Look at the steps to get PHP installed versus other languages. Then look at what "Hello World" and a simple form take.
- fuzzix 13y ago> "Look at the steps to get PHP installed versus other languages" Not much different to getting CGI working. If you need it working well, FastCGI is as much effort as PHP-fpm. SUexec is as much effort as SUPHP. Any language could supplant PHP in terms of ease of deployment, there's little out there that doesn't have some CGI library to handle the mucky parts. Not that I am advocating use of CGI for anything non-trivial.
- jfb 13y agoWho cares? It doesn't make the language any better.
- PavlovsCat 13y agoAnd who cares about that, in turn? It's just the glue you write your data structures, objects and functions in. You can still write shitty code in a nice language, and you can architect something well thought out in BASIC. 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.
- mistercow 13y ago>And who cares about that, in turn? Anyone who has to maintain bad PHP code, for starters.
- PavlovsCat 13y agoIf any other programming language was as popular, there would be just as much bad code in it. Nothing about PHP forces you to write bad code, nothing about other languages forces you to write good code. Also, if PHP is really just sucky and offers no advantages, why not simply rewrite it in a better language? Surely the costs would ammortize quickly.
- eevee 13y agoConversely, I wonder how much time/money has been spent porting away from PHP, or working on stuff like hiphop? I don't have an estimate, but it's an interesting question if you're going to argue in terms of economic impact.
- mistercow 13y agoI'm not really making any strong comment about PHP's usefulness or anything. I'm just saying that many of the things that have happened in its development would sound like they came right out of the manual for INTERCAL, except that they're too over the top. As for its popularity, well, that would be the "got out of hand" part.
- MichaelGG 13y agoJoke is sort of on them. Every single article I've read with engineers at the big sites talking about PHP mainly deals how to get around PHP. All of the things PHP is lauded for making things "easy" are the exact things the big sites go out of their way to avoid. 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.)
- 0x0 13y agoOn the other hand, what about time-to-market and worse-is-better and good-is-the-enemy-of-perfect? Could it be other efforts in the same space failed (and you never even heard of them) because they wanted to do things "right"?
- MichaelGG 13y agoThat's more happenstance of what happened to be on-hand. It's unlikely using, say, ASP with VBScript, would have generated any sort of "better-is-worse" type scenario. A Windows 2000 server with IIS/ASP installed had the same time-to-market advantage as PHP.
- freshhawk 13y agoCrack cocaine is a very successful product that has generated billions and billions of dollars for the world economy. You have to watch out for arguments from popularity, they don't prove or even suggest anything other than popularity.
- themodelplumber 13y agohttps://wiki.theory.org/YourLanguageSucks https://wiki.theory.org/YourLanguageSucks
- gst 13y agoI like his quotes: > 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-lerdorf http://axonflux.com/5-quotes-by-the-creator-of-php-rasmus-le...)
- GhotiFish 13y agoIn a very strange way, I respect this man.
- nivla 13y agoI find comments like these interesting and at the same time ironic, especially on a sites like HN. I could think of 10 reasons why PHP is the "wrong" language but I could also think of 100 reasons why it made a successful one. Rasmus my not have created a perfect language but he sure did create one heck of a successful one which even the "elitest"/"perfect" language are still trying to catch upto. 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).
- GhotiFish 13y agoI would be very interested to hear those reasons.
- pessimizer 13y ago1. mod_php 2. ...
- GhotiFish 13y agophp prevents you from having a good page structure? I'm no fan, but that's going a bit far, don't you think? What's a rickety syntax and inconsistent naming have to do with page design?
- MichaelGG 13y agoCan you explain how, in any possible universe, using strlen as a hash function and choosing function named to bin on length in any way helps PHP, at all?
- GhotiFish 13y agowell I can think of a reason you might do that. It's dead simple, and you can easily predict the distribution, so you can choose names that have a relatively good distribution. Sure your first few buckets go empty, but at that point, you're overthinking it, NEXT SECTION!
- deleted 13y ago[deleted]
- skloubkov 13y agoWhile I understand why this was done (for the sake of comparability), I feel like its better to bite a bullet and slowly phase out broken functions over several versions. 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.
- jtreminio 13y agoNothing in this discussion mentions anything broken, though.
- Yver 13y agoIndeed, and the title is incorrect too. Function names were not renamed to end up different buckets; Their names were picked that way.
- Someone 13y agoWhat about usability? "I wasn't too worried about not being able to remember the few function names." certainly indicates that usability decreased. That may have set a pattern for it getting broken, eventually.
- skloubkov 13y agoThis. I was implying that length of the string should mean length in characters, not bytes. This could lead to broken code and would require programmers to keep in mind both. I have switched from php long ago, but remember odd naming conventions and frequent switch of parameters.
- damncabbage 13y agoWell, not really. Consider the (very common) case of a PHP-based blog, forums or shop being hosted on shared hosting. The latter gets an upgrades, and the site explodes. (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.)
- 13y ago
- mikeash 13y agoThe site is extremely slow at the moment. In case anyone has trouble accessing it, I managed to load it, and here's the relevant bit: 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.
- tptacek 13y agoThat can't possibly be true. I refuse to believe it.
- pygy_ 13y agoEither way, it's hillarious :-)
- zaphar 13y agoOh It makes complete and total sense. PHP was not a "language" originally. It was a collection of handy functions in Rasmus' toolbox. When it "graduated" to language, and I use that term loosely no one bothered to clean it up. No one bothered to clean it up is PHP's mantra and it explains everything that people hate about the language perfectly.
- MichaelGG 13y agoEven with the "PHP is a personal hack", it doesn't make sense. More effort goes into naming functions than writing a one-line xor "hash". 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.
- ma2rten 13y ago
- Tloewald 13y agoWell, points for honesty, I guess.
- kabdib 13y agoI've written a few thousand lines of PHP in the last year or so. Every time I do, I want to weep. It might be better than Perl, but not by much.
- smacktoward 13y agoLike Perl, PHP is a long-lived, heavily-used-in-production language, which means there is a lot of cruft that has accumulated over the years that's difficult for the platform developers to just slough off. But much like there is a Modern Perl movement that has coalesced around voluntarily cutting out cruft and using a much cleaner, nicer-to-work-width subset of Perl, there is a similar movement in PHP-land that's doing the same thing. PHP The Right Way (http://www.phptherightway.com/ http://www.phptherightway.com/) is a good place to start if you're curious what "modern PHP" looks like.
- forsaken 13y agoThose same arguments would apply to Python too, and it doesn't seem to have nearly as much cruft.
- smacktoward 13y agoTrue. But very few languages can claim to be as elegant as Python :-D
- anthonyb 13y agoWell, that was the parent's point: PHP, heavily used in production, godawful language. Perl, heavily used in production, godawful language, but at least it's not PHP. Python, heavily used in production, pretty good language most of the time. (It's refactoring effort is Python 3, but ended up not changing very much.)
- judk 13y agoJust ask a Go dev about how "elegant" they think Python is.
- girvo 13y agoI've always wondered if there was a place for a language that was properly designed, but copied PHP/php-fpm's execution model? It has beautiful horizontal scaling, but perhaps the long lived process model is better (ruby, go, etc) than PHP's "stateless" (as in, the app holds no real state itself after the request, it shuts down) per-req setup. Thoughts?
- igul222 13y agoSee CGI.
- girvo 13y agoActually, I've been looking at SCGI with Nimrod... ;) 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 :'(
- djmdjm 13y agoIt's amazing that, after all these years, PHP still has the ability to horrify me. Hello again, old friend.
- jamesbrennan 13y agoIs the PHP source from 1994 available anywhere? That would help determine if this is Rasmus's satire or not.
- mappu 13y agoIt's http://museum.php.net/ http://museum.php.net/ 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.
- abimaelmartell 13y agohttp://museum.php.net/php1/ http://museum.php.net/php1/
- snyff 13y agofrom php-2.0.1/src/lex.c 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;
- fprawn 13y agoThere's a lesson here about how sometimes it's okay to fit your data to your code. This was, afterall, in php for years without causing much, if any, problems for end users. 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?
- awestroke 13y agoExcept this was no acceptable solution. Instead of using a better hashing algo than strlen(!), the function names was chosen by length, leading to one of the largest and most criticised flaws of PHP: the inconsistent function naming.
- RobAley 13y ago> PHP is great for doing quick and dirty dynamic web pages. And a lot more besides (subtle plug for http://www.phpbeyondtheweb.com 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.
- dsego 13y agoFu*k it, ship it?
- ibudiallo 13y agoOk i will admit it, i didn't understand a thing. Would someone care to explain it to me?
- dsego 13y agoI'm not really sure if this is right, but my best guess is that script parsers use a hash table to map the name of a function to a function pointer or something. Hash tables enable fast information retrieval by some key (usually a string). By just knowing the key you immediately (or after some calculations) know in which bucket to search for the element. For details see http://en.wikipedia.org/wiki/Hash_table http://en.wikipedia.org/wiki/Hash_table. 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.