[wp-hackers] The problem with WP_Rewrite <<< RE: Options for Controller - Views

Christopher O'Connell jwriteclub at gmail.com
Thu Dec 3 22:49:41 UTC 2009

> Let me rephrase that: SQL is designed to be used by *business people*.
> Not programmers.

And the goal clearly failed. Unless your "Business People" are much better
trained (and by that I mean terrified of you) than mine, they won't touch it
with a 10 foot pole.

> The only real reason we abstract it out is because we have only a
> small subset of SQL queries that are needed for the application at
> hand.

EXACTLY: Just like we have a small set of RegEx that we normally use. When
things get really complicated I can write my own RegEx, just as I write my
own SQL when things get really complicated now.

> You're looking at this from the point of view of "redirecting a URL to
> a template". But I'm looking at this from the point of view of what
> you *actually* want to do, which is to parse the URL and then
> determine and load the right template. These are actually equivalent,
> but for some reason, you are not seeing that fact.
If all that anyone ever wanted to do was to load a predefined theme file for
some URL, than your scheme is somewhat cumbersome but works. The general
case, however, is to have a particular URL stub (say /products, as it's
being used in discussion) cause a function to run that does some magic and
then loads a specific template file. The simplest case of this is when you
want to load the template file without sending it any particular arguments.
My case is not super specific, it's actually quite general, it's a common
use case, and the fact that I need to muck around in terms of rewriting the
already parsed arguments to change to a custom post type is ludicrous.

> Let's say I wrote you a new function, called redirect_URL_to_template.
> It'd work like this:
> redirect_URL_to_template('products');

Well of course it's silly, you don't build an API to the dumbest common
denominator, you build it to a reasonable general case. The problem with the
current version is that what you've just proposed is just about the
*only*case where the current version makes sense.

Or, I could teach you "this is how the system works, it's pretty
> simple but you do have to think a small amount, however it's powerful
> enough to let you make any arbitrary URL do any damn thing you like,
> whether it be routing to views, or calling functions, or even
> downloading the complete works of shakespeare.. You can do anything
> with it, and all you have to learn is this extremely tiny subset of
> regular expressions. And by extremely tiny, I only mean what these
> characters do: .*?+[]()$     Seriously, that's probably all you ever
> need.
> What makes more sense?

RegEx is not simple for people to learn. Unless and until one has a working
knowledge of regular languages, regular expressions are a black art. Can
people get some simple examples working? Maybe, but more complex (but still
common) routeings require a complex understanding of both regular languages
and the parsing engine itself (e.g. how "greedy" is it).

It makes more sense to allow people to say /products/{category}/{product} =>
display_product, where function
display_product($cat="shoes",$product="loafers"). Could it be wired up in
RegEx? Sure, but it's not simple.

> > P.P.S. This reminds me of the discussions on some of the linux boards
> about
> > how "including a graphical package manager is totally unneccessary,
> because
> > there's a command line one".
> Funnily enough, on my Fedora install, I'm always popping up a command
> line to run yum, because PackageKit sucks and is hard to use.

Umm, pretty much proves my point. I too use yum all the time, because I'm a
super nerdy linux beard. But for mere mortals the GUI is the way to go!

~ Christopher

More information about the wp-hackers mailing list