Closed larshp closed 1 year ago
I always followed this rule: If explicit declaration then move to top, if inline it's fine within nested branches as long as you don't use it outside that branch which would technically be possible. Not sure if that's the best approach.
yea, I agree, but its strictly not what the description conveys
it should be something like "Dont use inline in unrelated branches" or "Only use inline within branch where its defined"
I agree. An additional example would be nice. It should outline that this is perfectly fine if the variable is only used in the "nesting scope". Both an ELSE
branch as well as an access at the top-level of the method body would be considered "outside" of the nesting scope of the IF
branch where it is introduced.
I'm with @fabianlupa on this: if it's used in multiple branches, the declare explicitly. It's OK to declare inline if it's only used in the same branch and not anywhere else. Text could be updated accordingly, otherwise as @larshp pointed out, it sounds like no one will be able to use inline declarations in like 50% of cases.
https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#dont-declare-inline-in-optional-branches
In this example a variable is declared in an optional branch,
according to the rule description, this is not good, and should be changed to
? effectively a lot of inline declarations should not be used, ever?