post-page

Do You Have Class?

12
responses
by
 
on
January 25th, 2010
in
LinkyLoo

I have hard time understanding the basis of this article but I wanted to link to it because I know many in the WeblogToolsCollection audience are coders themselves and it would be interesting to see the conversation that arises from Andrew’s post. WordPress coders have no class. At least, that’s what Andrew says in his post that discusses object oriented code being used in a non-object oriented environment.

What do I mean by a non-object oriented environment? Well, firstly WordPress still does not require PHP5 for core code so there are limits to how many of the techniques it can use anyway. Secondly, WordPress has been around for a long time and has been developed by many contributors looking to achieve specific things with each patch without having a particular architecture imposed, except by committee.

WordPress developers tend to start as users who learn PHP in fits-and-starts when they need to accomplish something. They move from echo statements in themes, to functions, to classes, picking up ‘best practices’ as they go.

Let Andrew know what you think by commenting on his blog.

heading
heading
12
Responses

 

Comments

  1. Otto (215 comments.) says:

    I tend to agree with that article, but I think he’s fallen into the trap of what I call “the computer science fallacy”.

    I took Computer Science in college, and even got a degree or three in it. So I know that sort of thing on a very detailed level, and can give you all sorts of theoretical knowledge and chat about any sort of topic you care to name. I can tell you all about OOP, and processes, and development practices. I even understand, and can do, multi-threading properly (yikes!).

    But when I actually write the code, I tend to write short procedural snippets. Why? Because I’m trying to get a frickin’ job done, not create elegant code. Elegant code is fun to look at. But sometimes “ugly” code *gets you paid*.

    The CS fallacy is the idea that code should be correct instead of functional.

    There’s nothing wrong with wanting code to be graceful and to be easy to work with. But it must actually work, and that is priority number 1. Code that looks pretty but doesn’t do what you need it to do is useless.

    So no, I don’t mind the “ugly” pieces in WordPress. They work. That’s the important thing. And ugly working code can always be refactored into pretty working code.

    Object Oriented is the main focus of his article, and there’s nothing wrong with OOP in general, but there’s also nothing wrong with procedural in general either. They’re different ways of looking at the same problem and solving it. And that’s the important thing: that the problem is solved. Not that the code is elegant.

    Also, “elegant” is not the same as “easy”. I currently am employed full-time by a Fortune 200 company which has 25+ year-old C code running in production systems in 5000+ locations. We support and maintain that code. Most of it considered to be “legacy” and we’re not actively trying to replace it. The code works, and sometimes that’s the bottom line.

    • Aaron says:

      “The CS fallacy is the idea that code should be correct instead of functional.”

      The real world is bound by this rule: You can have it good, soon and cheap, but you can only pick two.

      Corrolaries:
      Good and cheap = project goes to backburner and done optimally.
      Good and now = premium must be paid to yank competent programmers off of existing tasks.
      Now and cheap = shlocky job.

      Sometimes, the right business solution is [shudder] COBOL, when you’re dealing with a legacy app that needs to be tweaked, not rewritten from scratch.

  2. bubazoo (213 comments.) says:

    Well, according to many PHP guru’s, they think wordpress is badly coded, and I think andrew’s post is what they mean by that. They think that because wordpress ign’t “elegant”, that its bloatware, that it could be optimized to run more smoothly if written more elegantly.

    that is the gist of the argument in a nuttshell. Personally, I don’t give a crap, because who cares if wordpress is “elegant” or not? Assuming it could be optimized better, how much would we be saving here? 0.0000000001 milisecond of time? at the very most? LOL!! I mean common, isn’t that a bit overly nit picky! So I say who cares, long as it works. If the guru’s think their so smart, why don’t they write their own version of wordpress then? they don’t, they just like to complain is what it is, just like anything else.

    • bubazoo (213 comments.) says:

      THe complainers also have to realize that wordpress is an “ongoing” project. Sure it probably would be optimized for PHP5 and all that, if it were be written today from scratch, but the point is its NOT, so you have to expect an ongoing project thats been around for many years to be badly optimized compared to todays coding standards.

      but like I said, even if it was rewritten completely from scratch, how much faster would it actually be? 0.00000001 milisecond faster? As fast as webservers are these days, do we really care to save that much time per page load to begin with?? lol

    • Andreas Nurbo (9 comments.) says:

      I think they call it badly coded because its hard to understand and get into and because there are bad code in WP. Strange globals, namingschemes and weird loops. Not all wrapper functions working the same way parameter wise as the main function they wrap around.
      Functions that utilizes globals that need to be set else where and what not.

  3. Victor (2 comments.) says:

    WordPress is a very nice CMS / Blog system. It’s easy to learn and it’s just fun to play with for php coders and webmasters. Because it’s so easy, a lot of webmasters or beginner coders starts hacking and writing their own code and plugins.

    I think about now will be a good time start refactoring the WP core to PHP5. Who doesn’t support PHP5 nowadays?

    @bubazoo:
    As much as I like WP, I have to say it is slow. Fortunately that problem can be solved by using a good cache plugin (like W3 Total Cache).

    But in Andrews defence and in my opinion, the line “Code Is Poetry” is kind of misleading…

  4. Andrew (11 comments.) says:

    Just to be clear about my intent, while I do explain what I mean by WordPress not being object oriented I am making absolutely no comment at all on WordPress itself, nor on the relative merits between object oriented vs procedural vs any other kind of code.

    It is more of an exploration into the reasons why WordPress extension coders use classes / object-based techniques and whether they should be criticised for doing so.

    Having said that, Otto may well have a point about my view on code. I am working through those issues and have yet to come out the other side.

  5. Victor (2 comments.) says:

    @Andrew
    I’m sorry, you did not say anything about the WP core code. The note was ment a bit cynical. WP is cool :)

  6. Joshua says:

    I suppose this is the question

    [blockquote]So, should those WordPress developers who are familiar with these techniques hold off on using them in their plugins or themes to make sure that other developers can more easily adapt their code?[/blockquote]

    Gee, why should I care about other developers? If I see that a certain coding technique is beneficial for my purpose, than I will use it, even if the rest of the world (exageration) couldn’t understand it. I don’t expect my code will be adapted, integrated, or copied. I expect my code will be downloaded and used, as a plugin. If it works, then mission completed. I write plugins not to show off my code to other developers; they’re for users.

  7. Hikari (79 comments.) says:

    Well, I’d for sure not stop using good techniques and design patterns just to keep my code more readable for ppl that don’t understand them to start with.

    Readability is achieved with good comments and documentation, not to the costs of quality code.

    Before doing something as evoiding classes or some design pattern for making it easier for other ppl to understand my code, I’d learn some PHP auto-documentation IDE. It was automatic when I developed using Java (IDE created comments structure and built HTML docs), now with PHP I know nothing of this kind.

    I’ve seen a few plugins really hard to understand, and a few very well structured. I assume that when the creativity is here I skip commenting and code like crazy, and not always I go back and detail what each piece of code is doing, but anyway if somebody needs just send me a comment asking and I’ll explain :P

  8. Andrew@BloggingGuide (63 comments.) says:

    Nothing is absolutely perfect. I am using WordPress and it may have some downs but at least it’s helping me do what I have and need to do and better.

  9. Ryan Boren (1 comments.) says:

    If you go back to the b2 days, the WP code base is almost a decade old. Nothing that old is going be ideologically pure or particularly pretty, especially if it is popular.

    Back in the b2 days PHP didn’t have much OOP support to speak of. We’ve slowly made some parts OOP or at least OOP-ish, but I for one am in no hurry to reinvent the code base. I’ve spent a couple decades doing Smalltalk, Java, and C++ development. I’ve written CORBA ORBs and object databases and have suffered enough UML for a lifetime. I’ve seen all kinds of patterns have their day. Despite or maybe because of all of that experience, I’m not in a hurry to impose OOP on WP. The benefit to end users is negligible and there is significant downside in the possibility of just creating a bunch of classy bugs. Such endeavors usually amount to engineering masturbation. The code is only one part of the success of a project and is not always even the most important. If WP had started from scratch or undergone a massive rewrite, it wouldn’t be what it is today. It might be a bit prettier on the inside, but not many people would notice or care.

    As for the code being hard to understand, I don’t think it’s all that hard. The most obscure parts are the ones that use classes, ironically. The really old parts where globals and such have been preserved for backward compatibility are also rather hard to follow, but most all of that stuff has been deprecated. Regardless, crank up your IDE and step through, the flow is pretty easy to wrap your mind around and almost all functions have inline documentation these days. Compared to some projects I’ve worked on that use tons of heavily abstracted classes, the straightforwardness is refreshing.

    Anyhow, there’s a lot of history in the WP codebase. Instead of reinventing it in fell swoops we’ve concentrated on delivering things users might actually want while gradually making the code prettier and better organized. That doesn’t necessarily mean switching things to the favored OOP patterns of the day, however. Sometimes you just need a function.



Obviously Powered by WordPress. © 2003-2013

page counter
css.php