I invite every single Drupal developer, core or otherwise, to read my remarks about Drupal coding culture here:

http://drupal.org/node/418830#comment-2765254

It does not mean I am not grateful for what Drupal can do and has done for me, and it runs many sites for me. I can't stand the way Drupal (not PHP) is coded. I am an advocate of strongly graphical UML-driven development (mostly Java), however the points I have to make about Drupal not embracing even basic object oriented patterns like use of interface contracts and dependency injection are nothing to do with PHP. It is just Drupal, and I would stand in a room with any single person on Drupal.org and if they don't understand why I find the way it is coded simply infuriatingly messy, I would be delighted (honestly) to explain it to you.

I want the whole of Drupal to be overhauled to use a range of basic Class, Interface and design patterns concepts that for some unknown reason are not used. PHP can support everything I would wish.

Comments

webel’s picture

You can ask yourselves as coders whether you want to spend the rest of your lives imitating what underlying compilers and language constructs already do for you,
or you can embrace object-orientation, dependency injection, design against contract patterns, and get completely for free as well a complete graphical UML representation of the entire Drupal system.

I find the current Drupal API and the way it is coded so unwelcoming, that I hesitate to contribute modules at all, it makes me want to avoid any coding against it, and I just try to do whatever I can with the CMS and with contributed features. And given that I love coding and am very experienced (over 30 years) that must tell somebody something.

The Drupal API makes me absolutely starving thirst for UML-driven Java, like a man in a desert without a beer.

Dr Darren Kelly (Webel)

Webel IT Australia, "Elements of the Web", Scientific IT Consultancy,
For PHP-driven Drupal CMS web sites, Enterprise Java, graphical UML, UML Parsing Analysis, SysML, XML.

webel’s picture

Example: a new development site to go live soon elsewhere, anonymous public users can list metadata only, not access attached documents:

The Project Performance International Systems Engineering Goldmines

I otherwise specialise in applications of strongly graphical systems and software engineering to modeling, control, and simulation of scientific instruments (such as particle accelerators, radiotelescopes, neutron beam instruments), modelling and simulation of nuclear systems, and hold courses in Unified Modeling Language (UML) (mostly for Java) and the new SysML Systems Engineering dialect, which I use extensively:

http://www.webel.com.au
http://www.webel.com.au/uml
http://www.webel.com.au/sysml
http://www.webel.com.au/java

And I develop synthesis systems, including a body music system employing accelerometers, and have for over a decade worked on a system to enable people to hear body music (and make body motion light shows) while dancing, exercising, riding a bike anywhere, completely independent of any reference system (because only dependent on acceleration), to replace your iPod with an "iBody" I call a Drancel:

http://www.webel.com.au/project/drancing

You will be able to wear multiplexed Drancels on our wrists, feet, and waist and hear yourself (and see yourself as an LED light show) as you go anyway, using real-time synthesis of accelerometer signals.

I use Drupal technology to present these things, am grateful for it, and I want to it to work well, for a very long time.

Webel IT Australia, "Elements of the Web", Scientific IT Consultancy,
For PHP-driven Drupal CMS web sites, Enterprise Java, graphical UML, UML Parsing Analysis, SysML, XML.

joachim’s picture

What bugs me when working with Drupal is more the limitations and WTFs of PHP. If one were going to rewrite Drupal from scratch, use a better language.

I have to say I like the hook system. It's not without its flaws, but it enables you to accomplish powerful things and big changes in little code. It does lead to glue modules that are nothing but a bunch of hooks whose interaction is mysterious at best -- but that is what documentation is for.

webel’s picture

@joachim

One major problem is that hook tricks thwart integration with many IDEs features, it makes it much harder to move through the system than with class-encapsulated hooks. Being a Java IDE person (and for example Netbeans IDE has quite good PHP support, as much as an untyped "scripting" language admits it), the Drupal hook system gets on my nerves. No IDE can following/pre-empt string concatenation tricks used to achieve hooks).

I am talking here about a large percentage of development time for every single developer.

Webel IT Australia, "Elements of the Web", Scientific IT Consultancy,
For PHP-driven Drupal CMS web sites, Enterprise Java, graphical UML, UML Parsing Analysis, SysML, XML.

joachim’s picture

Oh GAH netbeans.

If you don't tolerate hooks, I don't tolerate an IDE that can't even support basic text editing features such as selecting words and drag & drop! ;)

webel’s picture

I wrote at http://drupal.org/node/418830#comment-2765254:

this is the kind of thing I am talking about (often elsewhere on Drupal.org as an ongoing theme) that drives me mad when working with Drupal code, nearly all of it, core and contributed, and it has nothing to do with PHP (which has excellent object-oriented support and class and interface handling features and the ability to design against interface contracts), at all, it is simply Drupal culture, a trick that has become an obsessive anti-pattern:

    // Let modules modify the view just prior to executing it.
    foreach (module_implements('views_pre_view') as $module) {
      $function = $module . '_views_pre_view';
      $function($this, $display_id, $args);
    }

I realise fully that this code comes from Views developers, and how important that module is (and how much work it does for my life). There is absolutely no need (except for in Drupal culture) to play games like that with method names. None.
There are some nice things one can do because on can manipulate function names and pass them around, but this example above is not one of them.

Just because one can manipulate functions as names and pass them around in PHP does NOT mean that it is a good idea to always do it. The code above is essentially repeating what object-oriented structures enable us to avoid. I would like every single Drupal developer to read this and know: I don't think you, any of you, should be or need to keep doing that, and I find the way Drupal is coded so bad at times that I really have to ask seriously whether I can stay with the technology, even when it now runs many sites for me (some of which ironically teach advanced graphical object-orientation for UML+Java).

I want to, seriously, completely rewrite all of Drupal from top to bottom, because I am weary of tricks like this.

Step 1: isolate this very important architectural strategy as (one or more) dedicated methods, so that the approach is decoupled from other aspect of module development. If want to take this omniprescent drupal hack (and that is what it is) and all of its drupal hook cousins and at least quarantine them (via interface operations) in methods that provide what are essentially architectural language services, so that the policy is isolated and the implementation can be varied.

Stage 2: You are then welcome to do your string concatenation hack inside that method, if you still really want to.

Stage 3: Then, module developers can develop against an architectural interface, buffered from changes in the implementation thereof, which may eventually embrace proper object orientation, or in this case calling against a method of a Module subclass employing protected hook methods (rather than a string concatenation trick that looks like a compiler working overtime).

Stage 4: module developers can then, completely robustly, move towards a completely object-oriented drupal (such as in this case invoking operations on a Module interface directly, instead of the architectural buffer).

Webel IT Australia, "Elements of the Web", Scientific IT Consultancy,
For PHP-driven Drupal CMS web sites, Enterprise Java, graphical UML, UML Parsing Analysis, SysML, XML.

joachim’s picture

Step 1 already exists: module_invoke() and module_invoke_all(). Just due to pass by reference limitations they don't always apply, AFAIK.

guypaddock’s picture

@webel, I myself have been thinking about porting Drupal to OOP lately. I find that in larger enterprise applications is where Drupal's tricks really start to hurt a lot. So, if it were me, I would probably choose Java as the new language, perhaps using Servlets (though from working with them I know how painful they can be to get set-up), so that enterprise developers can feel comfortable using the system.

I would re-factor the core of Drupal first, making all of its core design OOP, but build a module that provides a compatibility layer -- an interface to enable many existing Drupal modules written in PHP to be used on the new system until appropriate re-writes could be done. The neat thing about Java and PHP being cousins of a sort (as Zend borrowed a lot from Java's language) is that there is a fair amount of support for integration with Java in PHP. The hard part about this compatibility layer would be in keeping track of the translations from PHP functions to OOP methods and objects, but I don't think it will be that bad once the core architecture is in place.

What do you think?