SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 40

Thread: Is PHP ugly?

  1. #1
    SitePoint Guru dagfinn's Avatar
    Join Date
    Jan 2004
    Location
    Oslo, Norway
    Posts
    894
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is PHP ugly?

    (Extracted from: Are PHP apps fundamentally data-driven? )

    Quote Originally Posted by Rasmus Lerdorf
    PHP is not about purity in CS principles or architecture, it is about solving the ugly web problem with an admittedly ugly, but extremely functional and convenient solution. If you are looking for purity you are in the wrong boat. Get out now before you get hit by a wet cat!
    The real issue is not "how ugly is the programming language?", but "how ugly is the code you write in that language?" PHP allows you to write beautiful or revoltingly ugly code.

    A couple of comparisons: The way object orientation has been implemented in Perl 5 is fascinating and minimalistic. It appeals to my sense of simplicity. But the resulting application code is ugly in the sense that you're forced to add stuff that shouldn't have to be there. Java is an attempt at purity, I guess, but the things you have to do just for bureaucratic reasons aren't always pretty and don't always contribute to the readability of the code.
    Last edited by dagfinn; Feb 25, 2004 at 06:25.
    Dagfinn Reiersøl
    PHP in Action / Blog / Twitter
    "Making the impossible possible, the possible easy,
    and the easy elegant"
    -- Moshe Feldenkrais

  2. #2
    SitePoint Guru
    Join Date
    Nov 2002
    Posts
    841
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The Eric Raymonds book that Harry quotes from in the other thread has an interesting take on this based on this article

    Quote Originally Posted by Eric Raymond
    Gabriel's central argument was about a very specific tradeoff between implementation and interface complexity, one which rather exactly fits the categories we have examined in this chapter. Gabriel contrasts an ‘MIT’ philosophy most valuing interface simplicity with a ‘New Jersey’ philosophy most valuing implementation simplicity. He then proposes that although the MIT philosophy leads to software that is better in the abstract, the (worse) New Jersey model has better propagation characteristics. Over time, people pay more attention to software written in the New Jersey style, so it improves faster. Worse becomes better.
    ...
    Gabriel himself, while sticking with the observation that ‘worse’ is more infectious and tends to win in the end, has publicly changed his mind several times about the underlying complexity-related question of whether or not this is actually a good thing. His uncertainty mirrors a lot of ongoing design debates within the Unix community.
    Richard Gabriel describes the MIT approach:

    Quote Originally Posted by Lisp: Good News, Bad News, How to Win Big
    The essence of this style can be captured by the phrase the right thing. To such a designer it is important to get all of the following characteristics right:
    • Simplicity -- the design must be simple, both in implementation and interface. It is more important for the interface to be simple than the implementation.
    • Correctness -- the design must be correct in all observable aspects. Incorrectness is simply not allowed.
    • Consistency -- the design must not be inconsistent. A design is allowed to be slightly less simple and less complete to avoid inconsistency. Consistency is as important as correctness.
    • Completeness -- the design must cover as many important situations as is practical. All reasonably expected cases must be covered. Simplicity is not allowed to overly reduce completeness.
    Richard Gabriel describes the new jersey approach:

    The worse-is-better philosophy is only slightly different:

    • Simplicity -- the design must be simple, both in implementation and interface. It is more important for the implementation to be simple than the interface. Simplicity is the most important consideration in a design.
    • Correctness -- the design must be correct in all observable aspects. It is slightly better to be simple than correct.
    • Consistency -- the design must not be overly inconsistent. Consistency can be sacrificed for simplicity in some cases, but it is better to drop those parts of the design that deal with less common circumstances than to introduce either implementational complexity or inconsistency.
    • Completeness -- the design must cover as many important situations as is practical. All reasonably expected cases should be covered. Completeness can be sacrificed in favor of any other quality. In fact, completeness must sacrificed whenever implementation simplicity is jeopardized. Consistency can be sacrificed to achieve completeness if simplicity is retained; especially worthless is consistency of interface.
    I think PHP represents the New Jersey approach. Consistency? not here. Watch out for that wet cat.

    Interestingly, the premise is that New Jersey programs propagate faster than MIT programs and I think thats true. PHP spreads on the basis of its simple hello world, the ease of deploying your hello world to the server, the wide availability, the low cost, and the fact that there aint no stinking data types to get in your way.

    The price for this, as in the interrupt handling example from the previous articles, is that the end programmer is saddled with a more complicated interface. (See PhpHttpResponseHandling for a comparison of PHP response handling interface versus java.)

  3. #3
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    The idea that worse propogates faster is something I seem to have used by accident. The SimpleTest interface is...well...simple is a kind way to describe it .

    What happens is that people are immediately dissatisfied with it and want to change it. Well, surprise surprise, there is a tutorial on how to do this. It is one of the most popular revisit pages in the whole site. Having done that, they fell they have more control. Not just confident enough to use the tool, but confident enough to have an opinion on it. And they then e-mail me too, so I get more feedback.

    I was deliberately sneaky here for different reasons. I used to teach people how to use Windows 3.1 a long time ago. I never showed them Word or Excel, but instead showed them how to change the wallpaper. Then I showed them how to use an icon editor to change all of the icons. Now everybody has an opinion on the right way to do their desktop, so discussion with each other would start and people would see each other saving files, etc. My job was easy.

    The Eric Raymond, etc. descriptions mesh with this.

    The path seem to be...
    1) Irritation leading to an opinion.
    2) Exploration only to find something quite primitive.
    3) Experimentation (this is the hard part).
    4) Customisation.
    5) Confidence and control, of a small section at least.
    6) An opinion about the internal structure.
    7) ...?

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  4. #4
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No. It's beutiful Learn to love it

  5. #5
    SitePoint Evangelist ghurtado's Avatar
    Join Date
    Sep 2003
    Location
    Wixom, Michigan
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know if this has anything to do with the uglyness of the language, but sometimes I really, really wish that PHP used dot notation instead of those ugly arrows (and no, I don't have a background in Java)

  6. #6
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @lastcraft Wonder if there's some kind of slogan there: "PHP - the itch you just gotta scratch"? First time I've heard the "worse is better" argument - it's almost scary.

    I used to teach people how to use Windows 3.1 a long time ago. I never showed them Word or Excel, but instead showed them how to change the wallpaper. Then I showed them how to use an icon editor to change all of the icons. Now everybody has an opinion on the right way to do their desktop, so discussion with each other would start and people would see each other saving files, etc. My job was easy.
    Wonder if a similar approach could be applied to PHP? Perhaps start by showing people parse_ini_file() and print_r().

  7. #7
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I bet if more people knew about print_r(), the world would be a better place (The PHP and Sitepoint world that is )
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  8. #8
    SitePoint Addict
    Join Date
    Aug 2002
    Location
    Ottawa, Ontario, Canada
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Lange
    I bet if more people knew about print_r(), the world would be a better place (The PHP and Sitepoint world that is )
    I have a custom function I used to use for in-script debugging:

    PHP Code:
    <?php
    /**
    * function to dump data for debug display

    * I got this function from the user-feedback section
    * for the print_r function on php.net.  It is very
    * useful for debugging.  It now features the use of
    * debug_backtrace to show exactly where and in which
    * file the dp() call is being made from.
    *
    * @param mixed $call variable to have its data displayed
    * @param string string to describe the data dump
    *
    */
    function dp($call,$cname='') {
      
    /**
      * @global boolean $debug variable to toggle debug output on or off 
      **/
      
    global $debug;
      if(
    $debug){
        echo 
    backtrace_header(debug_backtrace(),$cname);
        echo 
    '<pre style="text-align:left;">';
        
        if(!
    is_array($call)){
          
    $call=htmlspecialchars($call);
        }
        
    print_r($call);
        if(
    is_array($call)){
          
    reset($call);
        }
        echo 
    "</pre><hr/>\n";
      }
    }
    //end dp

    function backtrace_header($dbg,$cname){
      
    $subhead='';
      
    $heading='<br/><div style="text-align:left;font-weight:bold;font-size:small;">';
      if(
    strlen($cname)>0){
        
    $heading.=" :: $cname ::";
      }else{
        
    $heading.=':: Debugging Dump ::';
      }
      
    $heading.='<br/><br/>DATA:';
      
    $heading.='</div>';
      
      
      if(
    strlen($dbg[0]['file'])>0){
        
    $dbg[0]['file']=array_pop(explode('/',str_replace('\\','/',$dbg[0]['file'])));
        
    $subhead.="<br />file: {$dbg[0]['file']}";
      }
      
      if(
    strlen($dbg[0]['line'])>0){
        
    $subhead.="<br />line: {$dbg[0]['line']}";
      }
      
      if(isset(
    $dbg[1]['class'])&&strlen($dbg[1]['class'])>0){
        
    $subhead.="<br />class: {$dbg[1]['class']}";
      }
      
      if(isset(
    $dbg[1]['function'])&&strlen($dbg[1]['function'])>0){
        
    $subhead.="<br />func: {$dbg[1]['function']}()";
      }
      if(
    strlen($subhead)>0){
        
    $heading.="<small>$subhead</small>";
      }
      
      return 
    $heading;
    }
    ?>
    But a few months ago, I started using the xdebug module and made a slightly altered function to leverage the type colouring that xdebug does when doing a var_dump:

    PHP Code:
    <?php
    function vdp($call,$cname=''){
      global 
    $debug;
      if(
    $debug){
        echo 
    backtrace_header(debug_backtrace(),$cname);
        echo 
    '<pre style="text-align:left;">';
        
    var_dump($call);
        echo 
    "</pre><hr/>\n";
      }
    }
    ?>
    Perhaps they will be useful to someone...

    Cheers,
    Keith.

  9. #9
    SitePoint Zealot patrikG's Avatar
    Join Date
    Aug 2003
    Location
    Sussex, UK
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You tackle PHP in a very theoretical way. It was never meant to have anything like object orientation in it, it started off very much as a templating language. You touch on the improved OO of PHP5 - and yes, while it is going to be almost like Java, it will never be quite like it. After a couple of years of OO programming, I still think of myself as a beginner when I approach, for example, OO patterns - really fascinating. But, if PHP was a tree, you are grabbing the branches with your discussion, rather than looking at the root, as that is where the problem lies.

    What I find in the real world, I am working as a PHP developer, is that while PHP can be beautiful, it's roots are ugly. Mostly spaghetti code. For someone to learn how to display "Hello World!" on the screen would only take five minutes.
    Procedural programming is nice, but it lacks the abstractability, and thus the power of OO. The problem comes in you have to write pieces of software together: one OO programmer, one procedural programming/spaghetti-code programmer. The PHP he writes - I look at it, I understand it, I can't say anything, because those discussions have happened before and ended up in alienation.

    Strangely, though, I find that PHP is beautiful because it has evolved from that. PHP is evolving as we speak and that makes it a "living" language. I can't wait to get PHP5 RC1. OO - yes, bring it in, as much as possible, but do it organically, because everything else won't work.

    PHP ugly? You haven't seen beautiful, man

  10. #10
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In the past, PHP has been seen by those in big business, as being a language for the geeks - the non professionals amongst us.

    But after 2+ years, I've seen a few changes. But more so, I've seen a lot of peoples views on PHP change.

    It's growing, as a language and also as an acceptable development platform, and I'm not really just talking about PHP as being Open Source either

    You've just got to love that, ASP and DotNet cannot even touch it

  11. #11
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    My comment is this:

    Who really cares how pretty the code is as long as it is fast, efficient and produces good error-free results?

    That is the bottom line isn't it? If it works properly than fine. Once it is working, no one is going to see the code regardless of how "pretty" it is.
    Wayne Luke
    ------------


  12. #12
    SitePoint Guru okrogius's Avatar
    Join Date
    Mar 2002
    Location
    US
    Posts
    622
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by W. Luke
    My comment is this:

    Who really cares how pretty the code is as long as it is fast, efficient and produces good error-free results?

    That is the bottom line isn't it? If it works properly than fine. Once it is working, no one is going to see the code regardless of how "pretty" it is.
    However, "prettier" code makes maintenance a ton easier, which can never be a bad thing.

  13. #13
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Who really cares how pretty the code is as long as it is fast, efficient and produces good error-free results?

    That is the bottom line isn't it? If it works properly than fine. Once it is working, no one is going to see the code regardless of how "pretty" it is.
    Think that's sums up "the PHP factor". Discussions with Java/.NET types re. PHP typically end in "but it works" or "but I'm already finished" from the PHP side.

    That blog of Russel Beattie which is so quotable;

    What is it about PHP that makes it so good for web projects? On the face of it, it looks like half-*** Perl or or scriptlet-based JSP pages. I mean all the bad things we're supposed to be getting away from with MVC and JSTL is included in PHP. Yet, the language is used quite efficiently and well. Yahoo uses it for a ton of projects, all the best web-based BBS systems are written in PHP and now WordPress impresses as well.
    That's another summing point of view.

    You tackle PHP in a very theoretical way. It was never meant to have anything like object orientation in it, it started off very much as a templating language. You touch on the improved OO of PHP5 - and yes, while it is going to be almost like Java, it will never be quite like it. After a couple of years of OO programming, I still think of myself as a beginner when I approach, for example, OO patterns - really fascinating. But, if PHP was a tree, you are grabbing the branches with your discussion, rather than looking at the root, as that is where the problem lies.
    Very true. It's not just coding styles in PHP as well. Things also start to get awkward when you start asking things like "So can I really lock down PHP with safe mode?".

    But at the same time, it's nice to push the limits (no one else is going to discuss PHP design theory, if not those using it) and PHP4 works surprisingly well as an OO language. And because PHP is the itch you just gotta scratch...

  14. #14
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by HarryF
    Think that's sums up "the PHP factor". Discussions with Java/.NET types re. PHP typically end in "but it works" or "but I'm already finished" from the PHP side.
    Personally, I think my comment can be applied any programming language. The prettiest code is not necessarily the most efficient code. In my career as a professional developer over the last 10 years, I have seen code on all sides of the spectrum in dozens of programming languages. Some of it was horrible, some nice looking. None of that phases me. The most efficient code is the best code in my opinion regardless of its structure. For my website, I currently use PHP based scripts. However if something came out tomorrow that worked on the server better and more efficiently, I would switch to it.

    So take it as a pro PHP comment or not, but it was just a comment on programming in general regardless of language. I, personally, do not care what the code looks like whether it uses OO or gotos as long as it is efficient, quick and gets the job done. May not hold to your higher standard but since I don't work for you, it doesn't bother me.
    Wayne Luke
    ------------


  15. #15
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    I personally think it's hard to write ugly code with PHP.
    I'm not talking about in the grand sense, architectually, or anything like that.
    I'm just talking about looking at a file full of PHP code.
    With Perl, on the other hand, it's hard to not write ugly code.
    Close your eyes, and reach your hand out, and pick a random Perl script off the web somewhere, and look at it. It'll probably give you a headache.
    Do the same thing, except make it a random PHP script, you'll probably get less of a headache.
    I think that's why PHP took off the way it did. People could understand each other's code so much better than they could with Perl, so before too long there was 50 gzillion open source PHP scripts floating around.

    --ed

  16. #16
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  17. #17
    SitePoint Addict say's Avatar
    Join Date
    Sep 2003
    Location
    At work
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ghurtado
    I don't know if this has anything to do with the uglyness of the language, but sometimes I really, really wish that PHP used dot notation instead of those ugly arrows (and no, I don't have a background in Java)
    I can't agree more but if PHP were to use dot notation, they would have to seriously consider doing so as it might lead to code confusion in conjunction with the cocatenated. Well. perhaps to newbies.

  18. #18
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem isn't so much leading new PHPer's to confusion, more to do with backward compatablility, for example, if PHP5 was to have used Java like syntax, you couldn't have the backwardness that v5 finds acceptable, even if it is to a certain degree.

    It was talked about though

  19. #19
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In regards to porting your v4 OOP to v5 OOP that is

  20. #20
    SitePoint Evangelist ghurtado's Avatar
    Join Date
    Sep 2003
    Location
    Wixom, Michigan
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, its a pity that the dot operator is already used for concatenation. But I can live with arrows just fine, its only a side issue, really

  21. #21
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Here's a nifty tip - if you are wondering how clean the code in some application is, you can get a very rough idea just by setting error reporting to E_ALL. The number of popular applications that throw up 300 or more notices per page is interesting! It's all for careless things like undefined variables, forgetting to put quotes around string constants, etc. These are things that are likely to cause headaches at some stage during the application's development.

    The real test of how clean the code is, is to try and maintain the code - try to get to know how it works and how to modify its behaviour. In terms of maintainability I find that most PHP scripts I have seen fail miserably at this. One of the worst possible things you can do when developing is use a 'quick fix' or try to get an extra few percent of performance out of the application by using some ugly, ugly code.

    The argument that code can be as messy as you like as long as it's 'efficient' is a misguided assumption, and it is attitudes like this which cause some of the worst code I've seen. For starters, maintaining such code, even to make minor modifications, inevitably requires progressively uglier and uglier hacks thus reducing any benefit in efficiency that the code originally had. It also means the code is not reusable, and I would define code that cannot be reused or modified as the worst kind of 'inefficient', because the code is just near impossible to work with.
    [mmj] My magic jigsaw
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The Bit Depth Blog · Twitter · Contact me
    Neon Javascript Framework · Jokes · Android stuff

  22. #22
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    100 percent

    Anyone can knock out a web site nowadays. But that's not to say that everyone can do a half decent job of it.

    I do not care to remember the amount of times someone has asked to make changes to a site that uses spegetti code, and it's a job I loathe

  23. #23
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ^^ Agree also. There is no excuse for sloppy code, especially if the time was available to do it right. Most decent text editors can be set for auto indention, even converting indents to spaces and some IDEs have Tidy native. I often run phpCodeBeautifier, even on my own stuff, to make it more readable. I have E_ALL on at all times locally to force me to fix notices.

  24. #24
    SitePoint Zealot patrikG's Avatar
    Join Date
    Aug 2003
    Location
    Sussex, UK
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mtjo
    ^^ Agree also. There is no excuse for sloppy code, especially if the time was available to do it right. Most decent text editors can be set for auto indention, even converting indents to spaces and some IDEs have Tidy native. I often run phpCodeBeautifier, even on my own stuff, to make it more readable. I have E_ALL on at all times locally to force me to fix notices.
    There is truth in that, but I find time to be the greatest constraint. I was recently contracted to "finish" a project someone else had half-finished. Of course there was immense pressure to finish it on time.
    The code was tremendously ugly - no clear seperation of anything at all, logic and presentation was mixed, HTML & PHP, quotes where there shouldn't be any and tons of quick fixes.
    The problem was that it was half-finished - and I thought about cleaning up the mess, but decided against it and compromised quite a bit to finish it on time.

    As much as I would like to have had the time, explaining to clients why you need to totally re-code their project and thus increase their costs, is very, very difficult.

    From my experience everyone brings in their own toolkit and codebase to a project - some are good, but they are all quite different. Many times coders do not want to compromise on what they perceive is best practice (or rather "their" practice) - and that's exactly the problem.

  25. #25
    SitePoint Zealot sike's Avatar
    Join Date
    Oct 2002
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by HarryF
    Quote Originally Posted by rasmus
    9. Database abstraction is mostly a myth. There is nothing wrong with direct database calls' making use of all the tricks and cheats your chosen database has to offer, to tweak as much performance as possible out of it.

    10. Keep your base technology and building blocks simple. Stay with a nonthreaded Web server, and avoid complex frameworks and abstraction layers, to give yourself a chance to trace and debug any problems that may come up. Solving the Web problem is simple; don't try to make it hard.

    this made me think (again ) about my super hyper framwork stuff.


    Sike


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •