Skip to content

Use early return on view function - #270

Open
brunodles wants to merge 1 commit into
djdiskmachine:masterfrom
brunodles:refactorEarlyReturnOnViewFunctions
Open

Use early return on view function#270
brunodles wants to merge 1 commit into
djdiskmachine:masterfrom
brunodles:refactorEarlyReturnOnViewFunctions

Conversation

@brunodles

Copy link
Copy Markdown

Just a small change to reduce the amount of indentation of these functions.

Does not introduce any other changes, just reorganize and format the code.

@brunodles brunodles mentioned this pull request Aug 17, 2026
8 tasks
@djdiskmachine

Copy link
Copy Markdown
Owner

.. But we're returning early on minilayout 😄

@brunodles

Copy link
Copy Markdown
Author

What this PR is proposing is to simplify the functions.

These functions are all contained within the same if. The idea is to extract this if into some kind of validation step.

Instead of adding all the code inside of the if

void View::drawMap() {
  if (!miniLayout_) {
    // draw map code
  }//!minilayout
}

The comment at the ending bracket of the if is also a good indicator that this if is too big.

We can invert the ifs logic, and remove the indentation and brackets.

void View::drawMap() {
  if (miniLayout_) {
    // stop here
    return ;
  }
  // draw map code
}

The code of the function still the same.
If you prefer we can leave it as it is.

The deb check failed due an issue to install the required libraries.

@djdiskmachine

Copy link
Copy Markdown
Owner

Ohh ok now I get it, sorry I was really tired after a day at the office. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants