42 points · by davidcoallier · 15y ago · 54 comments
PHP faces a lot of similar discrimination that JavaScript did for the longest time. Sure, there are still criticisms for JavaScript but for the most part people have settled and realized that to make JavaScript good you have to write good code. Which is exactly the case for PHP.
The trendiness of PHP bashing exasperates the actual issues of PHP which can easily be abated with good practices.
We need a call for someone to get up and preach the best practices of PHP. And with that, a call for PHP Lint based on those best practices. There are a few individual attempts at providing JS Lint type analysis for PHP files but nothing from anyone with clout. We could use an official analyzer supported by recognized field leaders pushing quality coding practices.
For a server side language I would imagine a better solution is taking the good parts of PHP and creating a new language out of it. Its a very difficult thing to do, and attracting the top members of the PHP community will be challenging -- but could have a useful result.
I hate a lot about PHP, but it definitely has good parts. Python and ruby are great languages - but their style is completely different. I use PHP because there isn't a better alternative that "has the same feel."
I for one love PHP's natural templating ability, it's the main reason I use the language, but a lot of people think it encourages mixing business logic and presentation code.
Also, it has competing implementations with enormous corporations pouring money into them.
I doubt PHP would be in such a sorry state if it was in a similar situation.
isset($foo, 2)
Returns a parse error, even though isset looks like a function call and you're just passing it an extra parameter. sizeof(int, 2)
will return a parse error, because sizeof is an unary operator despite looking like a function (the parentheses are mandatory when using it with a type name). In PHP, isset is implemented as a "language construct", essentially like another operator.No, I got the exact same impression. PHP is a language that takes away all the fun in programming for me.
But I'm not saying that in a derogative way. Coming from C#, Java and Ruby, I feel that PHP is kinda fun and refreshing. The object model is quite simple, and I love the $$ (variable variable) syntax, and how 'reflection' is way simpler than any other language. It's language for hackers.
I've never heard this claim made, and it has been a long time since I've actually used PHP in any meaningful way. Care to expand on this?
I'd be interested in a comparison to Python's support for reflection, which is simple and pervasive.
Here's an example from the PHP docs on the reflection API, in the comments:
$a = new A();
$reflector = new ReflectionClass('A');
$properties = $reflector->getProperties();
$i =1;
foreach($properties as $property)
{
//Populating properties
$a->{$property->getName()}=$i;
//Invoking the method to print what was populated
$a->{"echo".ucfirst($property->getName())}()."\n";
$i++;
}
You have to instantiate another object to inspect the first one! Here's Python, just as an example. (Most languages would be simpler. As with most things, it would be difficult to find a language where reflection was more clunky than in PHP.) a = A()
for i, key in enumerate(a.__dict__):
setattr(a, key, i)
f = getattr(a, 'echo'+key.capitalize())
print(f())
On another thread somewhere, someone once suggested that PHP is actually Blub -- a fictional language whose immense and inherent superiority cannot be explained, only experienced.As a long time PHP dev, let me assure anyone who thinks that this is the case: in no way is PHP Blub.
These days, you find PHP almost everywhere. And how do you get to PHP? Let's assume we are in collage and want to write that next big website that's surely going to rule them all.
Now, we don't really know that much about all this "tech" stuff. But hey, I can hit "show source" in the browser. This must be easy. After a few baby steps with a WYSIWY(WishYoud)G tool, you decide to learn /some/ HTML for good. Once you figure that HTML alone can't do a lot, there's a somewhat native path to PHP.
You keep on reading tutorials written by others, who know as much as you or a little more. You are still on the cheap side, and need to keep tight on your money for that next big website you are going to write.
And the more you read the more enlightened you feel. Wow! I can actually do that and my dead cheap webhost offers PHP as well. Life is good.
Because you don't lack any minimal intelligence, you figure out how to write your next (big) website. You probably didn't succeed in writing the next FaceBook, but hey, you are now /one/ of the /web guys/. You probably think what you are doing is real fun.
There are then two paths you can take: - A: stick with PHP and feel enlightened all the way, when ever you learn some new trick, or - B: wonder if PHP is the only true real thing. You don't know C or some other "ancient" language, so you are still a little afraid. Perl seems to look a lot like PHP but it's syntax is confusing and no one of your friends on the forums you are frequenting is using it anyway. Then there is Python or Ruby. Wow those look strange. No curly braces for function bodies. Why do people here talk about templating? What's this about? Do I need that? PHP was so easy... Anyway, you are still curious and learn about this "other" way of writing webapps (that's what we are still primarily concerned with). Once you start to figure out that variables do /not/ have to start with $ to be valid, you wonder what else PHP might have hid from your novice learning? There is a lot more. Not necessarily PHP's fault. Just the lockin in that PHP mindset.
----
The basic problem with PHP (to me) is that I've seen it to be more a motel on the way to enlightenment. Some just find it too comforting to move on. Others, once they've passed it, rarely(ever?) come back unless someone else tells (forces) them to do so.
It would be far easier and more effective to simply create a new language based heavily on the good parts of php.
Here's what's going on. The Twitter API currently has two levels of permission: "read" (can access your data, which includes your tweets and followers even if you have a private account, and unfortunately also your DMs) and "write" (can update your account, including posting new tweets, adding new followers, creating new lists etc).
Most Twitter users were unaware that granting "read" access to an application gave that application access to their DMs. This was a problem. Twitter opted to solve it by introducing a new permission level, "direct messages", which is write-plus-direct-message access. They plan to remove the direct message ability from the "read" access.
To give developers time to fix any apps that this would affect, the switch-over date for direct message access is set to June 30th.
Up until that date, the Twitter OAuth authentication screen includes copy that tells you that the application will be able to access your direct messages until June 30th.
This does NOT mean that the application author intends to access them - it just means that the permission level you are granting gives them that ability up until the cut-off date.
This issue is a big problem for people like us ( http://lanyrd.com/ ) who use Twitter for authentication, because it scares away potential users. At least after the 30th we won't have to worry about the DM clause, but we'll still suffer from users assuming that we're going to tweet on their behalf.
Unfortunately, we need "write" access so that the follow buttons on our site work (Twitter's new JavaScript follow buttons aren't appropriate for our attendee directory because we show 20 people on a page: http://lanyrd.com/2011/europython/attendees/ ) - we also need "write" access for our currently-in-alpha Twitter list management features.
The best solution I can think of would either be finely grained permissions (so we could ask for list and follow access but not send-a-tweet access) or the ability for us to specify a reassuring message to be displayed on the Twitter OAuth screen clarifying our intentions.
Feel free to peruse the source, if you don't believe it: https://github.com/gwoo/phpneeds
PHP is an opensource project: volunteer!
http://news.ycombinator.com/item?id=2640756
Self plug: I cleaned up his original repo and put the patch against the official PHP git repo.
This was an attempt to generate awareness and that kind of behavior doesn't help anything.
I added "To die", because that's my honest opinion after having been a PHP dev since ~PHP3. Whether it's the language's fault or not, my experience with other people's PHP code is that anything big tends toward spaghetti except in a few well-engineered cases. Non-pasta is the exception that proves the rule.
People who actually know something about programming well, frankly, would not start new projects in PHP. Its only use to me is as a litmus test -- if your answer to "What do you think of PHP" doesn't include a significant critique of the language, I probably wouldn't like working with you. (Nor you with me)
That being said, I totally agree with you -- other people's PHP code tends towards spaghetti in the vast majority of cases. My take from this is that if PHP were to disappear tomorrow all these programmers building spaghetti would just inflict their level of skill on other platforms.
Technically, that's mostly true. Culturally and psychologically, I'm inclined to say it isn't. Just as you're more likely to leave things lying around haphazardly in a room that's already messy, you're more likely to write sloppy code in a sloppy codebase. When the language itself feels sloppy, it's damn hard to avoid that effect.
Sure, you can write good code in PHP, but why would you want to when there are so many other languages out there? The only reason I can think of is if you're selling a product to be deployed on shared-hosting websites belonging to customers.
This is the main reason I'm not doing web consulting!
I like to think -- informed by my own experience -- that PHP collects a disproportionate share of bad programmers because it's the easiest for bad programmers to use. Chiefly, it is possible to start writing scripts with not even a modicum of planning and forethought; you only need to know what your filename will be. So it stands to reason that they would move on to the new easiest language for bad programming.
Or maybe they would rediscover their passion for something other than web dev, go back to school and get English degrees.
I can hope, can't I?
I think it's a matter of culture, which is reflected in the language itself and in the community that surrounds it and writes code samples and OSS software.
See also: Rats flee a sinking ship.
PHP is great. What's with all the hate? It's a good tool for a certain kind of job, not the right tool for others. Big deal. There isn't a single language that you can't find bones to pick with. It's all about what you do with it and how you like to code. If you're comfortable writing server-side script in brainfuck, more power to you.
Some people want every language to be just like Java, so they can switch between languages with little to no effort -- never mind we'd have only Java in the end.
Some people want everything abstracted out, so no implementation details have to pe paid attention to -- nor leveraged, ever.
Some people won't believe a language supports something until there's a class explicitly named after it (``proper unicode support'' my ass -_-').
Some people believe an object wrapped around something will magically make it better (``a core object that represents the HTTP Request and Response'').
The list goes on...
Please let PHP remain PHP, at least let it retain the good parts :-)