SitePoint Sponsor

User Tag List

Page 3 of 6 FirstFirst 123456 LastLast
Results 51 to 75 of 136
  1. #51
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    Oh Dear...



    Well, you wouldn't have to edit anything, if you had a -BEEP- abstraction and an Interface to work with, would you?

    But of course... You don't have that luxury with procedural programming, do you? Tell me something, with all this editing of your files, exactly what are you doing? What are the possibilities huh?

    The possibilities of introducing new bugs... Alas, you are including a lot of 'module' files, so which file has the bug... A few hours later, after looking through God knows how many files, you may find the bug at some point during your working day.

    Sod that, that isn't software development





    I would think that it would make your life a damn sight harder and even more unbearable?
    No, it usually takes me about 2 seconds to find where the bug is because the error reporting tell me what line its on and I say "Oh its that file". It doesn't take forever, genius. It doesn't matter if you use OO or not, you still have to edit code, your class isn't going to fix itself if it has an error. OO is not flawless. My functions can be just as good as your classes.

    I'm not against OO and as I've said, I use it myself. I just don't like people who think its the only way of doing things.

    OO is one way of dealing with large codebases, functions is simply another way.
    Last edited by Archbob; Aug 3, 2005 at 17:52.

  2. #52
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bonefry
    From one point of view, you are right. From another you are wrong. It takes quite some time for a programmer thinking in procedural to think OOP and when he finally makes the switch, there is no way going back.
    I think the destinction I was making was about design. Any programmer can code using functions or classes. The mechanics of coding using classes is not difficult for programmers. It is the ability to do software design using more and better methodologies that distinguishes programmers. The first post in this thread shows that the programmer had a full grasp of how to implement code using classes. But that code used structured design rather than OO. The fact that there is an enabling tie between structured<->functions and OO<->classes is part of the confusion.
    Quote Originally Posted by bonefry
    And IMHO it's a mistake to consider OOP as an extension to procedural for better design. That's why we have UML. But then again, maybe I haven't understood you.
    Again, I didn't say the OOP extended procedural -- I said it provided expanded design possiblities.
    Christopher

  3. #53
    simple tester McGruff's Avatar
    Join Date
    Sep 2003
    Location
    Glasgow
    Posts
    1,690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aaargh here we go again. The OOP v procedural debate never seems to go away. There really is no debate, nothing to contest - but much to learn. There have been many topics on this already if you hunt around.

    Quote Originally Posted by Archbob
    My functions can be just as good as your classes.
    Polymorphism?

  4. #54
    SitePoint Evangelist
    Join Date
    Jun 2003
    Location
    Melbourne, Australia
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by REMIYA
    Wouldn't it be better, if they are placed in one huge file, compressed and then sent to the user? While the original modules stay for documentation and eventual updating and bug-fixing by the project admin.

    So one huge, compressed user file, and images
    Remiya, since I've found many of your posts to be informative, I would have assume that you're joking (the smiley leads me to suspect that too).

    Just in case anybody was taking you seriously -- and as a foil to Archbob's love of functions -- imagine one file with all the functions one might want to use for various requests made to a web site: say 500 functions. Imagine that 5-10 of these are used for any one request. Beause they're all in one file, most of that code is unused but that huge file still has to be parsed.
    Zealotry is contingent upon 100 posts and addiction 200?

  5. #55
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by auricle
    Remiya, since I've found many of your posts to be informative, I would have assume that you're joking (the smiley leads me to suspect that too).

    Just in case anybody was taking you seriously -- and as a foil to Archbob's love of functions -- imagine one file with all the functions one might want to use for various requests made to a web site: say 500 functions. Imagine that 5-10 of these are used for any one request. Beause they're all in one file, most of that code is unused but that huge file still has to be parsed.
    The counter to that line of argument is that file system operations can be significantly more expensive than parsing PHP code in a file you have already read, so you might be better off stuffing everything into a single file and always parsing everything. This line of optimization can equally apply to to classes in many different files as well as functions.

    As in all things with all things in optimizing code...it all depends.
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  6. #56
    SitePoint Addict timvw's Avatar
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    354
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by auricle
    Just in case anybody was taking you seriously -- and as a foil to Archbob's love of functions -- imagine one file with all the functions one might want to use for various requests made to a web site: say 500 functions. Imagine that 5-10 of these are used for any one request. Beause they're all in one file, most of that code is unused but that huge file still has to be parsed.
    Imagine one file with all the classes one might want to use for various requests made to a website: say 50 classes. Imagine that 5-10 or these are used for any one request...

    I don't think it's a good argument in a functions vs class discussion.

  7. #57
    SitePoint Evangelist
    Join Date
    Jun 2003
    Location
    Melbourne, Australia
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by timvw
    I don't think it's a good argument in a functions vs class discussion.
    Actually, you're quite right -- and I was being a bit unfair to Archbob who has said little about how he organises his functions in the filesystem. But my post was mainly concerned with Remiya's (admittedly tounge-in-cheek) post.

    Sweatje, I have a vague memory of someone like John Lim doing some benchmarking on filesystem operations. I suppose the question is whether the reading of a file takes more time or just the opening and closing. In his article about optimising PHP, John has only a little to say. He states that
    Accessing a hard disk can be 50 to 100 times slower than reading data from RAM
    but, of course, we're not talking about reading from RAM.

    Anyone got any figures?
    Zealotry is contingent upon 100 posts and addiction 200?

  8. #58
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by auricle
    imagine one file with all the functions one might want to use for various requests made to a web site: say 500 functions. Imagine that 5-10 of these are used for any one request. Beause they're all in one file, most of that code is unused but that huge file still has to be parsed.
    Now imagine this big file with 500 functions all of them in 500 files . The PHP parser opens every one of these 500 files . You must know that file IO operaions are the most energy and time-taking in any PC language including PHP.
    It is said that every class should be one idea, that is why every class should be in a separate file. But this is only for the developer. The average PC user would not even bother looking and managing your code. Also he gets startled seeing all these files.
    This is what I did with the open sourced RDLDB, I have compressed it into one file (resulting to 7kb compressed, no comments, no new lines, etc.), and I have placed the source in the documentation. So everybody who wants to take a look at the source can do it, with all the comments, neatly indented and colourized.
    So no 500 files => one compressed file for the average user, source in the documentation and the images, movies, etc. (if there are any).

  9. #59
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, if you look at any of the GPL script I release, its almost straight procedural code. The files are nicely named for the most part so its easy for newbies to edit. Try telling newbies to edit OO code, I'd never stop answering support tickets.

    For some of the other projects I do for cash, I tend to use more functions.

    In regards to the earlier post about the guestbook. Why would you want to go OO for something as easy as a guestbook? If its just a simple GB, functions really aren't even needed. Just pretty much 20 lines of code.

  10. #60
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by McGruff
    Polymorphism?
    Absolutely:

    foo.php:
    PHP Code:
    <?php

    function bluff()
    {
         echo 
    'foo bluff';
    }

    ?>
    bar.php:
    PHP Code:
    <?php

    function bluff()
    {
         echo 
    'bar bluff';
    }

    ?>
    index.php:
    PHP Code:
    <?php

    $bluff_module 
    some_or_other_business_check() ? 'foo' 'bar';

    require(
    $bluff_module .'.php');

    bluff();

    ?>
    But that is both specific to PHP, not nearly as flexible and requires no less work than OOP, so it's practically impractical. But proves the concept.

  11. #61
    FBI secret agent digitman's Avatar
    Join Date
    Sep 2004
    Location
    Work
    Posts
    697
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh man....... someone change this forum's name to 'Php Application Design Wrestling'.

    Dr Livingston and Archbob's debates are fun though

  12. #62
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BerislavLopac
    Absolutely:
    ...
    But that is both specific to PHP, not nearly as flexible and requires no less work than OOP, so it's practically impractical. But proves the concept.
    Unless you have an array full of some foos and some bars and you would like to have them all bluff. You are going to need to write some significantly more complex dispatching mechanism to accomodate that.
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  13. #63
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sweatje
    Unless you have an array full of some foos and some bars and you would like to have them all bluff. You are going to need to write some significantly more complex dispatching mechanism to accomodate that.
    Basically, you'll have to write the bit they wrote when they went from PHP4 to PHP5
    Hello World

  14. #64
    SitePoint Addict been's Avatar
    Join Date
    May 2002
    Location
    Gent, Belgium
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This thread has progressed faster than I've been following it, but just wanted to reply to Douglas' post (#24)...
    Quote Originally Posted by DougBTX
    The advantage of OO code is that if you can encapsulate that validation in the User class, so you don't need to duplicate the above validation each time you want to save a User object, you can just run it with $user->save();
    While I think we are both agreeing on the fact that syntactic validation is a good candidate for reuse, I wouldn't put it (the syntactic validation code) in the business object: Going on with the $user->save() example, we could say that a 'user' can be saved in different contexts.

    For example: a user signup and an update of a user record. To do those things, data has to come from outside of the application and in both cases that sort of data will be different, you cannot put all syntactic validation in the business object, IMHO, it would bloat it. Also, putting some basic validation outside of the object, would make it more unaware of the context in which it is saved, which I regard as a good thing.

    There are of course rules, which do belong to the business object (ex: a user must be over 18, ...) and they should go in there, or we'd be left with pretty useless domain classes But I very much feel that there's a difference; one is about validating user input, the other is about making sure that an object doesn't go in an invalid state. This is some of the stuff that has gotten me to think (well, just a little bit) about a PHP contract tool by the way.


    Edit: and just to hammer it home, that could be $user->save(), $account->save(), $post->save(), $article->save(), whatever you like, it would have the same $anything->save() interface. That's polymorphism, and you loose it if you make the validation external to the thing being saved.
    Sorry, but I fail to see how one would lose polymorphism?

    As an aside, I wouldn't want explicit UsernameRule or PasswordRules, I'd rather more generic IssetRule and LengthRule classes. You could always use custom ones, but those strike me as a better base set to have.
    Totally agreeing on the generic rules, I'd assemble them in different Validators and have $validator->validate($something); (which is why I fail to see how you'd lose polymorphism)
    Last edited by been; Aug 4, 2005 at 05:49. Reason: polymorphism instead of polymophism ;)
    Per
    Everything
    works on a PowerPoint slide

  15. #65
    SitePoint Addict timvw's Avatar
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    354
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by auricle
    Sweatje, I have a vague memory of someone like John Lim doing some benchmarking on filesystem operations. I suppose the question is whether the reading of a file takes more time or just the opening and closing. In his article about optimising PHP, John has only a little to say. He states that but, of course, we're not talking about reading from RAM.
    But, can you imagine an Operating System/FileSystem that wouldn't cache the files in RAM if they are accessed often?

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

    Quote Originally Posted by Archbob
    In regards to the earlier post about the guestbook. Why would you want to go OO for something as easy as a guestbook? If its just a simple GB, functions really aren't even needed. Just pretty much 20 lines of code.
    Could you post those twenty lines of code? I don't actually know what a guestbook does . if it's actually 100 lines then you are hitting the OO tipping point (for me).

    Regarding newbies not understanding OO, that is probably the only valid reason to eschew it for any reasonable project. It does take a year or two of suffering to become proficient (patterns, refactoring level).

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

  17. #67
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by been
    syntactic validation
    I think we are comming from totally different angles on this, can you explain what you mean by "syntactic validation"?

    Quote Originally Posted by been
    one is about validating user input, the other is about making sure that an object doesn't go in an invalid state.
    Can you explain the difference? From my perspective, those two things are really the same, because user input changes the state of objects. If that new state is invalid, I can spit errors back at the user.

    Quote Originally Posted by been
    Sorry, but I fail to see how one would lose polymophism?

    Totally agreeing on the generic rules, I'd assemble them in different Validators and have $validator->validate($something); (which is why I fail to see how you'd lose polymophism)
    Does that mean you have a User and a UserValidator? Or do you just have a generic Validator which you initialize when you need it like in Chris's example?

    Taking "the" example for polymophism:

    PHP Code:
    class Circle {
        
        function 
    Circle($radius) { ... }
        
        function 
    area() {
            return 
    PI $this->radius $this->radius;
        }
        
    }

    class 
    Square {
        
        function 
    Circle($length$breadth) { ... }
        
        function 
    area() {
            return 
    $this->length $this->breadth;
        }
        
    }

    $shape = new Circle(42); 
    And later, when you want to find the area, we use polymophism:

    PHP Code:
    echo $shape->area(); 

    If we take the area calculation outside of the Shape classes, much like talking the validation outside of the User class, you end up these two classes:

    PHP Code:
    class Circle {

        function 
    Circle($radius) { ... }

    }

    class 
    Square {
        
        function 
    Square($length$breadth) { ... }
        
    }

    $shape = new Circle(42); 
    Then, when we want to find the area, you need these classes:

    PHP Code:
    class CircleAreaCalculator {

        function 
    calculate($circle) {
            return 
    PI $circle->radius $circle->radius;
        }

    }

    class 
    SquareAreaCalculator {

        function 
    calculate($square) {
            return 
    $square->length $square->breadth;
        }

    }

    class 
    Calculator {

        function 
    setCalculator($calculator) { ... }

        function 
    calculate($shape) {
            return 
    $this->calculator->calculate(shape);
        }


    and this code to calculate the area:

    PHP Code:
    $calculator = new Calculator();
    $calculator->setCalculator(new CircleAreaCalculator()); //**
    echo $calculator->calculate($shape); 
    The line I've marked with ** is the problem line. If we assume that due to polymophism, $shape could either be a Circle or a Square, then we can't know whether we need a CircleAreaCalculator or a SquareAreaCalculator, but we have to write down one of the two, so we can't have polymophism.

    The trick would be to pass a $shape_area_calculator along with $shape ... and rather than passing two variables you might like to make it into one variable, just to make life easier ... so you might have $shape->area_calculator instead ... but then you only ever need to access it through $shape->area() so lets make $shape->area_calculator private ... and then you notice that you've got a bunch of infrastructure code you don't need anymore .. you trim it down ... then you are back at the code at the top of this post.

    Well, that's how I see it working out

    Later,
    Douglas
    Hello World

  18. #68
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For some of the other projects I do for cash, I tend to use more functions.
    Onto a nice little earner are we?

    As to your Guest Book, pretty comprehensiive is it? I too would be interested to see your Guest Book which comes under 20 odd lines of script.

    I'm looking for a laugh today you see...

  19. #69
    SitePoint Guru dbevfat's Avatar
    Join Date
    Dec 2004
    Location
    ljubljana, slovenia
    Posts
    684
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Some battles never seem to come to a conclusion

    I think terms like encapsulation and polymorphism should end this one, but for that, both sides should understand what the terms mean, which is obviously not the case.

  20. #70
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is basically a guestbook isn't it?

    PHP Code:
    <?php

    $content 
    file_get_contents('guestbook.txt');

    if (isset(
    $_POST['comment'])) {
        
    $content .= "\n ----- \n" $_POST['comment'];
        
    file_put_contents('guestbook.txt'$content);
    }

    ?>

    <h1>Guestbook</h1>
    <pre><?php echo htmlentities($content?></pre>

    <form action="?" method="POST">
    Your comment:<br />
    <textarea name="comment" rows="20" cols="20"></textarea>
    <input type="submit" value="add comment to guestbook" />
    </form>
    Under 20 lines including HTML

    Totally untested too!

    Douglas
    Hello World

  21. #71
    SitePoint Addict
    Join Date
    Aug 2005
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OFF TOPIC REPLY


    Quote Originally Posted by bonefry
    There is one problem with your statement. Should we stop using Linux because only God knows what incomplete idiots worked on it ?
    Of course not, because it is TESTED BY THE COMUNITY
    Comparing Linux distro(s) to badly coded PHP scripts floating around the Internet is not a valid comparison. Linux developers most times police their own development. There is no one entity that does the same for PHP.


    printf

  22. #72
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    backwards compatability for php4:
    PHP Code:
    function file_put_contents($file$contents) {
      
    $fh fopen($file'w');
      
    $fwrite($fh$contents);
      
    fclose($fh);


  23. #73
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


    And only in what? 3 lines... That is class

  24. #74
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Trimmed up (and working) example:
    PHP Code:
    $content = @file_get_contents('guestbook.txt');
    if(strlen($c = htmlspecialchars(trim(@$_POST['comment'])))) {
        file_put_contents('guestbook.txt', "$content$c<hr>");
        header("Location: http://{$_SERVER['SERVER_NAME']}{$_SERVER['SCRIPT_NAME']}");
    }
    ?>
    <h1>guestbook</h1><?=$content?>
    <form method=POST>
    <textarea name="comment" rows="20" cols="20"></textarea><br>
    <input type="submit" value="add comment to guestbook" />
    </form>
    OOP version anyone?

    Quote Originally Posted by sweatje
    backwards compatability for php4:
    PHP Code:
    function file_put_contents($file$contents) {
      
    $fh fopen($file'w');
      
    $fwrite($fh$contents);
      
    fclose($fh);

    Unfortunately no (locking).

  25. #75
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stereofrog
    Trimmed up (and working) example:
    Great. Nice tight example. OOP could be similarly small, but would show no obvious benefit at this point (as seems to be the case with all brief examples).

    To really have an impact of the procedural vs. OOP discussion, we need to start throwing features at the project. I'll lob in a few:

    * ability to vary persistance (i.e. choose to store in db instead of a file)
    * support for more fields (user name, url and email perhaps)
    * ability to add a comment SPAM filter
    * ability to notify owner of new posts

    ...
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.


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
  •