Moodle
  1. Moodle
  2. MDL-9585

rfc: coding convention change: keep functions in libraries

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.8
    • Fix Version/s: 1.8.1
    • Component/s: General
    • Labels:
      None
    • Affected Branches:
      MOODLE_18_STABLE
    • Fixed Branches:
      MOODLE_18_STABLE
    • Rank:
      24578

      Description

      There seems to have been an increased move for functions to support scripts to end up at the bottom of those scripts rather than in libraries, which is fine except at the moment that you want to reuse them some place else.

      The latest example of this (which is what has just bitten me) is mod/data/preset.php - I want to programmatically

      • create an instance of a database module
      • import a preset
      • do stuff (migrate entries from a glossary)

      at moodle upgrade time

      and all the code to deal with importing the preset (including a class!) is in preset.php which obviously I can't just include because it's not a library.

      I know it's relatively trivial for me to just move stuff (although I want this in 1.8, not head), but I wonder if it's worth getting some feedback about this from the wider dev community about coding conventions.

        Activity

        Hide
        Martin Dougiamas added a comment -

        The convention is DEFINITELY to keep all those functions in lib.php (if it's ever likely to be used from outside the module) or locallib.php (if you're sure the outside world will never use it). I'm pretty sure this is already in the coding guide.

        The preset.php situation is an anomaly hangover from the Google SOC student who wrote it and had to keep his damage localised

        Please move it if you need to! Thanks!! (Even in 1.8)

        Show
        Martin Dougiamas added a comment - The convention is DEFINITELY to keep all those functions in lib.php (if it's ever likely to be used from outside the module) or locallib.php (if you're sure the outside world will never use it). I'm pretty sure this is already in the coding guide. The preset.php situation is an anomaly hangover from the Google SOC student who wrote it and had to keep his damage localised Please move it if you need to! Thanks!! (Even in 1.8)
        Hide
        Penny Leach added a comment -

        I moved the database preset stuffs

        Show
        Penny Leach added a comment - I moved the database preset stuffs

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: