[keyword] anti-pattern

[antipattern] Not invented here

Wikipedia quotes

In programming, it is also common to refer to the NIH "Syndrome" as the tendency towards reinventing the wheel (reimplementing something that is already available) based on the belief that in-house developments are inherently better suited, more secure or more controlled than existing implementations.


Source: Not invented here Version date: 2014-02-19

Far too often, Drupal shops and Digital Media Agencies insist on reinventing the wheel by developing in-house contributed modules, either because they have "Not Invented Here" syndrome, or because they have not taken the time to do proper technology assessment of the (as of Feb 2014) over 14,000 contributed Drupal modules !

[antipattern] Java Interface constants [if abused]

Wikipedia quotes

In the Java programming language, the constant interface pattern describes the use of an interface solely to define constants, and having classes implement that interface in order to achieve convenient syntactic access to those constants. However, since constants are very often merely an implementation detail, and the interfaces implemented by a class are part of its exported API, this practice amounts to putting implementations details into the API, which was considered inappropriate by e.g. Java designer Joshua Bloch.[1] In general, collecting system constants into classes independent of behaviour might create a poor object-oriented design because it is often a sign of low cohesion. It is for these reasons that implementing constants interfaces may be considered to be an anti-pattern.

Use of this pattern has a few other downsides:

1. It pollutes the class namespace with read-only variables that may not be of use.

2/ Contrary to the compile-time tactical utility of implementing a constants interface, the incidental run-time artifacts have little practical purpose (cf. marker interfaces which also have no methods but are useful at run-time).

3. If binary code compatibility is required in future releases, the constants interface must remain forever an interface (it cannot be converted into a class), even though it has not been used as an interface in the conventional sense.

4. Without an IDE that resolves where the constant are coming from, tracking it back to its containing class or interface can be time consuming.

5. A variable (representing an instance) of the interface is syntactically no more useful than the interface name itself (since it has no methods).

Note that the Java libraries use constant interface pattern themselves, proving that it may be a reasonable choice in some situations.
Source: Constant interface Version date: 2014-01-02

I do not wish to enter into the raging debates about whether this is an anti-pattern in the Java language (which in fact in some places uses this very approach), I merely wish to emphasise that the reasons for not using an interface to encapsulate constants in PHP (and thus for Drupal) are less compelling.

Compare with the "pattern" PHP Interface constants [if used wisely].

[antipattern] Write Everything Twice (WET) (because "we enjoy typing")

HOT TIP: this content is flagged as highly recommended !
Wikipedia quotes

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." ..


DRY vs WET solution

Violations of DRY are typically referred to as WET solutions, which is commonly taken to stand for either "write everything twice", "we enjoy typing" or "waste everyone's time".

Source: Wikipedia: Don't repeat yourself, DRY vs WET solutions Version date: 2016-04-21

PLEASE READ TOP-TO-BOTTOM: This is an example of Writing Everything Twice (WET) code in typical Drupal-style, taken from the Current posts module example at Creating modules - a tutorial: Drupal 7.x:

Software Design Patterns and Anti-Patterns

This zone is by no means a complete or exhaustive list of design patterns or anti-patterns; it mentions only those I consider currently most relevant for the Webel tutorial modules, and also (especially the anti-patterns) for refactoring of Drupal core and prevailing Drupal contributed module coding habits.

Subscribe to RSS - anti-pattern