Skip to content

Drop 'strong discouragement' of nested block-local variables - #34

Open
leiflindholm wants to merge 1 commit into
tianocore-docs:mainfrom
leiflindholm:block-scope-vars
Open

Drop 'strong discouragement' of nested block-local variables#34
leiflindholm wants to merge 1 commit into
tianocore-docs:mainfrom
leiflindholm:block-scope-vars

Conversation

@leiflindholm

Copy link
Copy Markdown

The rules explicitly permit variable definitions such as
if (Condition) {
UINTN Example;
...
}

But for some reason it simultaneously "strongly discourages" from it. This feels entirely wrong to me; the codebase suffers from too-long functions with too many live variables making compilers' work more difficult - preventing optimisations and periodically throwing up warnings/errors as compilers change.

Change the strong discouragement to a note on not confusing variable scope.

The rules explicitly permit variable definitions such as
  if (Condition) {
    UINTN Example;
    ...
  }

But for some reason it simultaneously "strongly discourages" from it.
This feels entirely wrong to me; the codebase suffers from too-long
functions with too many live variables making compilers' work more
difficult - preventing optimisations and periodically throwing up
warnings/errors as compilers change.

Change the strong discouragement to a note on not confusing variable
scope.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com>
@mdkinney

Copy link
Copy Markdown
Contributor

I think there would a couple reasons for this restriction. The change needs to describe what has changed since the rules were established to justify the change.

  • Avoid use of same named local variable at different scopes within a function that can make code review and maintenance challenging
  • Be able to review stack usage from local variables by reviewing declarations in one location at beginning of a function instead of searching for additional declarations throughout the function. For env where the stack size is very limited, it is important to not use large structs or arrays as local variables.

@mdkinney

Copy link
Copy Markdown
Contributor

@ajfish Please provide background for original rules for local variable declarations.

@makubacki makubacki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending any empirical concerns, I favor this change and the file content update.

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.

4 participants