Topic: Midnight Musings: Internal API Conceptually Moot
I'm toying around on the 1.3 code base and hitting a brick wall. Let me example:
I'm looking at profile.php. Pretty simple, no? Anyway, I read through the section about deleting a user. Seems pretty cool. But then it hits me -- when I'm writing extensions, how does my extension gain that power?
Let's say I want to make an extension that, if a person includes the word "noob" in their first post they are automatically deleted with a vengeance. At the current time, I have no choice but to (shudder) duplicate the "delete user" code into my extension. This is, pretty much, nasty. If there are bugs with it, my extension will likely get left in the dust and exposed when updates happen. Code duplication like that, in general, sucks.
So I said, "Fine, I'm a smart guy, I'll just put all these little utility events in functions and make a new file, 'api.php' to serve me well." This is where the pretty red&gray brick wall landed in my face.
See, making the move from that file into a function does something. Something very special -- it changes the variable scope of what you have access too. When running en situ for profile.php works fine, if you try putting the delete user ability into a function, suddenly it's missing the database. Then another variable. Oh and that one you missed too. In short, PunBB very heavily relies on the idea that every variable is always available regardless of scope for some very important tasks.
I think the practicality of moving the majority of this code to an internal API-type setup would be essential to a proper extension platform. Extension authors will NEED functions like "delete_user" or "ban_user" -- even things as broad as "add_post" or "add_topic" should be in the API for extension developers to take advantage of.
Hooks are great (need a LOT more based on what I'm seeing in SVN, but I'm sure the devs know that) but without some kind of global utility API, we're either stuck duplicating code or up the creek with no paddle. Neither option is pretty.