[pattern] Don't Repeat Yourself (DRY Principle)

HOT TIP: this content is flagged as highly recommended !

In software engineering, don't repeat yourself (DRY) is a principle of software development aimed at reducing repetition of information of all kinds, especially useful in multi-tier architectures. The DRY principle is stated as "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system." ..

When the DRY principle is applied successfully, a modification of any single element of a system does not require a change in other logically unrelated elements. Additionally, elements that are logically related all change predictably and uniformly, and are thus kept in sync.

Source: Wikipedia: Don't repeat yourself Version date: 2013-12-12

Drupal code (and note I don't blame PHP here), both core and contributed, breaks the DRY principle so often, so constantly, so annoyingly repetitively, that it actually makes me (otherwise used to nicely coded object-oriented Java or C++ with model-driven support through graphical UML) feel like this:

This web site and the OOE = Object Oriented Examples = One Of Each module were in part created to discourage further repetition of .. well nearly everything that is repeated in Drupal code, like those strings used as keys of structured arrays that have no intelligence other than documented key conventions, instead of intelligent objects.

I promote here techniques for avoiding having to Write Everything Twice (WET) (because "we enjoy typing") (where I provide some examples of typical Drupal code persistently breaking the DRY principle), and through it techniques that are friendly for IDE-prompting, as demonstrated through the truly object-oriented tutorial module OOE = Object Oriented Examples = One Of Each.

The OOE poem: "An ode to WET and DRY"

With OOE = Object Oriented Examples = One Of Each style coding,
you will never have to directly use structured arrays ever again in Drupal.
And you will never again have to repeat "by hand" or struggle to remember
those "documented" and "by convention" string keys of Drupal structured arrays !
Because the OOE bridge encapsulates them instead in classes friendly to IDE prompting.
The OOE Classes are able to pass completely valid Drupal arrays back to Drupal core for you !

Visit also