Clarify scope of PHP coding standards for core (major version) and contrib code

Created on 1 October 2011, over 13 years ago
Updated 12 January 2024, over 1 year ago

Problem

  • Uncertainty about when or how to apply coding standards across Drupal core versions and core vs. contrib code.

Goal

  • Clarify the scope of coding standards with regard to
    1. major versions of core
    2. core vs. contrib code
  • Explicitly specify/state which particular coding standards have been different for earlier versions.

Details

  • In #1290258-59: The data type should be explicitly stated for all Drupal core @param and @return documentation. some (legit) confusion arose around my statement in a contrib issue:

    Drupal coding standards are version-independent and "always-current". All new code should follow the current standards, regardless of (core) version. Existing code in older versions may be updated, but doesn't necessarily have to be. Especially for larger code-bases (like Drupal core), updating the code of a previous version for current standards may too huge of a task. However, code in current versions should follow the current standards. Lastly, when following this practice, make sure to not squeeze coding standards updates/clean-ups into otherwise unrelated patches.

  • Based on that, the main people caring for Drupal coding standards discussed it and added the following intro text to http://drupal.org/coding-standards:

    Drupal coding standards are version-independent and "always-current". All new code should follow the current standards, regardless of (core) version. Existing code in older versions may be updated, but doesn't necessarily have to be. Especially for larger code-bases (like Drupal core), updating the code of a previous version for the current standards may too huge of a task. However, code in current versions should follow the current standards.

    Note: Do not squeeze coding standards updates/clean-ups into otherwise unrelated patches. Only touch code lines that are actually relevant. To update existing code for the current standards, always create separate and dedicated issues and patches.

    Based on the confusion that arose in aforementioned issue, this could have probably been discussed some more. ;)

  • As determined in aforementioned issue, there are coding standards - e.g., for string concatenation - which we currently apply differently for Drupal core patches depending on the core version a patch is for.

    I.e., patches backported from D7 to D6 may be adjusted for the differing string concatenation rules being used throughout Drupal 6 core for consistency.

    (Note, however, that I (sun) am currently not sure whether this "should" is actually turned into a "required" for backported D6 patches.)

  • The above coding standards intro text was primarily intended to clarify the scope of current coding standards in contributed extensions, and also clarify how to update (or ignore) existing code.

Proposed resolutions (with pros and cons)

In #23, webchick postponed this issue until blockers to #4: Use Coder Review are resolved.

Remaining Tasks

See: #1299710: [meta] Automate the coding-standards part of patch review

📌 Task
Status

Closed: outdated

Component

Documentation

Created by

🇩🇪Germany sun Karlsruhe

Live updates comments and jobs are added and updated live.
  • Coding standards

    It involves compliance with, or the content of coding standards. Requires broad community agreement.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇿New Zealand quietone

    I have read the IS and most of the comments. I admit that after #23, which I agree with, I started to skim. It was interesting to read about the challenges faces 12 years ago. Fortunately, and as far as I can tell these problems are in the past. Complying with coding standards is still a challenge but much is automated now.

    Based on #23 and the lack of discussion for 12 years I am closing this issue. I think outdated is the best status.

Production build 0.71.5 2024