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

Identifiers should not be longer than 31 characters

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Message:
      Give "xxx" a shorter name
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Legacy Key:
      IdentifierLongerThan31
    • Covered Languages:
      C, C++, Objective-C
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      10min
    • CERT:
      DCL23-C.
    • MISRA C 2004:
      5.1

      Description

      In addition to being difficult to use, too-long variable names can limit code portability. The ISO standard requires that variable, type, function and label names be no more than 31 characters long.

      Note that 31 characters is an upper bound, rather than a length recommendation. Shorter names are better, as long as they're still communicative.

      Noncompliant Code Example

      int this_is_a_very_long_identifier_that_definitely_should_be_renamed = 0;
      

      Compliant Solution

      int reasonable_identifier = 0;
      

      See

      • MISRA C:2004, 5.1 - Identifiers (internal and external) shall not rely on the significance of more than 31 character.
      • CERT, DCL23-C. - Guarantee that mutually visible identifiers are unique

        Attachments

          Issue Links

          1.
          C-Family RSPEC-4374 Language-Specification Active Unassigned

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                Anonymous
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated: