Gabe Sumner

Gabe Sumner

The RSS Feed URL cannot be found!
The remote server returned an error: (400) Bad Request.

Back to all posts

PHP: An Introspective Retrospective

I began using PHP in 1998 and used it heavily until 2004 when I discovered ASP.NET (C#).

I still maintain a few PHP-based web sites, but I will admit the bulk of my recent web development has been with ASP.NET (C#). If you do the math I have been a PHP programmer longer than I've been an ASP.NET programmer.

What the hell is a "NAMESPACE"?

Coming from the PHP-world, ASP.NET was a challenge. ASP.NET is comprised of strongly-typed variables, true OOP, namespaces, event-driven execution, web controls, compilation, etc. I spent weeks trying to accomplish simple tasks and failing. Many of these concepts were foreign to me. After reading many books & web pages, I eventually had an epiphany and all has been well since.

I will be very blunt, ASP.NET (C#) made me a much better programmer. PHP, by comparison, was a kids' toy. Each time I inherit a new PHP web site, I'm reminded of this. There is no formality or structure to any of it. Programmers will happily toggle into & out of HTML, PHP, Javascript and SQL. If they are really fancy they might even `escape` to the shell and toss in a few UNIX commands. All of this is done while magically creating and retyping variables without a second thought.

I have come to understand this is...retarded. Although it makes it easy for "newbies" to get things done, it does not lend itself to managing large-scale enterprise web applications.

   
LOOK WHAT I DID!!!!

This lack of structure makes the product an unmaintainable mess. Doing something as simple as adding a new bit of HTML becomes a "process". After spending 4 years with ASP.NET, "mixing my layers" now makes me feel dirty and compromised. For most PHP programmers I've encountered, they do this without a second thought; gleefully reveling in their chaotic mess like a small child experimenting with a bucket of paint.

Hey wait a minute; the problems you describe are caused by bad programmers, NOT PHP!

This is true...mostly. There are some amazing large-scale web applications that are using PHP. It's obviously possible to create good PHP code. However, the PHP language itself and the PHP culture does not actively require (or even encourage) "good form". This means "maintainable PHP" requires a high-degree of discipline from the programmer.

I did a Google search for "PHP best practices"; this was the first page found. The leading paragraph states:

One of PHP's greatest strengths can also be a great weakness in the wrong hands. I'm talking about its forgiving nature. One of the reasons why PHP has become so wildly popular is because it lets very inexperienced web developers build powerful applications without much planning, consistency, or documentation. Unfortunately, that means an awful lot of PHP code out there is sloppy, hard to read and impossible to maintain.

This is exactly my impression as well. The article goes on to describe various "good form" techniques for using PHP. Unfortunately, the article only focuses on making code more "readable". For example, it addresses why you should indent blocks of code. It does not really address how to structure large-scale PHP applications. To find information about creating an organized/layered PHP web application, I had to do a bit more searching. I found the following web page:

http://www.odi.ch/prog/design/php/guide.php

This is as close as I came to someone demonstrating "good form" with PHP. Although, I note the "require_once" function is needed to pull this off. Wow! Let me quickly say; PHP should be downright embarrassed that in the year 2008 they STILL don't have namespaces.

Adrian Holovaty of the Django/Python fame has a slide in his presentation (check the 11:00 minute mark) that is a screen-shot of the "reserved" PHP words for the letter "A". It always gets a good laugh from the crowd and effectively demonstrates the problem with having no namespaces. The absence of these "standard" language features is why the PHP language does not actively encourage "good form". Is it possible? Certainly, in the hands of a talented & disciplined programmer anything is possible. However, the programmer pulls this off in spite of PHP, not because of PHP.

In the end, I'm for whatever works. There may be a variety of reasons why PHP makes sense. Ultimately, it is important to understand the strengths and weaknesses associated with technology choices so you can craft the best possible solution.

Additional comments can be found here.

Facebook DZone It! Digg It! StumbleUpon Technorati Del.icio.us NewsVine Reddit Blinklist Furl it!

Comments  36

  • Jack @ The Tech Teapot 25 Feb, 08:52 AM

    Namespaces are coming in PHP 6 out this year I believe. Take a look at symfony it is a full MVC framework for PHP.

    Comparing the best practice in one language with the worst practice in another doesn't make a heck of a lot of sense. I'm sure you can make C# ASP.NET into a one layer mess if you really want to. And you can certainly code PHP to best practice.


  • Gabe 25 Feb, 08:55 AM

    Thanks for the comment Jack. I will certainly check out Symfony.


  • Jacob 25 Feb, 09:02 AM

    Namespaces are supposed to be in PHP 5.3 (they're being backported from 6).

    Symfony is a great PHP framework, just a little slow.

    All in all, the author is correct. PHP is a mess all around, and the mess is the source of PHP's popularity and problems. I'm a little amazed that you enjoy working with a static typed language. A good dynamically typed language (like python) is far easier to work with.


  • Gabe 25 Feb, 09:55 AM

    Hey Jacob. My introduction to ASP.NET (C#) was largely prompted by a work-related project that needed to integrate with the company "Active Directory." At the time, the choice of technology made sense. In the midst of this, I discovered a lot I liked.

    I have dabbled with Python and have always been intrigued. I haven't yet launched a "real" project with Python however, hopefully I will get the opportunity someday.

    Thanks for the comment.


  • Andreas 25 Feb, 10:27 AM

    What do mean with "true OOP" for ASP? What are the differences to PHP5?


  • bungle 25 Feb, 10:41 AM

    PHP is simple and more to the point. Java and C# (ASP.NET) are more about abstractions. PHP might seem like too simplistic way to do things, but I like it (retarded or not). Spend a little bit more time in .NET and Java lands and you see, that in those camps, over engineering seems to be a habit. Over engineering in my opinion is a lot more harmful than being too simplistic. In PHP you just get things done. In Java and .NET you are a little bit more focused on overall architecture and abstractions.

    > PHP culture does not actively require (or even encourage) "good form"

    That's true. But in the end PHP has a lot of frameworks build on it that try to encourage doing things in a "good form", whatever that is (just like you think ASP.NET Web Forms does or ASP.NET MVC does). C# does not encourage you to do anything in any manner (just like PHP as a language doesn't).

    PHP is getting namespaces, and I agree with you, that namespaces in PHP is a good thing, but not something that you cannot live without (at least I have not had big problems with PHP without namespaces).

    And PHP is a glue and it really works well as a glue. At least better than any other platform. All these (http://fi.php.net/manual/en/funcref.php, http://pecl.php.net/packages.php) are (mostly) high quality and well tested libraries. They are not always coherent and similarly designed, but they really work well on PHP. It seems like whatever you need to do in web environment, there is always an extension or a function for that in PHP. That's something that ASP.NET cannot provide. Yes, .NET framework has a lot of libraries, but using them is always more verbose than doing similar things in PHP. And the whole web is full of reusable PHP code (good and bad quality).

    Maybe I'm too defensive here... I admit that PHP has its quirks, but that's the way it is (nothing/no one is perfect after all). In the end functionality is what counts. A great architecture is worth nothing if the application doesn't deliver what it should. And a great architecture isn't something that is bound to some particular language or platform or framework. There is none such a thing as "good form". The good form is always in a changing state, it's not a nailed down thing. If you look for example C#. C# is starting to look more and more as a dynamically typed language with some functional language semantics. The borders are fading. Maybe C# isn't that beautiful after all (or maybe it's becoming bloated?) and maybe it's not something that can be called as a "good form" after a couple of years? Who knows?

    If you look at how web develops, you soon find out that PHP adjusts to web's changes very well. ASP.NET for example seems always lacking behind. Take for example Ajax. It took MS a good while to build a good ajax extension for ASP.NET (And support in VS was in by default in VS2008). In PHP AJAX was usable since day one and frameworks started to appear immediately. Or you could use any of those great javascript libs with PHP very easily. That's something that wasn't that easy with all the (needless?) abstractions that ASP.NET Webforms forced you to use. You could have dropped Web Forms, but then you would end up with a lot worse platform (or you could try out Monorail). That's a bad thing about abstractions, they make too many assumptions and then they leak.

    If you look this at open source point of view, I'll bet you that .NET is the worst platform currently. Ruby, python, php, c, c++ and java camps are a lot more active in this manner.

    Well, everyone has their own reasons to use whatever they want to. It was good to hear that you had PHP background. Maybe you just got tired with PHP and ASP.NET can be refreshing (something new to learn and master). Maybe you will get bored with ASP.NET after a couple of years.... maybe not... only time will tell... maybe you will start writing PHP again.


  • Gabe 25 Feb, 11:17 AM

    Hey bungle, what an incredible response! This is the type of "exchange" that is so useful when learning & pursuing the best possible solution.

    I don't really consider myself anti-PHP and would not be opposed to using PHP for a project. It it simply important to me that technology choices are made for a "reason" and not because of "dogma". When choices are made I believe it is important for everyone to understand the strengths & weaknesses associated with the choice.

    Beyond that, it's simply about creating the best solution possible. As long as this is the goal (and not using a particular technology), I'm happy!


  • Martin 25 Feb, 11:37 AM

    I am a .Net programmer and I have dabbled in PHP, and one of the first things I noticed with PHP was the mess you are speaking about.

    It's one of the most off-putting things about the languagwe - as soon as I see/have to maintain PHP code I cringe at the unholy mess of HTML/PHP and SQL strings everywhere.

    Another thing that I feel may be misrepresented in one of the previous comments is that PHP may have a great open source community, but so does ASP.Net - one of the great strengths of Microsoft's [platforms is the massive investments in creating community platforms that are large and well informed.

    As for libraries - I have never had a problem finding specialized libraries for free from the .Net community.

    Also, the most powerful aspect of the .Net framework is the fact that it's library is massive and has namespaces for all kinds of system/desktop specific functions which would be harder to replicate in PHP.

    Finally, the high-level of abstraction to true OOP coding and (should you require to) full binary compilation (no, not MSIL - you can develop fully managed binary libraries from Asp.Net code and the compiler to create DLL libraries) and create fast executing sites.

    Don't get me wrong, many great things have been done with PHP, and it's overall architecture is much more cost effective than a windows based app - but in terms of form and style, I feel Asp.Net and it's array of languages offers a cleaner coding experience.


  • Paul Hummer 25 Feb, 11:39 AM

    As an "experienced" PHP developer, I've designed, written and implemented some award winning frameworks in PHP. I'm also quite familiar with (and favor) other languages to develop for the web.

    I would say the low barrier to entry with PHP is a blessing and a curse. I've watched a friend of mine evolve into a pretty good PHP developer, just by watching him experiment.

    I will say, however, that when I pick up a new PHP project and start working with the logic code, there is an AWFUL lot of "boilerplate" code I have to write just for security and functionality. It's very annoying.


  • Jake 25 Feb, 11:53 AM

    Having moved from C++ & Java to C#.NET one the of first things I thought was WTF!
    Check out Partial methods and partial classes - there is no logical or sane reason why these things should exist, I have yet to find a sensible reason for either .
    I've not used PHP much, but it does feel like a poor mans perl.

    For my 2c I'd do a "big" site in one of the Java frameworks, a quick & dirty site with RoR or perl and anything speed dependent in C, Erlang for distributed computing - it's a dream.


  • maht 25 Feb, 11:57 AM

    PHP is the crudmaker, the only path is to grow from an awful PHP programmer into competent one, there's nothing in PHP worth learning, it teaches you NOTHING about programming except how to stop shooting yourself. And I've been doing it for 8 years, but the clients just won't go away.


  • Greg Jorgensen 25 Feb, 12:55 PM

    PHP has allowed a lot of inexperienced programmers to write mediocre code. In this respect PHP is like Visual Basic: the languages flaws are exacerbated by the majority of the programmers using it.

    PHP certainly has shortcomings, as does every language, but condemning it because it doesn't have some feature another language has is unfair and misleading. Take namespaces, a feature I am used to and would like to see in PHP. You write:

    "Adrian Holovaty of the Django/Python fame has a slide in his presentation (check the 11:00 minute mark) that is a screen-shot of the "reserved" PHP words for the letter "A". It always gets a good laugh from the crowd and effectively demonstrates the problem with having no namespaces."

    About half of those functions are array_xxx functions, which are more properly fixed by making arrays real objects, not by namespaces. Most of the rest of the "a" functions are namespaced in the sense that they have a distinctive prefix unlikely to clash: apache_, apc_, apd_, aggregate_, aspell_. Only a handful of "a" names without prefixes are left. And in PHP namespace collisions are not usually a fatal error anyway -- nothing bad happens if I make my own acos function.

    Just a couple of days ago I tried to use a Django site that should be a showcase for the framework (the PyCon registration site), and I ran into one problem after another that would be mocked as amateurish if the site was written with PHP.

    I use Python every day and have migrated applications from PHP to Python to get the advantages of the language and long-running server processes, but PHP has its uses and I still use it when it makes sense.


  • Greg Jorgensen 25 Feb, 01:05 PM

    As soon as I read that I noticed a mistake. I jumbled two thoughts into one sentence:

    "And in PHP namespace collisions are not usually a fatal error anyway -- nothing bad happens if I make my own acos function."

    Making a new clashing function will cause a PHP compiler error, so something bad does happen, but it's not a subtle untrapped runtime problem.

    Making a variable that masks a function isn't possible in PHP because variable names are prefixed with $. Compare that to what happens with this Python code:

    str = "foo bar"
    ...
    print str(someObject)

    Oops! Runtime error.

    I get the point about PHP needing namespaces, but Python has quite a few built-ins starting with "a" itself, and Python makes it a little too easy to mask a built-in without telling you about it.


  • Ryan 25 Feb, 01:23 PM

    Hi Greg

    You are right. Python has quite a few built-ins starting with 'a'.

    >>> l = dir(__builtins__)
    >>> len(l)
    134
    >>> [i for i in l if i.startswith('a')]
    ['abs', 'all', 'any', 'apply']

    I think I can remember those ones. ;-)


  • sili 25 Feb, 02:26 PM

    Some would say PHP is, "training wheels without the bike"


  • Greg Jorgensen 25 Feb, 06:04 PM

    Ryan, point taken, I didn't count them first. I'm not slamming Python, just the Pythonistas who slam PHP unfairly for a laugh.

    I count 122 PHP functions that start with 'a'. However of those, 60 are array_* and arrayobject_*, functions, 10 are apache_* functions, 9 are aggegrate_* functions, 14 are apd_* functions (a module that is not usually loaded), 8 are apc_*, 4 are aspell_*, and 2 are assert_*.

    That's a lame kind of namespacing, but it's good enough to count as namespacing for practical purposes, and at least demonstrates an attempt to address the problem. Of the 15 non-prefixed functions 7 of them are trig functions (acos, acosh, asin, asinh, atan, atanh, atan2) that should be in their own namespace, as they are in Python. That leaves 7 non-prefixed global 'a' functions: abs, addcslashes, addslashes, array, arsort, asort, and ascii2ebcdic.

    I don't think that's so bad, but it depends a little on which letter you pick. ;-)

    The accepted PHP solution is to use classes to create namespaces; that works fine if you are concerned about it. That won't fix the PHP global functions but it does let you separate your own functions.

    I have certainly been frustrated by PHP's polluted global namespace, but at least the compiler detects attempts to redefine a function, and the syntax disallows masking a function with a variable. I have been bitten just as often by Python letting me define a variable named "str" or "all" and then not telling me about it until a run-time error occurs.


  • Greg Jorgensen 25 Feb, 06:13 PM

    'Some would say PHP is, "training wheels without the bike"'

    Well there are lot more PHP sites doing business than Django sites. I would say Python (and Ruby) are fancy bikes without the pedals -- nice and shiny but a pain to deploy.

    The tool is not the problem -- in the hands of amateur programmers every tool is a blunt object. PHP is a first language for a lot of people, and the results are mostly equivalent to first short stories or first treehouses. The good thing about all of those PHP 'a' functions is that you can safely ignore almost all of them. If the number of global functions in PHP makes you nervous Python, or medication, may be needed.


  • Chris O. 25 Feb, 08:28 PM

    I can't tell you how much I agree with your post. The .NET framework (including the System.Web namespace, which is ASP.NET) blows everything else away. .NET is about productivity and extensibility. The speed at which I can develop ENTERPRISE-scale web applications in .NET--compared to PHP or Perl--is no contest. I'm not a PHP professional, but after 12 years in the web development ball game, I know a thing or two about languages.


  • starmonkey 25 Feb, 08:43 PM

    PHP's a mess, but it's like a messy bedroom - you always know where to find things (like clothes on the chair instead of in the dresser).


  • no religious wars please 25 Feb, 09:33 PM

    Nothing like a good language flamebait, you can write crappy code in any language, and there is crappy code written in every language, like this little Gem written in C#:
    ==============
    public static string RemoveCharsFromBag(string input, string bag)
    {
    try
    {
    for (int i = 0; i < bag.Length; i++)
    {
    if (input.Contains(bag[i].ToString()))
    {
    input = input.Replace(bag[i].ToString(), "");
    }
    }

    return input;
    }
    catch { return string.Empty; }
    }
    ===============


    Fact is there should probably be a programmers union that requires a competency test before an individual goes around passing themselves off as a programmer. As the old saying goes you need a license to drive a car but any old moron can claim to write software.


  • Josh in California 26 Feb, 01:51 AM

    Problem is, PHP lacks design and direction. It's one big mess. Example: on some platforms, functions like mail() will mysteriously fail. The problem? Some parts of PHP make use of crufty old standard library functions, which are limited to 255 open file descriptors. Once a process goes beyond 255 open files on such a platform, all kinds of PHP functions begin to fail. This is in spite of the fact that newer library functions are available that do *not* have this problem--some parts of PHP have been rewritten to make use of them, and others haven't.

    I won't use PHP for any serious project, simply because its implementation is inconsistent in quality and there is no design to speak of.


  • pcdinh 26 Feb, 03:03 AM

    Poor programmers often blame programming language for their weaknesses. I admit that PHP has a lot of flaws in its design but no one realize some of those. Almost people attack its clothes but not its body.

    Some said: "Oh, PHP is bad. It encourages mixing presentation and business logic" or "PHP is mess. It does not support MVC". A language "encourages" nothing except it does encourage incompetent people to leave programming jobs. How to structure a program is programmer and architect job, not language itself. Programming language is not framework, right?

    The rest said: "Programming in PHP is horrible. It does not support namespace or package. PHP pushes everything into global space." They are all inexperienced and not practical. C programmers have found the solution for ages. PHP has lot of global-space functions and built-in classes. You can prefix function and/or class name to simulate namespace. This solution has been applied in a lot of PHP frameworks and it works great. I am far from expert but I can say that if you are a good and disciplined developers, you will find that the lack of official namespace support in PHP is not a problem in practical cases. Syntax does not make a programmer become more disciplined.

    Please use Java, C# and Python and write everything into a class, a file or in a function and see what happens.


  • Jon 26 Feb, 03:06 AM

    PHP has many problems, some of which are being addressed (namespaces were to be introduced in PHP 5, but were delayed due to technical issues if I recall correctly, and are currently planned to be released in PHP 5.3.0 - see http://uk.php.net/manual/en/language.namespaces.php ), and as suggested most of the issues seem to stem from the programmers.

    I've been using a namespace "dodge" for quite a while; by using PHP 5 classes (I've no real experience with older PHP OO) as namespaced libraries. By having all methods within the class created as class methods rather than instance methods, and forming a constructor that immediately die()s when called, a (less than perfect) form of namespacing can be performed. For example:

    class A {
    function __construct() { die("Cannot instansiate library"); }
    public static function Foo() { echo "Hello "; }
    }
    class B {
    function __construct() { die("Cannot instansiate library"); }
    public static function Foo() { echo "World\n"; }
    }

    A::Foo();
    B::Foo();

    Namespace introduction in PHP is not going to be an immediate solution in any case however. For backwards compatibility the global namespace will still have to retain it's current crowding, and unless you're lucky enough to be able to dictate the version of PHP in use (which can be problematic if more than just your system is making use of it) then even when 5.3 or 6 eventually has namespaces we won't be able to make use of them until those versions are the versions that are in common use.

    Despite all the problems with PHP however it is often still the right tool for the job. Consider the server requirements for running ASP or JSP-based sites, or if you'll need to convince the system administrators to install particular Perl modules, or maybe even install an entire system like Ruby. PHP has won it's position as a wide-spread language not just because it's easy to develop, but because it's quick, easy and cheap to deploy.


  • pcdinh 26 Feb, 03:11 AM

    @Josh in California

    You said: "Some parts of PHP make use of crufty old standard library functions, which are limited to 255 open file descriptors. Once a process goes beyond 255 open files on such a platform, all kinds of PHP functions begin to fail."

    Could you please list some of those buggy functions? Perhaps you have used a unsupported and experimental extensions that may cease development for a long time. It is common practice. But it is good to know.


  • Searle 26 Feb, 03:11 AM

    There's still hope, there are some wise people working on
    PHP-internals:

    http://marc.info/?l=php-internals&m=119833623532713&w=2

    http://marc.info/?l=php-internals&m=120336491008719&w=2

    I use PHP daily for $job, and a IMHO totally underestimated fact is that it doesn't really care how good your language is, it's the TOOLS. The tools for PHP are awful. PDT is crap, PhpEd is, Komodo is (for PHP).

    The most important feature IMHO for an IDE is project-wide Code Completition (or Content Assistent) . It enables you to get into huge libraries really quick. My last experience was with jmonkeyengine, a BIG java 3d library, and I could just use it because the IDE practicly told me what to do.

    I tried to learn Catalyst for perl, which is a simply brilliant. But it took me ages to step into, because I was searching through the documentation. Code Completition would have solved the problem.

    It's a problem of the tools for many dynamic languages (don't know how groovy's tools are, have to test it...)

    Same for the PHP tools. If you're lucky you'll get hints for Classes or built-ins. But thats far from enough. Propertiy types, return value types, parameter types or local variables types are unknown and therefor ignored. It could be as easy as supporting best practices, one ought to code by convention. Something like
    "If you a add a comment, telling me the type of your variable, I can help you."

    So i think: if there were good tools that would support a set of best practices instead of trying to guess what the (amateur) programmer meant, the code would become better. Same as application structure became better with the rails-like frameworks.




  • pcdinh 26 Feb, 03:28 AM

    @Searle

    Tooling is not a strong point in PHP world. .NET, world of almost tool-dependent developers, is superior in this case.

    IMHO, PDT is good enough. You should check out the latest version and use it together with Aptana. That combination is excellent to web developers. However, code completion does not work without code documentation. It is a bit different from static typed programming languages like Java. You need to document your code carefully to make code completion support in IDE work.

    I often document my code as follows:

    /**
    * Move file to predefined destination
    *
    * @param stdClass $file File information
    * @throws Exception An exeption will be thrown when moving failed
    */
    public function moveFile(stdClass $file)
    {
    $targetPath = getcwd() . "/tmp/" . basename($file->uploadName);
    $tempName = $file->tempName;
    Pone_File::moveFile($tempName, $targetPath);
    }

    It would be a great help to code completion parser built in the IDE


  • Dave Regan 26 Feb, 08:46 AM

    I know you've said that a programming language should not promote bad programming practices but this really IS the programmer's fault and not languages. You could program any OOP and not use any object oriented concepts, and inject HTML anywhere and everywhere. You could create straight procedural code in c++, python and even ASP.NET (though visual studio forces you into an OO structure). The difference for you, as I see it, is that you were introduced to structure and the ideas of OOP in ASP and c# first, but you could have just as easily have been introduced to them in PHP. I think the main problem is that learning PHP is accessible and easy. As such there are way to many beginners out there advising other beginners and so you get a lot of really bad examples to learn by. I think if you look in to object oriented PHP you would be surprised. Of course, it doesn't have available the .NET framework, but that's another issue.


  • Gabe 26 Feb, 10:21 AM

    Hi Dave, great comment! There is a lot of truth to what you say.

    My article certainly acknowledged that a good programmer can (and will) make ALL the difference. But I continue to support my assertion that the PHP language and the PHP culture does not actively support best practices or modern/innovative approaches.

    Do a Google search for ".NET best practices" or "Java best practices". Look at the WEALTH of information available. Now compare to "PHP best practices".

    The #1 link that appears for "PHP best practices" is a page by someone who also wrote this:

    http://www.odi.ch/prog/design/php/index.php

    As I said, in the hands of a good programmer ANYTHING is possible; but why make things harder for yourself?


  • Josh in California 26 Feb, 01:11 PM

    "Could you please list some of those buggy functions? Perhaps you have used a unsupported and experimental extensions that may cease development for a long time. It is common practice. But it is good to know."

    You mean like mail()?

    I don't normally use PHP myself--I only try to support the poor webdevs who do, and the mail() bug on Solaris has been a pain in our collective asses for a long time.


  • Derek 26 Feb, 07:52 PM

    Dude, PHP is horrible, but you're claiming that ASP.NET is a great alternative? Jeeperz! C# is a pretty good language, but Microsoft's ASP.NET is only a half-step in the right direction, but then two steps backward.

    ASP.NET was better than plain old ASP, PHP, and ColdFusion because it pretty well enforced the separation of business logic and visual markup. But then they tried to graft an event-driven, stateful paradigm onto a platform that is stateless and has only one event - the HTTP request. You spend so much time trying to figure out which event to handle just to display text in a table or a form element. You end up telling the client to pass enormous hidden form fields back and forth just to keep track of what color a form control is. You force the user to download countless kilobytes of Javascript that do simple things like submit a form. Any time you want to break away from the Microsoft Way of doing things, you have to rely on hacks or hundreds of lines of custom code to implement your custom class.

    ASP.NET MVC is finally catching up with WebWork/Struts and Rails. More evidence of Microsoft innovation.

    There are countless MVC web frameworks for PHP, C#/VB, Python, ColdFusion, Ruby, and even Smalltalk. They're all much better than ASP.NET.


  • Gabe 26 Feb, 10:52 PM

    Hi Derek.

    I personally like the "event driven" nature of ASP.NET. I understand your point about the stateless-nature of HTTP, but I also understand that for years we have used technologies to overcome the shortcomings of HTTP and give our web sites the "appearance" of statefullness. This includes hidden form variables, cookies, sessions, databases, AJAX, etc.

    ASP.NET (and technologies similar to it) are just another evolution towards making our web sites perform like applications.


  • bungle 27 Feb, 04:59 AM

    "ASP.NET (and technologies similar to it) are just another evolution towards making our web sites perform like applications."

    Without fixing the protocol used in web you are basically hacking (well, another question could be that should the http be fixed in a first place? http protocol is so simple, and because of that it has enabled a great scalability). That's exactly what ASP.NET event handlers and view state is, hacks. Only few frameworks outside ASP.NET have taken similar approach. Most of the frameworks used currently in web space are Front Controller based MVC frameworks. Just like MS's new ASP.NET MVC framework is. ASP.NET MVC is a move back to the templating in a view layer (PHP has always been about templating (spaghetti or layered), so was ASP and so is Rails and most of the other frameworks). It's still interesting that ASP.NET MVC framework does have support for Web Forms concepts (ie. you can mix templating with user/server controls - that might be a great feature, at least that's something "new").

    ASP.NET has succeeded in enabling 3rd party component/control markets. Much better than anyone else. Can you for example buy Rails (or any other frameworks) components from 3rd parties? Probably, but the offerings are very limited compared to ASP.NET. This also means that to maintain productivity with ASP.NET framework, you should really spend some time and money on 3rd party libraries (if your business is not to write these libraries).

    Nobody can defend that PHP is not a lousy language in academic or language design point of view. It really sucks. But from pragmatic (or agile) or practical perspectives PHP looks a lot better. If you just can forget a second PHP's language or library inconsistencies, I think that it's more easy to live with PHP. You had learned a lot about programming and designing applications by doing ASP.NET. I did learn a lot by writing Java applications and studying many frameworks (I'm now SharePoint 2007 / ASP.NET developer by occupation and PHP developer by hobby). I had a time when I thought that I should go on and leave PHP behind, but I got a lot more wise over the years and I started to like PHP again. I might be a moron.

    When you compare ASP.NET with PHP you are really saying that you compare ASP.NET Web Forms with PHP. Web Forms is the thing that makes you believe ASP.NET is great. You could try to drop out Web Forms. ASP.NET without Web Forms is a similar platform to PHP. Without web forms you have to write very much boilerplate code to gain on productivity. Just like you have to do with PHP. You can write your own framework (just like MS has done with Web Forms, and now with MVC) or you could use a framework written by some 3rd party (and then you have a choice between FOSS and commercial). You could also choose a specialized framework (CMS for example) or you could probably combine several with your own glue.

    If you are not disciplined enough, you can always choose a framework that has strict policies, clean separation, hard coded (or configurable) conventions etc. And it usually can be a good thing if you have big project with many developers.

    So, let's stop bashing PHP because of it's language or library inconsistencies or other problems and let's start to argument about the real problems (ie. you cannot write a good net bank in PHP because it has a problem with {tell my why}, or that with ASP.NET I can really be {that} much more productive that writing stuff on framework X because {tell me why}).

    I agree that tools are a thing in which dynamically typed languages suck compared to for eg. .NET and Java (Visual Studio 2008 with ReSharper 4.0 or IntelliJ IDEA). For PHP there is some quite good IDEs: PDT, Aptana and Komodo IDE (and of course vi and emacs, ;-)), but sure they don't provide the same level support as the products mentioned above.

    What comes to OOP. Some people seem to think that it's the only true way to write software (I have for example written a layered front controller based MVC web framework without a single class/object). Well it might be, but it's also a much more difficult and more complicated to design great OOP libraries (than implement straight forward procedural functions, at least it seems that most people think procedurally by their nature). I have seen (and written) much more badly designed OO libraries than the really good ones. In that contrast, PHP's global functions look sometimes really good. And what about AOP? Functional programming is also getting talked about. And, oh yeah, plain ol' C is still going strong.


  • Gabe 27 Feb, 11:00 AM

    Hi bungle, another well written piece; thank you for posting. I accept your challenge of citing a specific example. However, I want to state again that I never said it was "impossible" to do something with PHP. Rather my concerns stem from PHP being inherently "messy" and "difficult" to work with.

    Without further ado, here is the project:

    Create a large (40+ field) multi-step registration form. A form where a user needs to enter a lot of information (conforming to varying criteria requirements), click "Next", complete more information, etc. The user should be able to return to previous steps in the form to update information if they later discover mistakes.

    Now, using ASP.NET, web controls, field validators and MultiView I can make VERY short work of this project. The gritty (boring) details are largely solved automatically. This allows me to focus on the "big picture". My "presentation layer" will consist of only HTML and web controls. No C# code will be visible at all. Behind the scenes I can use C# to modify the web objects that I have placed in the presentation layer. This is very clean, very fast, and very effective.

    Using PHP, on the other hand, I will be spending a lot of time writing code that merely deals with preseting HTML form field values. I will also need to write code to deal with storing information in hidden form fields so that I can maintain "state" between each "step". (This is the "hack" for compensating for the stateless nature of HTTP. Any solution to this problem, BTW, is a "hack". I don't understand why "ViewState" is any more or less of a "hack" than this.) In the end, my HTML will be littered with PHP code.

    Again, it isn't that this isn't possible with PHP. Rather my issue is that this is a lot harder than it needs to be. I love application design, I hate micro-managing minutia. If, due to performance concerns, I need to begin micro-managing these details, I can do that. But I see no reason to "default" to this. Computers are really good at performing mundane repetitive tasks; let the computer do what it does best.

    I know "control freaks" have a tendency to panic when layers of abstraction hide "details" from them. However, unless they program using only their "0" & "1" key they are already dealing with some layer of abstraction. Furthermore, that's okay.

    Well designed abstraction layers allow us to focus on "big picture" design issues. In my experience, this benefits the project & the programmer in numerous ways. It lets me focus on "creation", which is what I have always loved the most about my job.


  • asdf 28 Feb, 06:57 PM

    php 5.2.4 has namespace, fail.


  • kate 5 Mar, 05:48 AM

    I can't agree with you.PHP is good always
    http://www.w3answers.com


  • Adam Cox 10 Mar, 07:27 PM

    PHP is greater than ASP & .NET because it is free and open. You can't get the source for .NET. You can't get rewarded for contributing to PHP.


Post a comment!


HostMySite.com   website uptime