Details

    • Type: Sub-task
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Component/s: Coding style
    • Labels:
      None

      Description

      https://docs.moodle.org/dev/Coding_style#Wrapping_lines

      if (a_long_condition() &&
              a_nother_long_condition()) {
          do_something();
      }
      

      https://docs.moodle.org/dev/Coding_style#Wrapping_Control_Structures

      $coursecategory = ($element['object']->is_course_item() or $element['object']->is_category_item());
      $scalevalue = in_array($element['object']->gradetype, array(GRADE_TYPE_SCALE, GRADE_TYPE_VALUE));
       
      if ($coursecategory and $scalevalue) {
      

      So do we add to new line with extra spaces, or do we break it into variable assignments with tests?

      My preference is a variation on the latter:

      $dosomething = a_long_condition();
      $dosomething = $dosomething && a_nother_long_condition();
       
      if ($dosomething) {
          do_something();
      }
      

      Either way, the examples offer opposing advice - the 'good' example in wrapping control structure is basically the 'bad' example in wrapping lines.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              poltawski Dan Poltawski
              Reporter:
              dobedobedoh Andrew Nicols
              Participants:
              Component watchers:
              Marina Glancy, Eloy Lafuente (stronk7)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated: