Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-1712

Default parameters should not be defined

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
      None
    • Message:
      Add an overloaded method to define [parameter name|parameter number n]
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Covered Languages:
      C, C++
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min

      Description

      Setting method parameter defaults seems like a tidy way to make a method more usable. However, function pointers to methods with defaulted parameters can be confusing, because the function signature may not seem to match the call signature. Therefore, the use of multiple, overloaded methods is preferred.

      Noncompliant Code Example

      void HelloWorld (string name="World")
      {
          cout << "Hello " << name << endl;
      }
      

      Compliant Solution

      void HelloWorld (string name)
      {
          cout << "Hello " << name << endl;
      }
      
      void HelloWorld ()
      {
          HelloWorld("World");
      }
      

      See also

      • S3719

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              ann.campbell.2 Ann Campbell
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: