[wp-hackers] The problem with WP_Rewrite <<< RE: Options for Controller - Views
mikeschinkel at newclarity.net
Thu Dec 3 18:34:23 UTC 2009
On Dec 3, 2009, at 12:43 PM, Otto wrote:
> ... To be quite blunt, if a person is not capable of understanding
> regular expressions, and can't look in a book for 10 minutes to figure
> out what they want to do, then they should not be writing code of any
> kind. They should stick to something simple, like flipping burgers.
And to be blunt in return, it's exactly that type of position that I think should disqualify your opinion from having any sway with respect to WordPress' direction. That is highly condescending. Your assertion would compare to me saying "Unless you have the skills of the German masters you shouldn't be allowed to brew beer."
> Obviously, I don't expect an end user to understand regular
> expressions. I wouldn't want people making fields to put regexp on the
> admin screens, for example.
> But there's a certain level of knowledge you need to obtain to write
> code, and to write PHP code in particular. Simple Regular Expressions
> is one of those most basic levels of things you need to know, just
> after string handling.
That "certain level of knowledge required" is only required because some people who think others are not worthy block the way to accessibility by more people.
According to your "rules" nobody should be able to code a theme unless they are capable of understanding regular expressions. Meh. I'll quote many a wise programmer:
"Some people, when confronted with a problem, think "I'll use regular expressions." Now they have two problems."
Regular Expressions are notoriously fragile and mastering Regular expressions takes time and diligence. Expecting the themer to become good of regular expressions is just silly.
> Do I expect a plugin author to understand regexp? Absolutely.
> Do I expect a theme author to understand regexp? No.
> Do I expect them to be able to ask somebody or Google search to find
> examples? Yes.
The flaw in that logic is that regular expressions are complex enough with nuances that can easily bite you that it's very difficult to see an example and use it it quickly craft a different example that works. So if you are asking a themer to use regular expressions then you are asking a themer to understand regular expressions.
If regular expressions are so easy, why is it that a bunch of really smart developers (probably smarter than anyone on this list and especially me) have proposed URI Templates? (answer: because regular expressions are just too damn hard):
Regular expressions can represent practically anything. The valid scope of URL rewriting is much smaller than what a regular expression can handle. Using regular expressions for URL rewriting when something more straightforward is available is pure overkill.
Look, even WordPress' permalink section eschews regular expressions for a form of URL templates. Obviously there is a reason regular expressions are too hard. (and by your logic, people could have just cut and paste examples from the docs into the admin. I'm glad your approach did not prevail there.)
>>> The post_type variable is supported in 2.8, but *custom* post_type
>>> support wasn't added until 2.9.
>> But it still doesn't work in 2.8, right? At least it didn't work when I tried to use the URL with a post_type parameter on an existing live site. Anyway, not important.
> No, it works in 2.8 just fine, but the post_type must be "post", or
> "page", or "attachment", etc. Basically, wp_query didn't like anything
> but the various built in ones.
In other words for custom post types it doesn't work in 2.8. Reminds me of the joke about the lost pilot in the helicopter who asked the people in the building where he was:
>> Conversely I'm floored by your adamancy about not wanting to make this common need approachable. The code you mention is fine for plugins but not fine for themes.
> The code I mentioned was *far* more appropriate for themes than for
> plugins, because it's creating specific conditions that the theme must
> satisfy (like having a custom/products.php file in it, for example).
> And it didn't even require regexp.
Sigh. add_custom_url() was much simpler than your code and did all the same things.
>> The skill level for PHP coding among plugin developers is much higher than for your *average* themer who in many cases use cuts and pastes PHP code from examples...
> What's wrong with them cut and pasting the example from somewhere and
> modifying it to their needs?
1.) cutting and pasting regular expressions doesn't work unless they are an exact match,
2.) the more complex it looks the less approachable it is and the less likely people will end up being able to use it.
Look, I'm trying to make adding a custom URL *declarative*; you are trying to force it to continue to be *procedural*. The former is almost always easier to learn than the latter:
... Many languages applying this style attempt to minimize or eliminate side effects by describing what the program should accomplish, rather than describing how to go about accomplishing it. This is in contrast with imperative programming, which requires an explicitly provided algorithm.
The declarative programming try to blur the distinction between a program as a set of instructions and a program as an assertion about the desired answer, in other words, the declarative programs can be dually viewed as programming commands or mathematical assertions. Thus, it is easy to understand the semantics of declarative language using the way we understand ordinary mathematics.
> More to the point, what makes you think a theme author isn't going to
> do the same with your add_custom_url nonsense, eh? You've got a ton of
> "magic" words in there... url-type, callback, single-post, etc, etc.
> And it's using an array as well.
It's far easier to learn magic words for a single function call from a doc page than it is to learn how to assemble many different concepts from potentially many different doc pages, and more importantly its much harder to master using regular expressions correctly than learning a small finite list of keywords.
> I am really not seeing why you think your method is any easier or less
> complicated, especially if you're going to assume that the theme
> author doesn't know PHP all that well. Heck man, theme authors cut and
> paste the register_sidebar calls for their functions.php files all the
> time, and they're about as complex as your add_custom_url is.
Honestly, if you can't see why it's easier or even accept that other people can see things different then there's nothing left for us to discuss.
More information about the wp-hackers