OOP

Programming language trade-offs

Submitted by Larry on 30 September 2010 - 7:04pm

This article is also available in Serbo-Croatian

This article is also available in Dutch

There has been much discussion of late in Drupal about Object-Oriented Programming. That's not really surprising, given that Drupal 7 is the first version that has really tried to use objects in any meaningful way (vis, as something other than arrays that pass strangely). However, too much of the discussion has boiled down to "OMG objects are inflexible so they're evil!" vs. "OMG objects are cool, yay!" Both positions are harmfully naive.

It is important for us to take a step back and examine why one particular programming paradigm is useful, and to do that we must understand what we mean by "useful".

Programming paradigms, like software architecture, have trade-offs. In fact, many of the same methods for comparing architectural designs apply just as well to language design. To do that, though, we need to take a step back and look at more than just PHP-style objects.

Warning: Hard-core computer science action follows. If you're a coder, I recommend getting a cup of $beverage before continuing, as it could take a bit to digest although I've tried to simplify it as much as possible. There's fairly little Drupal-specific stuff here so hopefully it should be useful to any PHP developer.

How's your OOP?

Once again, I am slated to present general Object-Oriented techniques at DrupalCon. It's an important topic; sadly a large number of Drupalers don't really "get" OO programming, but Drupal 7 is starting to make heavy use of OO. There are also an enormous number of places in Drupal where a more Object-Oriented approach would make the code vastly cleaner, simpler, and faster, if only more people thought to approach it from that standpoint.

Of course, the question is how to target such a session. I don't want to talk over people's heads, but I also don't want to waste your time with "this is a mouse"-level material.

So, I put the question out to you, future DrupalCon SF attendees. What level of technical detail would be most useful to you?

Important DrupalCon session change!

Submitted by Larry on 3 March 2009 - 10:22am

Just to give everyone a heads up, I have made some changes to one of my sessions. Based on the feedback I received earlier, my session on Object-Oriented Drupal has been updated. It seems no one wanted to hear about the basics, as they already knew them. :-) I will instead be focusing on design patterns, OO design philosophy, and how it applies (or should apply) to Drupal. It's too late to get changes into the printed program, but I have updated the session page on the DC DC web site to reflect the new focus.

So if you were hoping for a session on basic PHP OOP syntax and concepts, um, sorry. If you're looking for an intermediate to advanced session on how to use OOP well, then this session is for you.

I'll see you in DC!

Objectifying Drupal: What do you want to know?

Submitted by Larry on 7 February 2009 - 3:14pm

So we're a month away from DrupalCon DC 2009, and although the official schedule has not been published it seems likely from the preliminary schedule that my Objectifying Drupal session will be accepted. The basic idea is to help Drupal's mainly procedural army of developers get up to speed on object-oriented development, which has been gaining popularity in contrib (most notably the Views module) and will be in many parts of Drupal 7.

Of course, given how large an army of developers we have there is no one level of existing expertise I can target. There are entire multi-course college programs on OOP design, and I have an hour. :-) So, how about some preliminary feedback? What do you want to see in a one hour session on object-oriented code in Drupal?

Dependency injection, testing, and Drupal

Submitted by Larry on 24 December 2008 - 2:08am

Via Planet PHP I stumbled across this article decrying Singletons. It's not a new argument, really, but one of the comments pointed me toward a Google Tech Talk video entitled "Global State and Singletons". To be honest I don't agree with everything said in either the article or the video, but both are spot on about the problems of global state, something I've lamented before in relation to testing.

That is especially relevant now, as we consider the question of Handlers in Drupal. Why? Because the most controvercial part so far, the environment variable, is designed to address exactly this problem, a problem that is currently prevalent throughout all of Drupal.

Permit me to explain.

Handlers in core: Concept Needs Review

Submitted by Larry on 14 December 2008 - 7:04pm

Some time ago, I posted an RFC for pluggable "system handlers". It generated a fair bit of feedback, nearly all of it positive. That was followed up with a presentation in Szeged, which generated even more positive feedback.

So what's happened since then? Well, a fair bit. There's working code, but there are still some key gotchas to sort out. That gives us a couple of options for how to proceed, for which I would like feedback, particularly from core developers and maintainers. (Dries, webchick, this means you! :-) )

Autoloading classes in Drupal 6

Submitted by Larry on 3 October 2008 - 12:50am

I need to not have spare time. When I have spare time, I do crazy things. Not crazy things like your mother told you not to do, but things like write modules on a lark.

Like I said, dangerous. But, useful. In this case, it was a conversation over on Ryan Szrama's blog that kinda got out of hand and gave me another idea for a module, which I am happy to announce is now available for download.