However, I stumbled across an article today from Gergely Hodicska explaining the new name space support in PHP 5.3:
Namespace support in PHP was a long-felt want feature. In PHP the main motivation behind adding namespace support to the language was to solve the problem of long class names. If you develop a bigger library, you have to use long class names to avoid naming conflicts, for example look at this monster: Zend_Search_Lucene_Analysis_Analyzer_Common_Text_CaseInsensitive.
From the version 5.3 you can group your code into namespaces. Different namespaces can contains classes, functions, constants with the same name.
Namespace support is great, and as a C# programmer who dabbles in PHP on occasion, I just do not understand how full time PHP programmers managed to stay sane without them.
That said, I do not believe that adding namespaces will be enough for PHP to maintain its lead as the most popular scripting language.
PHP has over 3,000 functions in its global namespace! Many of these functions are redundant, or extremely similar. Yet these functions do not seem to follow any form of naming schema or argument consistency.
For example, PHP has the following string manipulation functions:
strstr, strchr, stristr, strpos, strrchr, stripos,mb_strpos, mb_strrpos, strrpos, strripos, substr
While namespaces solve the issue of organizing your own code, you still have to deal with the creeping mess that is the global namespace.
My proposal?
- Reorganize all 3,000 functions into seperate namespaces based upon their functionality.
- Rename all functions to follow a consistent naming pattern.
- Eliminate redundant functions, or merge functions that are similar.
- Create aliases that allow legacy PHP programs to call the old functions
- Old PHP support should be configurable in PHP.ini, and calling depreciated functions should still work, but throw a warning.
- Audit all functions return types, and develop a consistent pattern.
If Zend does not take drastic measures to reorganize their language, then I believe PHP will slowly be replaced by its much more elegant competitors.
23 comments:
just let php die....
by the way, for a contender to beat PHP this contender must recognize how php grew, and what php's current strong points are.
I think solutions like rails or django are NOT the answer to beat php. The underlying language (ruby or python) would need to tackle this, and I believe both ruby and python _could_ beat php _if_ there is a focus on the www as one of the most important aspect on a modern language
PHP will be around for quite a while yet because it's easy to use and has a vast number of systems - particularly user-popular items like BBSs and control-panel style systems - that work on it.
You'd be unrealistic to even try refactoring all the existing functions. People would keep using the ones they are used to, the ones their systems are written in. Then, at some point you "turn off" backwards compatibility? It'll never happen - it's too great a change for the punters to go for it.
And PHP's main strength is it's ease of use (which is why it's main weakness is security). Many people who have "picked up" PHP don't have any other programming background and won't understand why you might want to restructure the code in any way, let alone make a change that will impact across your entire existing code base.
Namespaces are a feature many developers who happen to use PHP will welcome with open arms - but it won't make a big difference to "PHP developers" because they won't even notice.
You can't simply reorganize the entire global function structure. That is called making a new language. Sure people are leaving PHP for 'web 2.0' style languages (by which I mean fancy new languages for lazy people). But Ruby is useless large scale and Python's formatting makes you add declarations to make you are in the proper scope (something that you aren't supposed to have to do in Python). Eventually, those people will return to PHP (or Perl) after they realize those new languages are not quite as good as they were to begin with. Like the morning after you cheat on your girlfriend with that chick from the bar.
PHP does and will survive because it gives you what you need (not what you want) to write viable web applications plus a little more (I use PHP on my Windows and Mac machines for scripting). And PHP 6 is coming to reclaim its place in the market.
Here's a few programming tips: if you can't remember the functions, quit your programming job. If you can't conform to the language's syntax, quit. If you blame the language (any of them) for your failures, quit.
By the way, I'm not directly talking to the author of this blog. He isn't complaining about PHP, only postulating. This comment is for everyone else that might rip on PHP simply because they are poor programmers.
I've been programming for nigh on 11 years now, and PHP is the one language that I can truely say I enjoy writing.
I do C++ and Java too, but C++ wants to kill me everytime I look at it and Java just isn't very well suited to... well anything.
So coming from a strong programming I know how to write well, which is a real problem for me when 1) The vast majority of PHP programmers don't and write horrific code. 2) Due to this PHP now has next to no respect among programmers.
For me though PHP is a joy to write, as long as you take some of it's crazyness into account (disabling the effects of magic quotes, register globals and writing multibyte string functions for instance) it's not necessarily easy, but it mostly always does what you tell it to.
Saying that, the huge amount of worthless functions in the global namespace and the inconsistancies in the naming conventions and argument orders have always irritated me no end.
So yes, I 100% agree with your sentiment that all the functions should be put into separate namespaces.
If you noticed though, they started to do something similar by replacing a lot of functions with a number of global classes. (The XML class for instance used to be about 20 odd functions)
Also the fact that PHP6 removes things such as magic quotes and register globals can only be good, PHP is a little bit of a mess now, but they're making it better. There's no need to write it off just yet.
Looking at these problems i can not draw a parallel betwean php and javascript. In both cases the global namespace is poluated with all kind of stuff and in both the need for namespaces is obvious. Javascript developers already found a way around this problem with the help of JSON, i wonder if php couldn't create something similar.
In conclusion i think PHP is here to stay. Sure people are jumping on ruby maybe python, but that does not mean that php is bad or that it will die out.
This article is a piece of nonsense. The number of PHP developers are still rising and the number PHP jobs is rising faster than ever. PHP is finaly being used in lots of serieus projects.
PHP doesn't have a lot of functions which does the same. It has some extensions wich have the same purpose, where in most cases one of both is deprecated. The need for namespaces most come from all the different frameworks and libraries which won't play together.
Last having a new major release is a bad thing, because it means backward incompatibility. Look at the linux kernel, we haven't seen a new major release in ages, even more we've been on 2.6 for quite a while and according to linus that we last even a lot longer. I hope PHP 6 is the last major release ever.
adaniels: Stagnation is good for no one.
I have a different suggestion: implement autoboxing.
"string"->length == strlen("string")
$array->length == count($array)
This will make PHP feel much more object-oriented, and gives opportunity to rename all methods.
I think it's important to remember that PHP had this problem (and so, so many more) BEFORE and WHILE it became popular and still its growth has continued un-hindered.
Why do you expect it to go into decline when it is visibly *improving* as a language?
I think after a while the main post should be replaced with user comments.
I respect others opinion so i expect you to read my opinion with same respect.
My opinion could be a little forced since i used C fro too many years.
1) using namespace does not copress information. You still have to know the namespace and the function name so i guess it did not improve anything. More likely you will have to relearn what you know.
2) restructuring ? Better make a new language.
3) php die ? Not until it serve it's purpuse. As i uderstood it's purpuse it's not to code servers and other 200 Mb applications instead it's a server side part for html ..small stuff. And it does do it's job quite well for that.
P.s. I like php, anytime i have to write some small program where i don't need space and i use it 1-2 times i use php. But of course if you need classes and 4Gb memory then i recomand Java or C++.
"It is no secret that developers are jumping off the PHP bandwagon like sailors off a sinking ship."
That razy-biased nonsense alone makes your entire rant worthless. It's not secret? I haven't heard this, I certainly have seen it. People are not flocking away from PHP; a small percentage of people who cut their teeth in PHP are experimenting with new, young, not-yet-timetested technologies like Django. Just because a group of people have begun to praise Rails like it's the second coming doesn't herald the demise of PHP. In fact, if anything, it acknowledges its prevalence.
Your entire post is wishful thinking at best, but certainly unnessary drama. PHP is in no danger. It's installed in something like 80% of websites, it's easy to use, it's easy to learn, it's fun to write, and it's free.
I think the last anonymous comment said it all. PHP is here to stay.
Everyone wants to see PHP die, but hey if that happens it will be because the universe has decided that 30+ billion years of existence was probably quite enough - and went poof. ;)
Very few people are "jumping off the PHP bandwagon like sailors off a sinking ship". In fact many people are taking a vacation from PHP. Personally I've visited Ruby for the last year - absolutely fabulous language with some incredible tooling - and then went right back to PHP.
PHP has a secret weapon nobody else has mastered - your dog could learn it. It is so dirt easy, simplistic, and yet supporting of some semblance of OO that using it is a no brainer for many.
If anything, PHP feeds off the competition. Ruby gets Rails (one framework), PHP gets 10+ relatively good ones in the same period. Mostly because Rails really was a revolution, and PHPers got a little pissed at not having something similar ;).
Point is PHP is adapting. The screw up with PHP5 adoption rates really held things up since so few saw any reason to leave PHP4, but it's slowly getting there. Come PHP6, you better pray Ruby 2.0 comes out kicking :).
Your premise that PHP needs saving is faulty. Within its niche, PHP is doing quite well. PHP is widely available, hosting PHP apps is cheap and easy. There is a vast array of great downloadable open source software that people who don't even care about computer languages can use. Many internet businesses use PHP because, for all its faults, those faults are well known and the solutions are as well.
Your proposal would result in significant backward compatibility problems and is simply impossible to implement. Additionally, and here is the thing many CS type people don't like, the small inconsistencies that you highlight don't really matter that much in the big picture.
You can write a blog software in the best, most technically consistent and advanced language in the world and it still won't displace nasty old WordPress written in PHP. That's because community, attitudes, and availability matter more to project success than the order of the parameters on some function.
Oh crap, another guy shouting that '3,000 functions in its global namespace' is bad or good or whatever. The number of functions or anything else in the global namespace is truly irrelevant in any practical way for programmers. And the whole naming consistency nonsense is a tiresome argument that has been around since the advent of PHP and still does not hold water. Consistent to whom? Have any PHP programmers every really been confused by functions that follow the underlying library's parameter order?
Get a life! PHP certainly has flaws. Ask any professional PHP programmer if you want a list -- most are in the object model. Academic additions like namespaces may look good in language feature comparison checklists, but are in reality of much less practical value.
Every single one of those 3K functions is there for a reason, and as one Anon said, their structure and naming reflects existing, underlying libraries that newcomers to PHP may already be familiar with. Plus, a flat namespace makes possible the raw joy of "http://php.net/{function name}". PHP is effective because it's good glue, don't try to impose some silly expectation of "consistency" on it. My other languages are Python and Actionscript 3.0, and I find myself breathing a little sigh of relief every time I switch from one to another for any reason, each has its own core strengths.
Wow. Someone said that there's a good reason for 3000 global functions, and then someone else says that PHP is so easy your dog could learn it.
Then, another someone says that if you can't remember which of the 3000 function to use, you should quit. Yet another someone said that the documentation is easily available and that's a good thing.
What I hate most about PHP is how its developer community, by and large, thinks that the language's weaknesses are its best assets somehow. I had a similar argument with someone regarding the consistency of the x86 instruction set, and that one person used essentially all the same arguments as stated above. Holy logical contradiction, batman!
Wow, the commenters are nuts. I suspect anyone who thinks PHP is a joy to write has never used another scripting language. PHP is absolutely riddled with bad design decisions, inconsistencies, glaring holes, and poor attempts at copying other languages' features. It's only easy to learn and easy to use if "learning" now means rote memorization of hundreds of exceptions and weird behaviors. Perhaps brand new programmers will appreciate not having to actually learn anything to write software , but the language's design hardly encourages any good programming practice and everything that makes it "easy" just gets in my way.
I have yet to see anything that can be done in PHP but not in Perl, Python, and Ruby just as easily and usually more cleanly.
it's always funny to read "the death of X programming language" based purely on aspects of the language itself. It's a very cute, navel-gazing consideration on the part of programming geeks.
PHP will remain popular as long as:
- it is ubiquitously installed by default on just about every non-windows host
- it's just "on" (no need for setting up an environment, yada yada yada)
- you can do simpl easy quick stuff... simply, easily and quickly *and not have to be a programmer*
Scoff all you like guys. It does the job. And for every job, the right-ish tool. Ruby Python PErl etc etc... all great stuff. Pick your flavor and do the job.
It gets tiring listening to same rendition of "PHP is crap". Basic fact is that a lot of PHP developers are multi-lingual. I know Perl, PHP, C++, Java, Python and for the last year, Ruby.
Ruby is the most dangerous of the lot to PHP IMO. I did say it was a fantastic language. PHP keeps rolling on for a few reasons. 3000+ global functions are essentially irrelevant - I use maybe 50+ with any regularity, and the rest are a click away using the coolest invention for documentation ever: http://php.net/{function}.
Is it as OO as Ruby? God no! It's horrendous at times, even the operator sucks. And there's no base classes to manipulate! But PHP still has enough OO to make it productive, capable of TDD (and even BDD - I'm developing PHPSpec myself since it is an honestly cool Ruby innovation in rspec). The other stuff while very useful - is not essential.
Are it's frameworks brilliant? Sometimes/sometimes not - but who cares when you scrabble one together from a selection of dozens of truly awe inspiring libraries? Or replace components at will?
Is it hard to learn? Hehe, non-programmers can use it with little effort in hackish "echo" based scripts. It makes security suck, but do you really think a three day programmer would write a secure Ruby script? PHP's strength is a direct cause of its insecure perceived weakness. That it's capable of procedural programming just makes learning it easier.
Does it follow best practices? There are XP/Agile PHP developers (I'm one of them) but I will give it to everyone else that PHP does not follow the same trends as Ruby or Python here. More suckage :( and the one point I think PHP really loses out on...
Is it available?
Your kitchen sink probably has it installed...
php 6 on the way,so it will be having Namespaces,wait and see
http://www.w3answers.com
Wow. Someone said that there's a good reason for 3000 global functions, and then someone else says that PHP is so easy your dog could learn it.
Then, another someone says that if you can't remember which of the 3000 function to use, you should quit. Yet another someone said that the documentation is easily available and that's a good thing.
Nope, no "holy logical contradiction, batman." Here's why:
It's true that having 3000 functions in the global namespace isn't ideal from a theoretical perspective, but guess what? It doesn't hurt anything either. You don't need to know all 3000 functions to write very sophisticated applications. In fact, I doubt any developer is familiar with all of them. The learning curve to get started in PHP is much smaller than many other languages (especially, shudder, Java). If you can't remember the basic functions that you need for day-to-day development, then, yes, you should quit your job, because you apparently have the intelligence of a thumb tack. The basic functions aren't hard to learn (assuming you're willing to put even a modicum of effort into it). For everything else, there's the extensive, easily usable manual and significant developer community to reference.
Having those 3000 functions available to use if you want gives you built-in capability to do all kinds of things that you would have to search for an extension or library in other languages to do. (In one PHP application I can parse XML into a DOM, interact with a serial port, generate a PNG image, and process a credit card transaction without installing a single library.) The only other language I know that approaches the breadth of functionality available in PHP is probably Java, but it's a whole lot harder to use and a whole lot harder to set up properly.
The difference between, say PHP and Java/Python/Ruby, is comparable to the difference between London and Washington, for example. London just "grew up," so its streets aren't often neat and orderly, whereas D.C. was planned on a grid before it was built. Sure, there might be some advantages to an orderly street layout, but I doubt that's a reason anybody's taken into consideration when choosing a city to live in.
Oh, BTW, I know PHP (obviously), Perl, Java, ECMAScript, x86 assembler, C, C++, bash, Visual Basic, and a few other specialty languages most people have never heard of. I'm a developer for Cornell University as well as owner of a design/development firm.
Zsolt: did you know that javascript already has quite good support for namespaces? I suggest researching the subject before saying something embarassing.
Post a Comment