• K2TheX (unregistered) in reply to WhatTheFrank
    WhatTheFrank:
    graybreard:
    I have a friend.. who's a brilliant programmer. The only problem is, he's good at solving extremely complicated issues. But not easy ones. So he turns easy ones into complicated before solving them.

    Based on your description, your friend is not a brilliant programmer. It takes a pretty shoddy programmer to be unable to solve easy problems without turning them into complicated ones. The brilliant programmers are the ones who can take extremely complicated problems and break them down into easy ones, then solve those.

    +1

  • Nobody (unregistered)

    FYI: This is the Propel Criteria class: http://propel.phpdb.org/trac/browser/trunk/runtime/classes/propel/util/Criteria.php

    Seems to be the inspiration.

  • Leo (unregistered)

    LOL. The Real WTFs are Jason's comments. Missed out on "reading comprehension" in school, did you?

  • Dirge (unregistered)

    Hey, I want to thank everybody who mentioned Propel, because reading the canonical version of what this WTF was copying (poorly) was even funnier than the actual article here. Bonus points for thinking that such a ridiculous level of abstraction and mess of code is actually easier to work with than just writing SQL. I suppose it's good to know that while some things may change, PHP will always be the ghetto of code, with its own bizarre customs that are incomprehensible to outsiders.

  • jejacks0n (unregistered)

    He's a pussy for not using the output buffer at all there. String concatenation is so slow, and he should've been optimizing that abstraction from the beginning.

  • bigeoino (unregistered)
    selectBeans($this->getOvertimeAvailabilityBeanDefinition(),$c);

    Was paula involved in this too?

  • ohmy (unregistered) in reply to Jason

    I try to avoid web-development in general and PHP in particular like the plague, so I couldn't care much less about a PHP extension designed for SQL building.

    Expecting WTF commenters to have heard of Propel seems a bit much to me...

  • @Deprecated (unregistered) in reply to ohmy
    ohmy:
    I try to avoid web-development in general and PHP in particular like the plague, so I couldn't care much less about a PHP extension designed for SQL building.

    Expecting WTF commenters to have heard of Propel seems a bit much to me...

    That is not a stretch at all. We here at TDWTF are experts on EVERYTHING related to computers, as evidenced by postings in these forums.

    Let's say we were to form a company and bid on a contract for a complete integrated solution including design from the ground up - we would design, build, and program the BEST %$#$@ SYSTEM IN THE WORLD!!! Mwa ha ha.

    That is, if we ever stopped bickering over stuff like how to format date strings.

  • (cs) in reply to Jason
    Jason:
    AND TO FURTHER RANT - The goddamn submitter should have KNOWN because every fucking file is prefixed with a gigantic disclaimer, license, and url to propel.phpdb.org AND a plain as day explanation of what it does. WITH FULL PHPDOC COMMENTS.

    If all of that were, for some VERY strange reason, stripped from the files, THEN, perhaps MAYBE that is "TRWTF" ™

    hahahaha, wow. someone has their panties all in a wad. read the article. also, are you the lead dev for Propel or something? CALM DOWN MAN! BREATHE! ITS GONNA BE OK
  • ohmy (unregistered) in reply to @Deprecated
    @Deprecated:
    That is not a stretch at all. We here at TDWTF are experts on EVERYTHING related to computers, as evidenced by postings in these forums.

    Let's say we were to form a company and bid on a contract for a complete integrated solution including design from the ground up - we would design, build, and program the BEST %$#$@ SYSTEM IN THE WORLD!!! Mwa ha ha.

    Oh yea right I totally forgot, how could I be so silly! My humble apologies to the community. So can we use XML in that new system?

  • Bob (unregistered) in reply to ohmy
    ohmy:
    @Deprecated:
    That is not a stretch at all. We here at TDWTF are experts on EVERYTHING related to computers, as evidenced by postings in these forums.

    Let's say we were to form a company and bid on a contract for a complete integrated solution including design from the ground up - we would design, build, and program the BEST %$#$@ SYSTEM IN THE WORLD!!! Mwa ha ha.

    Oh yea right I totally forgot, how could I be so silly! My humble apologies to the community. So can we use XML in that new system?

    As a configuration file for which .csv files to load, of course.

    Real SQL coders do all the work in TRIGGERs.

  • (cs) in reply to Jason
    Jason:
    AND TO ADD To my extreme disbelief, apparently the rest of you knuckleheads don't know it's Propel either.

    Good god.

    yes, because we're ALL supposedly to familiar with EVERY NON-STANDARD* php extension.

    Not only is your extension not in the standard extensions, it's not even LISTED http://us3.php.net/manual/en/extensions.membership.php

    Give me a break bonehead, i bet you're one of the Propell authors trying to plug your crap.

    • by standard i mean "core" or "bundled"

    In short: STFU

    Addendum (2009-06-15 13:23): Oh btw Jason, after looking at the actual implementation

    I was a professional LAMP developer for 18 months and I've done a lot of personal LAMP development

    1. Pick an accurate class name
    2. Learn to implement that functionality efficiently. I've seen the same functionality, more usably and more understandably coded in less than half that space.
    3. [Shatner]Stop. Over. Complicating. Every. Farking. Thing. Under. The. Sun. To. Make. A Scripting. Language. Look. Like. A. Compiled. Language.[/Shatner]
    4. Xanax
    5. Valium
  • GrumpyYoungMan (unregistered) in reply to WhatTheFrank
    WhatTheFrank:
    graybreard:
    I have a friend.. who's a brilliant programmer. The only problem is, he's good at solving extremely complicated issues. But not easy ones. So he turns easy ones into complicated before solving them.

    Based on your description, your friend is not a brilliant programmer. It takes a pretty shoddy programmer to be unable to solve easy problems without turning them into complicated ones. The brilliant programmers are the ones who can take extremely complicated problems and break them down into easy ones, then solve those.

    Some of us can't be arsed to solve simple problems, regardless of what the user wants. So, we solve complicated problems. But we solve the complicated problems very elegantly, and thus are worshipped. Except by the users, who want a simple solution to simple problem handed to them, instead a an elegant solution to a complex problem shoved up their asses. But, you can't please everyone.

  • (cs) in reply to Kazan
    Kazan:
    1) Pick an accurate class name 2) Learn to implement that functionality efficiently. I've seen the same functionality, more usably and more understandably coded in less than half that space. 3) [Shatner]Stop. Over. Complicating. Every. Farking. Thing. Under. The. Sun. To. Make. A Scripting. Language. Look. Like. A. Compiled. Language.[/Shatner] 4) Xanax 5) Valium
    Blueworthy, definitely blueworthy.
  • PV (unregistered) in reply to COB
    COB:
    He was ahead of his time, it's an early version of LINQ. Intellisense and everything! Genius!

    This is awesome.

  • Pestulant (unregistered) in reply to Jason
    Jason:
    propel.phpdb.org

    What a waste of an article. I would never expect in a thousand years to see Propel in a WTF, thanks to an uneducated developer - here we have one.

    Jesus christ.

    Sure for one simple query, write a SQL and be done with it.. but showing the Propel criteria object as part of the WTF is just ridiculous.

    Propel is designed to be used for application development, certainly not for Select * from sometable where date >= now.

    Your WTF would be much better read if you pointed out that the developer had went through the trouble of using a powerful database abstraction and ORM layer to execute a very simple query, but somehow I believe there's more to the story than just that simple query otherwise why would they have spent the time to fucking deploy it in the first place?

    Horrible WTF.

    Alex - WTF?!

    Propel? Isn't that water? http://www.nowpropelled.com/
  • Procedural (unregistered) in reply to Kazan
    Kazan:
    Jason:
    AND TO ADD To my extreme disbelief, apparently the rest of you knuckleheads don't know it's Propel either.

    Good god.

    yes, because we're ALL supposedly to familiar with EVERY NON-STANDARD* php extension.

    Not only is your extension not in the standard extensions, it's not even LISTED http://us3.php.net/manual/en/extensions.membership.php

    Give me a break bonehead, i bet you're one of the Propell authors trying to plug your crap.

    • by standard i mean "core" or "bundled"

    In short: STFU

    Addendum (2009-06-15 13:23): Oh btw Jason, after looking at the actual implementation

    I was a professional LAMP developer for 18 months and I've done a lot of personal LAMP development

    1. Pick an accurate class name
    2. Learn to implement that functionality efficiently. I've seen the same functionality, more usably and more understandably coded in less than half that space.
    3. [Shatner]Stop. Over. Complicating. Every. Farking. Thing. Under. The. Sun. To. Make. A Scripting. Language. Look. Like. A. Compiled. Language.[/Shatner]
    4. Xanax
    5. Valium

    Propel would be a class system, not an extension, and a very important one at that too. It is a core of many higher-level PHP systems, such as Symfony. Also check out Doctrine.

    Competence FAIL.

  • Paula (unregistered)

    comments->add('First');

  • Taka (unregistered)

    Thanks for the class!!! I've been looking for something like this for a long time, this is gonna help me out tremendously...

    Oh I'm so excited I think I peed myself.

  • Chris (unregistered)

    This is really not that WTF-worthy. Yes, it's a bit weird, but you can obviously see the good intentions behind the whole thing. TRWTF is that everyone is suggesting to just write plain SQL code. That's what's got PHP its bad reputation in the first place -- mixing business logic with database access code and having two (or three, if you still embed PHP in HTML) languages in one file!

    Now the guy is obviously overdoing it a bit with all those methods to manually place parentheses and the like, but I'm actually working on a project right now that uses a very similar (but better though-out) process to build database queries in a programmatic way (this is in Java though).

    For example:

            QueryBuilder queryBuilder = new QueryBuilder(getEntityManager());
            QueryEntity entity = queryBuilder.select().entity();
            entity.setEntityClass(Account.class);
            queryBuilder.select().where().and();
            Expression whereExpr  = queryBuilder.select().where().and();
    
            if (searchParams.getOwnerId() != null) {
                whereExpr.eq(entity.getField(FIELD_OWNER_ID), searchParams.getOwnerId());
            }
    
            if (searchParams.getAccountNumber() != null) {
                whereExpr.eq(entity.getField(FIELD_ACCT_NUMBER), searchParams.getAccountNumber());
            }
    
            return getResultList(queryBuilder.build());
    

    This is IMHO pretty readable, and there's no ugly SQL to be seen anywhere. Especially not ugly concatenations of SQL code with Java variables. Needless to say, should we decide to switch databases, all that needs to be done is potentially modifying the QueryBuilder class to accomodate for weird database idiosyncrasies (like MySQL's backtick).

    But good luck to all you guys who are still mixing their SQL code straight into their business logic ;)

  • (cs) in reply to Jason
    Jason:
    Crafty_Shadow:
    When I read $c = new Criteria(); I thought to myself WTF, Propel? (no pun intended), but as I actually went about reading the article I found myself uttering What In The Name Of All That Is Holly...

    It seems like the developer came across the Propel implementation of Criteria at some point, and left with those vague impressions set off to build it's own... and failed miserably.

    There you go, good point. I honestly didnt bother to read that much because I couldn't believe in the first place that someone would submit Propel as a WTF. But it's there for a reason. Holy shit.

    Why in god's name would anyone attempt to replace the Criteria object, why?! in his case he SHOULD have simply done

    $SQL = "Select * from blah where date >= 'some-date' and wtf='no'"; $con = propel::getconnection('dbname') $stmt = $con->prepare($sql); $stmt->execute(); - that simply uses the PDO routines.

    What a fucknut. God damn it. facepalm

    You are a WTF.

    http://thedailywtf.com/Articles/Beaten-Into-Submission.aspx

  • (cs) in reply to Procedural
    Procedural:
    Kazan:
    Jason:
    AND TO ADD To my extreme disbelief, apparently the rest of you knuckleheads don't know it's Propel either.

    Good god.

    yes, because we're ALL supposedly to familiar with EVERY NON-STANDARD* php extension.

    Not only is your extension not in the standard extensions, it's not even LISTED http://us3.php.net/manual/en/extensions.membership.php

    Give me a break bonehead, i bet you're one of the Propell authors trying to plug your crap.

    • by standard i mean "core" or "bundled"

    In short: STFU

    Addendum (2009-06-15 13:23): Oh btw Jason, after looking at the actual implementation

    I was a professional LAMP developer for 18 months and I've done a lot of personal LAMP development

    1. Pick an accurate class name
    2. Learn to implement that functionality efficiently. I've seen the same functionality, more usably and more understandably coded in less than half that space.
    3. [Shatner]Stop. Over. Complicating. Every. Farking. Thing. Under. The. Sun. To. Make. A Scripting. Language. Look. Like. A. Compiled. Language.[/Shatner]
    4. Xanax
    5. Valium

    Propel would be a class system, not an extension, and a very important one at that too. It is a core of many higher-level PHP systems, such as Symfony. Also check out Doctrine.

    Competence FAIL.

    What file does Django's settings.py file subclass from? What is its ORM called? What is the syntax for emulating a Hindley-Milner type system using Perl regular expressions?

    If you don't know the answer to any of these, you fail at competence.

    (Hint: PHP is a trivial little programming language billions of people don't care about)

  • MR (unregistered)

    Although I doubt it's going to be well received a good point of doing the "Propel" way is to centralize query building.

    Not due to change in the SQL language but due centralize handling of common pitfalls such as SQL injection.

    By providing a simple class the developer has added possibility to fix issue like those in a single place instead of manually search for and audit every single one of the SQL statements. Code is more searchable as well.

    With that said I'm no fan of .LeftParanthesis, .RightParantesis and so on but I can see some merits with what he's done.

    Personally I prefer LINQ.

  • (cs) in reply to K2TheX
    K2TheX:
    WhatTheFrank:
    graybreard:
    I have a friend.. who's a brilliant programmer. The only problem is, he's good at solving extremely complicated issues. But not easy ones. So he turns easy ones into complicated before solving them.

    Based on your description, your friend is not a brilliant programmer. It takes a pretty shoddy programmer to be unable to solve easy problems without turning them into complicated ones. The brilliant programmers are the ones who can take extremely complicated problems and break them down into easy ones, then solve those.

    +1
    +2

    His definition of brilliant is quite different than mine. His version sounds like a WTF.

  • Procedural (unregistered) in reply to Captain Oblivious
    Captain Oblivious:
    Procedural:
    Kazan:
    Jason:
    AND TO ADD To my extreme disbelief, apparently the rest of you knuckleheads don't know it's Propel either.

    Good god.

    yes, because we're ALL supposedly to familiar with EVERY NON-STANDARD* php extension.

    Not only is your extension not in the standard extensions, it's not even LISTED http://us3.php.net/manual/en/extensions.membership.php

    Give me a break bonehead, i bet you're one of the Propell authors trying to plug your crap.

    • by standard i mean "core" or "bundled"

    In short: STFU

    Addendum (2009-06-15 13:23): Oh btw Jason, after looking at the actual implementation

    I was a professional LAMP developer for 18 months and I've done a lot of personal LAMP development

    1. Pick an accurate class name
    2. Learn to implement that functionality efficiently. I've seen the same functionality, more usably and more understandably coded in less than half that space.
    3. [Shatner]Stop. Over. Complicating. Every. Farking. Thing. Under. The. Sun. To. Make. A Scripting. Language. Look. Like. A. Compiled. Language.[/Shatner]
    4. Xanax
    5. Valium

    Propel would be a class system, not an extension, and a very important one at that too. It is a core of many higher-level PHP systems, such as Symfony. Also check out Doctrine.

    Competence FAIL.

    What file does Django's settings.py file subclass from? What is its ORM called? What is the syntax for emulating a Hindley-Milner type system using Perl regular expressions?

    If you don't know the answer to any of these, you fail at competence.

    (Hint: PHP is a trivial little programming language billions of people don't care about)

    Captain Obvious to the rescue: the original commenter claims to be competent at PHP and still be unaware of one of its most common ORMs. This is scary.

    Reading comprehension FAIL*.

    (As for the flamebait about PHP, I still have a workday ahead of me so I won't take it.)

    • I still think this structural neologism sucks; are we really trying to save three letters to complete this sentence ?
  • (cs) in reply to Chris
    Chris:
    This is really not that WTF-worthy. Yes, it's a bit weird, but you can obviously see the good intentions behind the whole thing.
    And what road do those lead you down?
  • (cs) in reply to Procedural
    Procedural:
    Captain Oblivious:
    Procedural:
    Kazan:
    Jason:
    AND TO ADD To my extreme disbelief, apparently the rest of you knuckleheads don't know it's Propel either.

    Good god.

    yes, because we're ALL supposedly to familiar with EVERY NON-STANDARD* php extension.

    Not only is your extension not in the standard extensions, it's not even LISTED http://us3.php.net/manual/en/extensions.membership.php

    Give me a break bonehead, i bet you're one of the Propell authors trying to plug your crap.

    • by standard i mean "core" or "bundled"

    In short: STFU

    Addendum (2009-06-15 13:23): Oh btw Jason, after looking at the actual implementation

    I was a professional LAMP developer for 18 months and I've done a lot of personal LAMP development

    1. Pick an accurate class name
    2. Learn to implement that functionality efficiently. I've seen the same functionality, more usably and more understandably coded in less than half that space.
    3. [Shatner]Stop. Over. Complicating. Every. Farking. Thing. Under. The. Sun. To. Make. A Scripting. Language. Look. Like. A. Compiled. Language.[/Shatner]
    4. Xanax
    5. Valium

    Propel would be a class system, not an extension, and a very important one at that too. It is a core of many higher-level PHP systems, such as Symfony. Also check out Doctrine.

    Competence FAIL.

    What file does Django's settings.py file subclass from? What is its ORM called? What is the syntax for emulating a Hindley-Milner type system using Perl regular expressions?

    If you don't know the answer to any of these, you fail at competence.

    (Hint: PHP is a trivial little programming language billions of people don't care about)

    Captain Obvious to the rescue: the original commenter claims to be competent at PHP and still be unaware of one of its most common ORMs. This is scary.

    Reading comprehension FAIL*.

    (As for the flamebait about PHP, I still have a workday ahead of me so I won't take it.)

    • I still think this structural neologism sucks; are we really trying to save three letters to complete this sentence ?
    Except he nowhere claimed to be a PHP expert. Methinks the reading comprehension failure was yours.
  • (cs) in reply to Grimoire
    Grimoire:
    His definition of brilliant is quite different than mine.
    It could be an innocent typo. Perhaps he meant to say, "brillant".
  • (cs) in reply to dpm
    dpm:
    Chris:
    This is really not that WTF-worthy. Yes, it's a bit weird, but you can obviously see the good intentions behind the whole thing.
    And what road do those lead you down?
    Love the subtlety.
  • Procedural (unregistered) in reply to Ilya Ehrenburg
    Ilya Ehrenburg:
    Procedural:
    Captain Oblivious:
    Procedural:
    Kazan:
    Jason:
    AND TO ADD To my extreme disbelief, apparently the rest of you knuckleheads don't know it's Propel either.

    Good god.

    yes, because we're ALL supposedly to familiar with EVERY NON-STANDARD* php extension.

    Not only is your extension not in the standard extensions, it's not even LISTED http://us3.php.net/manual/en/extensions.membership.php

    Give me a break bonehead, i bet you're one of the Propell authors trying to plug your crap.

    • by standard i mean "core" or "bundled"

    In short: STFU

    Addendum (2009-06-15 13:23): Oh btw Jason, after looking at the actual implementation

    I was a professional LAMP developer for 18 months and I've done a lot of personal LAMP development

    1. Pick an accurate class name
    2. Learn to implement that functionality efficiently. I've seen the same functionality, more usably and more understandably coded in less than half that space.
    3. [Shatner]Stop. Over. Complicating. Every. Farking. Thing. Under. The. Sun. To. Make. A Scripting. Language. Look. Like. A. Compiled. Language.[/Shatner]
    4. Xanax
    5. Valium

    Propel would be a class system, not an extension, and a very important one at that too. It is a core of many higher-level PHP systems, such as Symfony. Also check out Doctrine.

    Competence FAIL.

    What file does Django's settings.py file subclass from? What is its ORM called? What is the syntax for emulating a Hindley-Milner type system using Perl regular expressions?

    If you don't know the answer to any of these, you fail at competence.

    (Hint: PHP is a trivial little programming language billions of people don't care about)

    Captain Obvious to the rescue: the original commenter claims to be competent at PHP and still be unaware of one of its most common ORMs. This is scary.

    Reading comprehension FAIL*.

    (As for the flamebait about PHP, I still have a workday ahead of me so I won't take it.)

    • I still think this structural neologism sucks; are we really trying to save three letters to complete this sentence ?
    Except he nowhere claimed to be a PHP expert. Methinks the reading comprehension failure was yours.

    Nice, we get a 2-for-1 today. It must be the short bus day.

    "I was a professional LAMP developer for 18 months and I've done a lot of personal LAMP development"

    P is for PHP.

  • xeno (unregistered)

    For a programmer who only knows OO, eveything looks like an object. Even another symbolic language.

    (Waits for somebody to miss the point and launch into an impassioned defence of OO, when that is in fact not what I'm critisising as such...)

  • (cs) in reply to Procedural
    Procedural:
    Nice, we get a 2-for-1 today. It must be the short bus day.

    "I was a professional LAMP developer for 18 months and I've done a lot of personal LAMP development"

    P is for PHP.

    That's what you think. Others know that it can stand for any one (or more) of Perl, PHP and Python (in alphabetical order). My choice would be Python.
  • Billy (unregistered) in reply to Stephen Melrose
    Stephen Melrose:
    Mr. A. T. Roll:
    Thank God I read Daily WTF. I had heard about Propel, and thought about using it today. Now I will be sure to steer absolutely clear of that piece of garbage! TYVM Daily WTF!
    Propel is a lot better than what this guy has demonstrated. Give it a go before you knock it. Makes development a hell of a lot easier.

    Also Doctrine is another very good PHP ORM.

    Hahaha...I was wondering whether a billygoat came along.

    Read the OP's name....

  • Someone (unregistered) in reply to GrumpyYoungMan
    GrumpyYoungMan:
    WhatTheFrank:
    graybreard:
    I have a friend.. who's a brilliant programmer. The only problem is, he's good at solving extremely complicated issues. But not easy ones. So he turns easy ones into complicated before solving them.

    Based on your description, your friend is not a brilliant programmer. It takes a pretty shoddy programmer to be unable to solve easy problems without turning them into complicated ones. The brilliant programmers are the ones who can take extremely complicated problems and break them down into easy ones, then solve those.

    Some of us can't be arsed to solve simple problems, regardless of what the user wants. So, we solve complicated problems. But we solve the complicated problems very elegantly, and thus are worshipped. Except by the users, who want a simple solution to simple problem handed to them, instead a an elegant solution to a complex problem shoved up their asses. But, you can't please everyone.

    Surely an elegant solution is one that first simplifies the problem? A complex solution is rarely (if ever) elegant. (Although what people call elegant solutions are usually 'I thought of a weird way to do this that noone else will have thought of' - which leads to difficult to maintain code). I think (when talking code) people too often confuse elegant with extravagant!!

    By the sound of it (despite what you might think) I doubt very much that you produce elegant solutions to complex problems - or for that matter, are worshipped.

    Oh, and if you are a troll...my bad...

  • (cs) in reply to WhatTheFrank
    WhatTheFrank:
    It takes a pretty shoddy programmer to be unable to solve easy problems without turning them into complicated ones. The brilliant programmers are the ones who can take extremely complicated problems and break them down into easy ones, then solve those.
    Most of the really brilliant programmers are those that recognize that the current complicated hard problem is actually a simple one from another field, and take the solution from there and apply it economically to the current issue. The usual experience when dealing with their code is “Yes, of course that solves it. But how on earth did they ever think of doing that?!” (The wise ones will have document why they picked that solution, but you can't always have everything you want…)
  • Fedaykin (unregistered) in reply to Chris
    Chris:
    This is really not that WTF-worthy.

    (snip)

    This is IMHO pretty readable, and there's no ugly SQL to be seen anywhere. Especially not ugly concatenations of SQL code with Java variables. Needless to say, should we decide to switch databases, all that needs to be done is potentially modifying the QueryBuilder class to accomodate for weird database idiosyncrasies (like MySQL's backtick).

    But good luck to all you guys who are still mixing their SQL code straight into their business logic ;)

    Sorry, your example is just as much of a WTF even if it's a bit prettier. Is there any particular reason you aren't you using a DAO pattern where you can encapsulate all your DB access nicely with an ORM (e.g. Hibernate) and some simple OQL?

    class AccountDao {
    public List<Account> getByOwnerId( int ownerId ) {
        Query query =fEm.createQuery("select o from Account a where a.ownerId = :ownerId");
        query.setParameter( "ownerId", ownerId );
        return (List<Account>)query.getResultList();
    }}
    

    This has all the advantages your proclaim for your code (except, they aren't just claims but reality), with the added benefit of not being a roll your own solution to industry standard tools. Plus, for the majority of your operations (simple selects, deletes, writes, etc.) you can build a nice base class to handle all that instead of laboriously constructing queries for each and every DB operation.

    ORMs are your friend...

  • Mr.'; Drop Database -- (unregistered) in reply to Grimoire
    Grimoire:
    K2TheX:
    WhatTheFrank:
    graybreard:
    I have a friend.. who's a brilliant programmer. The only problem is, he's good at solving extremely complicated issues. But not easy ones. So he turns easy ones into complicated before solving them.
    Based on your description, your friend is not a brilliant programmer. It takes a pretty shoddy programmer to be unable to solve easy problems without turning them into complicated ones. The brilliant programmers are the ones who can take extremely complicated problems and break them down into easy ones, then solve those.
    +1
    +2

    His definition of brilliant is quite different than mine. His version sounds like a WTF.

    The OP was being sarcastic.

  • Tama (unregistered) in reply to Chris
    Chris:
    This is IMHO pretty readable, and there's no ugly SQL to be seen anywhere. Especially not ugly concatenations of SQL code with Java variables. Needless to say, should we decide to switch databases, all that needs to be done is potentially modifying the QueryBuilder class to accomodate for weird database idiosyncrasies (like MySQL's backtick).

    But good luck to all you guys who are still mixing their SQL code straight into their business logic ;)

    I hope that by hiding "ugly concatenation", you don't mean "ugly string concatenation" such as "select foo where bar = " + myVar. That's what PreparedStatements are for (more efficient, avoid SQL injections, etc); no need for a fancy query builder there.

    As for "mixing SQL code straight into their business logic", that's what the DAO pattern is for; again, no need for fancy query builders just for that. See http://thedailywtf.com/Articles/The_Enterprise_Rules_Engine.aspx for more about that.

    I think the only place where it's worth using "Query builder"-like objects (such as Criteria for Hibernate in the Java world) is when you need to create on-the-fly queries, such as what you would have for a simple search tool (e.g. find all users by status and/or registration date and/or last login date and/or last name and/or email address etc...). But that's the exception, not the rule.

    CAPTCHA: no one gives a damn.

  • Paul (unregistered)

    I worked on a project a few years ago where the SQL was done nicely. But HTML had to be encoded using this approach.

    But what was scarier is that this was VBScript (ASP) and is was functions like this

    function GenerateHTML() GenerateHTML=OpenBracket() & HTML() & CloseBracket() end function

    function OpenBracket() OpenBracket="<" end function

    etc etc etc... as you can imagine it was not fun to maintain this.

  • (cs) in reply to Chris
    Chris:
    But good luck to all you guys who are still mixing their SQL code straight into their business logic ;)

    Uhmmm... Didn't you just write your SQL code straight into your business logic? Sure you "encapsulated" it away in some random class (that isn't easier to read). But you still have the SQL code hardcoded right there in that function.

    What is the big win you get out of doing it this way?

  • (cs) in reply to MR
    MR:
    With that said I'm no fan of .LeftParanthesis, .RightParantesis and so on but I can see some merits with what he's done.

    There are no merits for what he did. You write utility functions to make programming easier, and harder to fuck up. You don't add a "leftParen" forcing the user to ALSO add a "rightParen." You create some sort of "grouping" concept. Add your clauses to the group. The group then knows to add the left, right parens. The code is simpler, easier to understand, and harder to fuck up.

  • My Two Cents (unregistered) in reply to chrismcb
    chrismcb:
    MR:
    With that said I'm no fan of .LeftParanthesis, .RightParantesis and so on but I can see some merits with what he's done.

    There are no merits for what he did. You write utility functions to make programming easier, and harder to fuck up. You don't add a "leftParen" forcing the user to ALSO add a "rightParen." You create some sort of "grouping" concept. Add your clauses to the group. The group then knows to add the left, right parens. The code is simpler, easier to understand, and harder to fuck up.

    Perhaps, but idiot-proofing breeds idiots. (How did windows evolve to where it is, and what sort of user has it created?)

    Too often, people focus on creating systems that are 'impossible' to muck up. Too often users prove that they can be quite inventive in stuffing things up. Creating a system that requires people to know what they're doing is a wonderful thing - you scare away the monkeys that will break it. Sure, even people who know what they're doing may make mistakes and break things, but trying to idiot-proof the system will not help. Creating a system that is 'unbreakable' encourages people to put your average off-the-street "I finished school to year 10' types behind the wheel, and this is never a good thing!

  • Tama (unregistered) in reply to My Two Cents
    My Two Cents:
    chrismcb:
    There are no merits for what he did. You write utility functions to make programming easier, and harder to fuck up. You don't add a "leftParen" forcing the user to ALSO add a "rightParen." You create some sort of "grouping" concept. Add your clauses to the group. The group then knows to add the left, right parens. The code is simpler, easier to understand, and harder to fuck up.

    Perhaps, but idiot-proofing breeds idiots. (How did windows evolve to where it is, and what sort of user has it created?)

    Too often, people focus on creating systems that are 'impossible' to muck up. Too often users prove that they can be quite inventive in stuffing things up. Creating a system that requires people to know what they're doing is a wonderful thing - you scare away the monkeys that will break it. Sure, even people who know what they're doing may make mistakes and break things, but trying to idiot-proof the system will not help. Creating a system that is 'unbreakable' encourages people to put your average off-the-street "I finished school to year 10' types behind the wheel, and this is never a good thing!

    I'll assume that the post above was not a troll (or maybe it's just too late, and I'm missing the obvious).

    Total bullshit. Good software guidelines generally dictate that the code you write should be as liberal as possible with its input, and as restrictive as possible with its output. Idiot-proofing your system makes bugs MUCH easier to find; it also provides you with guarantees about your "building blocks": once you know that you cannot fuck up your SQL statement by forgetting the rightParenthesis call, you know that the SQL syntax problem you're dealing with has to be somewhere else.

    Who knows, the idiot you're proofing against may be you, in four weeks, when you don't remember the idiosyncrasies of your system?

  • Bob (unregistered) in reply to Jason
    Jason:
    propel.phpdb.org
    Jason:
    AND TO ADD To my extreme disbelief, apparently the rest of you knuckleheads don't know it's Propel either.

    Good god.

    So, apparantly the dictionary definition of "knuckleheads" has been updated, and now reads "people not familier with all the projects hosted at phpdb.org", so apparantly until you're a PHP developer, you're a knucklehead.

    I agree completely with Jason - "good god" (and some extreme disbelief) is precisely the correct response to that sort of bitching about knuckleheads.

  • My Two Cents (unregistered) in reply to Tama
    Tama:
    My Two Cents:
    chrismcb:
    There are no merits for what he did. You write utility functions to make programming easier, and harder to fuck up. You don't add a "leftParen" forcing the user to ALSO add a "rightParen." You create some sort of "grouping" concept. Add your clauses to the group. The group then knows to add the left, right parens. The code is simpler, easier to understand, and harder to fuck up.

    Perhaps, but idiot-proofing breeds idiots. (How did windows evolve to where it is, and what sort of user has it created?)

    Too often, people focus on creating systems that are 'impossible' to muck up. Too often users prove that they can be quite inventive in stuffing things up. Creating a system that requires people to know what they're doing is a wonderful thing - you scare away the monkeys that will break it. Sure, even people who know what they're doing may make mistakes and break things, but trying to idiot-proof the system will not help. Creating a system that is 'unbreakable' encourages people to put your average off-the-street "I finished school to year 10' types behind the wheel, and this is never a good thing!

    I'll assume that the post above was not a troll (or maybe it's just too late, and I'm missing the obvious).

    Total bullshit. Good software guidelines generally dictate that the code you write should be as liberal as possible with its input, and as restrictive as possible with its output. Idiot-proofing your system makes bugs MUCH easier to find; it also provides you with guarantees about your "building blocks": once you know that you cannot fuck up your SQL statement by forgetting the rightParenthesis call, you know that the SQL syntax problem you're dealing with has to be somewhere else.

    Who knows, the idiot you're proofing against may be you, in four weeks, when you don't remember the idiosyncrasies of your system?

    If anything, by over-complicating systems (as you suggest) you introduce idiosyncracies. You will not fuck up (as you put it) statements by missing right parenthesis - things won't work, but they won't fuck up - you will simply need to find where you went wrong.
    I'm not for a minute saying (or at least didn't mean to) that things should be done using leftParen and rightParen methods - further more, any error caused by missing a parenthesis would appear in the development stage, or at least the testing stage, well before anything is fucked up. I'm a big fan of 'easier', but think extreme caution is required when people start saying 'harder to fuck up'. Trying to catch every single fuck-up before it happens creates a false sense of security, and promotes a lackadaisical (or certainly at least careless) attitude, where developers believe that anything they do will not fuck up the system, and don't bother to try to avoid stupid mistakes.

    Accidents happen, and while it is important to minimise accidents, it is more important to accept that they happen, that they will impact schedule (and possibly many other things), but they are unavoidable. When accidents happen, there should be process in place to recover, and people should be trained to double and triple check their code and then have a peer review it before it even hits a testing phase.
    If there is a problem with mistakes creeping into production systems and fucking things up, then that problem is in the process that allows the mistake to go unnoticed - not with the process that allowed the mistake to be made in the first place.

    I don't really understand where your thoughts on Good Software Guidelines come into this, so perhaps I've misunderstood much of what you are saying, however it seems a little worrisome that you would think Idiot-proofing makes any guarantee whatsoever. It may give you a nice sense of security (albeit a false one), and make you sleep better at night, however the fact that you have attempted to idiot-proof everything does not mean that you have successfully done it.

    Naturally, you won't agree with me on this (and can't say I care overly, either), and I'm quite sure I won't agree with anything you write should you choose to reply (in fact I think I only bothered replying to this because of the sentence 'Total bullshit' in your post).
    Clearly idiot-proofing works for you (or you think it does), but if you've ever worked with idiots (and believe me, I have) they always seem to have a knack of finding a way around any guard you put in place against them.

  • (cs) in reply to Chris
    Chris:
    But good luck to all you guys who are still mixing their SQL code straight into their business logic ;)

    Really? Where else are you going to put it? After all, if the purpose of a program is to fulfill some business need then, by definition, every piece of code you write is business logic.

    Maybe you mean "SQL code in client code" in which case I think you are wrong. SQL code has to be in the client somewhere; either in the code you are writing or in the code of some library/abstraction you are using. In both of those cases, bad programming can lead to injection vulnerability.

    Possibly you mean "business logic in SQL"? In which case, I still think you are wrong. :-)

    Some business logic must to be on the database server (possibly as well as on the client). Why? Because you can't force the bad guys to use your client.

    B

  • Adrian Pavone (unregistered) in reply to @Deprecated
    @Deprecated:
    ohmy:
    I try to avoid web-development in general and PHP in particular like the plague, so I couldn't care much less about a PHP extension designed for SQL building.

    Expecting WTF commenters to have heard of Propel seems a bit much to me...

    That is not a stretch at all. We here at TDWTF are experts on EVERYTHING related to computers, as evidenced by postings in these forums.

    Let's say we were to form a company and bid on a contract for a complete integrated solution including design from the ground up - we would design, build, and program the BEST %$#$@ SYSTEM IN THE WORLD!!! Mwa ha ha.

    That is, if we ever stopped bickering over stuff like how to format date strings.

    I thought we had settled on YYMD/DY/MY?

  • Adrian Pavone (unregistered) in reply to Chris
    Chris:
    This is really not that WTF-worthy. Yes, it's a bit weird, but you can obviously see the good intentions behind the whole thing. TRWTF is that everyone is suggesting to just write plain SQL code. That's what's got PHP its bad reputation in the first place -- mixing business logic with database access code and having two (or three, if you still embed PHP in HTML) languages in one file!

    Now the guy is obviously overdoing it a bit with all those methods to manually place parentheses and the like, but I'm actually working on a project right now that uses a very similar (but better though-out) process to build database queries in a programmatic way (this is in Java though).

    For example:

            QueryBuilder queryBuilder = new QueryBuilder(getEntityManager());
            QueryEntity entity = queryBuilder.select().entity();
            entity.setEntityClass(Account.class);
            queryBuilder.select().where().and();
            Expression whereExpr  = queryBuilder.select().where().and();
    
            if (searchParams.getOwnerId() != null) {
                whereExpr.eq(entity.getField(FIELD_OWNER_ID), searchParams.getOwnerId());
            }
    
            if (searchParams.getAccountNumber() != null) {
                whereExpr.eq(entity.getField(FIELD_ACCT_NUMBER), searchParams.getAccountNumber());
            }
    
            return getResultList(queryBuilder.build());
    

    This is IMHO pretty readable, and there's no ugly SQL to be seen anywhere. Especially not ugly concatenations of SQL code with Java variables. Needless to say, should we decide to switch databases, all that needs to be done is potentially modifying the QueryBuilder class to accomodate for weird database idiosyncrasies (like MySQL's backtick).

    But good luck to all you guys who are still mixing their SQL code straight into their business logic ;)

    I was going to say something about how you had just implemented the C# method in php, but then I re-read your post and you said you were using Java. Of course proper OO languages do this right, generally using built in classes. PHP in general however does not, so please do not defend it.

    I had to write a shopping cart engine in php at one point, and used the tried and true UI/BLL/DLL method, which is the only way I have seen in php to seperate the business logic from the user interface logic as you stated. This is unlike C# or similar where design patterns like MVC (and MVP/MVVM in non-web based) are much more prevalent, and where good OOP is generally practiced by any non-hobbyist who has half a clue.

  • Adrian Pavone (unregistered) in reply to Adrian Pavone
    Adrian Pavone:
    I had to write a shopping cart engine in php at one point, and used the tried and true UI/BLL/DLL method, which is the only way I have seen in php to seperate the business logic from the user interface logic as you stated. This is unlike C# or similar where design patterns like MVC (and MVP/MVVM in non-web based) are much more prevalent, and where good OOP is generally practiced by any non-hobbyist who has half a clue.

    Sorry, there's no edit button for me, this was meant to say "C# 2.0", i.e., Before the advent of LINQ.

  • (cs) in reply to @Deprecated
    @Deprecated:
    That is, if we ever stopped bickering over stuff like how to format date strings.

    However the client wants them formatted.

Leave a comment on “Simple SQL”

Log In or post as a guest

Replying to comment #:

« Return to Article