Usage of QUIT to exit a method

objectscriptQuality release 
1.0.0
Id 
OS0031
Rule type 
Code Smell
Severity 

Major

Major
SQALE characteristic 
  • Maintainability
    • Understandability
Tags 
cache-2014, clarity, coding-guidelines
Remediation function 
Constant/issue
Remediation cost 
2min

The QUIT command can be used for three different scenarios in program code:

  • exit the method with no value;
  • exit the method with a value;
  • breaking out of a loop statement, try block or catch block.

As a result, this can lead to code where it is very confusing to actually detect the usage, all the more that the nesting level is deep and the code is long; consider for instance:

    Method m()
    {
        for {
            if (somecondition) {
                quit // breaks out of the for loop, does not return!
            }
        }
        write "always printed!", !
        quit // this one actually returns
    }

For this reason, it is preferable to always use RETURN when the intent is indeed to terminate the execution.