SitePoint Sponsor

User Tag List

Page 3 of 4 FirstFirst 1234 LastLast
Results 51 to 75 of 99

Thread: Method Chaining

  1. #51
    SitePoint Addict rvdavid's Avatar
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    233
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr L
    For the vast majority of PHP developers without a proper CS background, they are uneducated and yes, they are dumb.
    Harsh.

    Off Topic:


    Quote Originally Posted by Dr L
    People though, in general are dumb anyways;
    you've obviously been thinking about this subject matter for a little while


    Quote Originally Posted by Kyber
    But I definitely wouldn't use it as the default interaction with a RDBMS. SQL is a far superior for this.
    I am of the same opinion.

  2. #52
    SitePoint Enthusiast
    Join Date
    Mar 2007
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow I haven't seen this before..

  3. #53
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BerislavLopac View Post
    Sorry, but the whole idea of using OOP syntax to construct queries is a complete nonsense. Those are two orthogonal concepts, and they don't have much in common.
    i am agreed with above statement.

  4. #54
    SitePoint Zealot
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rvdavid View Post
    yes... you're right, but it's still easy. I see it more as escaping data is easy, not bothering is negligent.
    You have to remember that thanks to PHP's low barriers of entry, many coders who believe they're decent PHP developers have never heard of SQL injections.

  5. #55
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jasper Bekkers View Post
    The problem is broader than just SQL injection, think about arbitrary shell execution, cross side scripting, regular expressions that can be injected and every other "guest platform" (as defined in the StringBorg link I posted earlier). Yes, it can be solved using parametrised queries but that seems like an ah hoc solution to a general problem.
    I took a closer look at StringBorg. From what I can deduce, it's a generic template-engine, which escapes values for the target output. For some reason, it's embedded directly at the language level, but it might as well have been implemented as a library. As such, it's just a beefed up sprintf + array_map + relevant-escape-function.

    I think it's an interesting idea to treat all these different output types with a generic mechanism, but I question the reason for implementing it with its own syntax?

    Thanks for the link btw.; The related project, php-sat, looks very interesting.

  6. #56
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken View Post
    I think it's an interesting idea to treat all these different output types with a generic mechanism, but I question the reason for implementing it with its own syntax?
    StringBorg looks rather like a macro facility to me. If php had macros (or if someone wrote a preprocessor for php ), it would be handy to be able to write
    Code:
    $sql = "SELECT ... WHERE name=<<$name>> AND..."
    and have it automatically translated to
    Code:
    $sql = "SELECT ... WHERE name=".escape($name)." AND..."
    before compilation, i.e. at the macro level
    Thanks for the link btw.; The related project, php-sat, looks very interesting.
    +1. Really interesting stuff.

  7. #57
    SitePoint Zealot
    Join Date
    Dec 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Personally, I think it's extremely stupid, and very inefficient. For example, take a look at the following two lines:

    Code:
    $this->db->select('title')->from('mytable')->where('id', $id)->limit(10, 20); 
    
    mysql_query("SELECT title FROM mytable WHERE id = $id LIMIT 10,20");
    It's quite obvious which one is simpler, and cleaner to use. Not to mention the second statement doesn't have to go through a bunch of PHP code to generate the actual SQL statement. In my opinion, CodeIgniter pulled a Microsoft. They tried to make things so easy and user friendly, they only made things worse. Not to mention, what happens when you need to execute a more complex SQL statement, like say:

    Code:
    SELECT transaction.id FROM transaction,transaction_details WHERE transaction.id = transaction_details.transaction_id AND transaction.userid = 55 AND transaction.status = 'approved' AND transaction_details.index_id = 12
    Kiopa Software -- Demo Now Online! Check it out!
    Goal: Consolidate all data & tools you use on a daily basis.
    Grand opening special, licenses FREE for a limited time.

  8. #58
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bloody hell, there are other uses of fluent interfaces besides building SQL queries. How about discussing some of those instead of being redundant. Or did you miss the 20 other people that have said the same thing?

  9. #59
    SitePoint Addict rvdavid's Avatar
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    233
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by shea View Post
    Bloody hell, there are other uses of fluent interfaces besides building SQL queries. How about discussing some of those instead of being redundant. Or did you miss the 20 other people that have said the same thing?
    Chill out man, everyone's entitled to contribute.

  10. #60
    SitePoint Zealot
    Join Date
    Dec 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by shea View Post
    Bloody hell, there are other uses of fluent interfaces besides building SQL queries. How about discussing some of those instead of being redundant. Or did you miss the 20 other people that have said the same thing?
    Yeah, sorry about that. Sure, method chaining has some great uses, but not for generating SQL queries. That's just being stupid.

    It's kind of like when some developers use OOP for literally every aspect of their applications. They have no reason for doing it, except they think it's the cool and "professional" thing to do, and all the while, it lowers the quality of the application in many ways.
    Kiopa Software -- Demo Now Online! Check it out!
    Goal: Consolidate all data & tools you use on a daily basis.
    Grand opening special, licenses FREE for a limited time.

  11. #61
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    > Not to mention the second statement doesn't have to go through a bunch of PHP code to
    > generate the actual SQL statement.

    You are missing the point I think? The use of fluent interfaces to coin the phrase is to implement an approach that is more accessable from the view of the application developer, in the sense that not only making the use of fluent interfaces allows easier design, but the use of fluent interfaces expresses the domain.

    Looking at a SQL string does not express the intentions of what is happening in regards to a given domain; Also, not every developer is apt with SQL, even with moderately complex queries...

    Which leads me onto the point of more complex SQL, where there would be other, more ideal solutions; You use the tools for the job at hand, which is something that no developer should forget

  12. #62
    SitePoint Zealot
    Join Date
    Dec 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston View Post
    You are missing the point I think? The use of fluent interfaces to coin the phrase is to implement an approach that is more accessable from the view of the application developer, in the sense that not only making the use of fluent interfaces allows easier design
    Yeah, exactly. Frameworks such as CodeIgniter are supposed to make a developer's job easier, not more complex while adding an extra learning curve, and requiring the developer to write more characters of code.

    Quote Originally Posted by Dr Livingston View Post
    Looking at a SQL string does not express the intentions of what is happening in regards to a given domain
    And that method chaining example explains it better than a simple SQL statement how exactly?

    Quote Originally Posted by Dr Livingston View Post
    Also, not every developer is apt with SQL, even with moderately complex queries...
    Then they shouldn't be developing online database applications, simple as that. One of the things that irritate me the most about my job is when clients force me to work with their so-called "developers" and "server administrators" who have absolutely no clue what they're doing. Then I'm stuck baby sitting these people, explaining to them how they're supposed to do their job, just so I can do my job correctly.
    Kiopa Software -- Demo Now Online! Check it out!
    Goal: Consolidate all data & tools you use on a daily basis.
    Grand opening special, licenses FREE for a limited time.

  13. #63
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston View Post
    Looking at a SQL string does not express the intentions of what is happening in regards to a given domain; Also, not every developer is apt with SQL, even with moderately complex queries...
    That may be true, but then the abstraction needs to be done higher up than these examples. You need interfaces like:
    PHP Code:
    $users->getOnlineUsers(); 
    Not:
    PHP Code:
    $db->select('*')->from('users')->where('online'true); 

  14. #64
    Afraid I can't do that Dave Hal9k's Avatar
    Join Date
    Mar 2004
    Location
    East Anglia, England.
    Posts
    640
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When we were doing Visual Basic at school, one of the things I liked was the
    Code:
    with
    keyword. Basically it allowed you to create fluent interfaces without the need of returning a reference to the object.

  15. #65
    SitePoint Addict Mastodont's Avatar
    Join Date
    Mar 2007
    Location
    Czech Republic
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Really? With in VB is shortcut, eliminating a need to repeat object's name.

    Code:
    With object
       .Property1 = value
       .Property2 = anothervalue
    End With

  16. #66
    Afraid I can't do that Dave Hal9k's Avatar
    Join Date
    Mar 2004
    Location
    East Anglia, England.
    Posts
    640
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mastodont View Post
    Really? With in VB is shortcut, eliminating a need to repeat object's name.

    Code:
    With object
       .Property1 = value
       .Property2 = anothervalue
    End With
    Yes, that's what I was referring to, have a look at the comments in this blog post. Instead of returning $this in each method, with is used instead.

  17. #67
    SitePoint Addict Mastodont's Avatar
    Join Date
    Mar 2007
    Location
    Czech Republic
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is big misunderstanding. In PHP, lines

    PHP Code:
    $customer->newOrder()
    ->
    with(6'TAL')
    ->
    with(5'HPK')->skippable()
    ->
    with(3'LGV')
    ->
    priorityRush(); 
    are in fact
    PHP Code:
    $customer->newOrder()->with(6'TAL')->with(5'HPK')->skippable()->with(3'LGV')->priorityRush(); 
    But in VB you cannot rewrite lines

    Code:
        With ActiveCell
            .Clear
            .ClearContents
        End With
    as

    Code:
        ActiveCell.Clear.ClearContents

  18. #68
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I assume that the following:
    Code:
    With ActiveCell
            .Clear
            .ClearContents
    End With
    Translates to:
    Code:
    ActiveCell.Clear
    ActiveCell.ClearContents
    Yes?

  19. #69
    SitePoint Guru 33degrees's Avatar
    Join Date
    May 2005
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken View Post
    Yes?
    Yes, the "with" statement sets a default receiver for method calls

  20. #70
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Where is see the benefit in method chaining is image manipulation.
    PHP Code:
    $img = new Image('/path/to/some/image.jpg');
    $img->resize(100100)->rotate(-45)->stroke('black'2);
    $url $img->save('/path/to/new/image.png'); 
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  21. #71
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In my opinion, method chaining doesn't make much sense unless we're accessing objects hierarchically. The image manipulation above is much better done consecutively, as this is how this process is done.

  22. #72
    SitePoint Addict Jasper Bekkers's Avatar
    Join Date
    May 2007
    Location
    The Netherlands
    Posts
    282
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BerislavLopac View Post
    In my opinion, method chaining doesn't make much sense unless we're accessing objects hierarchically. The image manipulation above is much better done consecutively, as this is how this process is done.
    I haven't used fluent interfaces a lot, but I used it recently to make some code in my ray tracer more readable. Although the whole sequence (MoveTo/LookAt/Point/On) could be chained together, it really shouldn't because it doesn't read as well.

    Code:
    l_Painter.MoveTo(Point3f(0, 0, -10)).LookAt(Point3f(0, 0, -5));
    l_Painter.Paint(m_Scene).On(m_Canvas);
    The advantage of a fluent interface is that you can always decide between doing things consecutively or chaining them together. Normally in image processing however, you'll want to chain certain actions together because they have a relationship. Scale, rotate and move for example can all be combined and handled in one go through an Affine Transformation which is cool because you then have only 'slow' operation instead of three or four.
    Design patterns: trying to do Smalltalk in Java.
    I blog too, you know.

  23. #73
    Obey the Purebreed trib4lmaniac's Avatar
    Join Date
    Dec 2004
    Location
    Cornwall, UK
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    Where is see the benefit in method chaining is image manipulation.
    PHP Code:
    $img = new Image('/path/to/some/image.jpg');
    $img->resize(100100)->rotate(-45)->stroke('black'2);
    $url $img->save('/path/to/new/image.png'); 
    At first glance, that example looks like an excellent use of method chaining. But that is because I interpret the resize and rotate methods as returning new Image objects, whilst leaving the original instance unmodified.

    I am not sure whether or not I approve of the intensive uses of method chaining outlined in this thread (but I am sure that the SQL examples from the thread starter are atrocious). All I know is that I find jQuery a pleasure to develop with - jQuery being a popular JavaScript framework making extensive use of method chaining.

  24. #74
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    368
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A good example of method chaining i see regulary and use is jQuery for javascript

    so far i havent seen a good uses of chaining in php5, well theres zend filter, but in that particular case the examples are so convoluted makes me sick reading it, i like zend framework and use alot of the classes from it but not Zend_Filter

    it seems to me someone on the dev team wanted to be "cool" and they sacrificed readability for being "cool"

  25. #75
    SitePoint Wizard
    Join Date
    Feb 2007
    Posts
    1,274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To take an example from earlier in this thread:

    Code:
    $this->db->select('title')->from('mytable')->where('id', $id)->limit(10, 20); 
    
    mysql_query("SELECT title FROM mytable WHERE id = $id LIMIT 10,20");
    See if you can guess which one is suspectible to SQL injections?


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
  •