- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Admin
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.
Admin
LOL. The Real WTFs are Jason's comments. Missed out on "reading comprehension" in school, did you?
Admin
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.
Admin
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.
Admin
Was paula involved in this too?
Admin
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...
Admin
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.
Admin
Admin
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?
Admin
Real SQL coders do all the work in TRIGGERs.
Admin
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.
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
Admin
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.
Admin
Admin
This is awesome.
Admin
Admin
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.
Admin
comments->add('First');
Admin
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.
Admin
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:
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 ;)
Admin
You are a WTF.
http://thedailywtf.com/Articles/Beaten-Into-Submission.aspx
Admin
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)
Admin
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.
Admin
His definition of brilliant is quite different than mine. His version sounds like a WTF.
Admin
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.)
Admin
Admin
Admin
Admin
Admin
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.
Admin
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...)
Admin
Admin
Hahaha...I was wondering whether a billygoat came along.
Read the OP's name....
Admin
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...
Admin
Admin
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?
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...
Admin
Admin
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.
Admin
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.
Admin
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?
Admin
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.
Admin
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!
Admin
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?
Admin
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.
Admin
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.
Admin
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
Admin
I thought we had settled on YYMD/DY/MY?
Admin
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.
Admin
Sorry, there's no edit button for me, this was meant to say "C# 2.0", i.e., Before the advent of LINQ.
Admin
However the client wants them formatted.