Uploaded image for project: 'OpenMRS Core'
  1. OpenMRS Core
  2. TRUNK-5845 Search and fix minor errors and typos
  3. TRUNK-5957

Local variables should not be declared and then immediately returned

    XMLWordPrintable

Details

    • Sub-task
    • Status: Closed
    • Could
    • Resolution: Fixed
    • None
    • Core 2.5.0
    • None
    • Low

    Description

      From SonarQube:

      Declaring a variable only to immediately return or throw it is a bad practice.

      Some developers argue that the practice improves code readability, because it enables them to explicitly name what is being returned. However, this variable is an internal implementation detail that is not exposed to the callers of the method. The method name should be sufficient for callers to know exactly what will be returned.

      First case:

      Second case:

      Problem:
      Create a local variable just to be returned immediately.

      Solution:
      Return an interesting value immediately, without creating unnecessary variables.

      Gliffy Diagrams

        Attachments

          Activity

            People

              sacull Lukasz Debicki
              sacull Lukasz Debicki
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: