Rule feedback: reorder definitions to the top of routine
See original GitHub issueI have an issue with this check existing at all. It violates the good practice of using the most restrictive visibility.
Example:
method test.
DATA:
some_flag type abap_bool,
some_string type string.
some_flag = abap_false.
"
"imagine 15 lines of code here
"
some_string = 'value'.
" some more code here
endmethod.
By placing the declaration at the top, I’m making the string visible to the part of the method I’m not using it in. I’d rather do
method test.
DATA: some_flag type abap_bool.
some_flag = abap_false.
"
"imagine 15 lines of code here
"
DATA: some_string type string.
some_string = 'value'.
" some more code here
endmethod.
If I don’t intend to use the string in the first half of the method, I shouldn’t need to declare it at the beginning - then I’m protected against accidental usage and I’m making my reasoning about the usage explicit to future maintainers.
This is precisely why inline data declarations are good (they have their own scoping issues, but that is another matter), but these might not be available on your release.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Definitions in top of routine - abapOpenChecks
Check that DATA and other definitions are in top of routine(FORM/METHOD). Traditionally variables are declared at top of modularization block.
Read more >A Guide to the Rulemaking Process - Federal Register
For information on using the federal eRulemaking portal to submit comments, go to the. Regulations.gov “Help” pages on submitting a comment. Before the...
Read more >Ground Rules for Teams: Definition and Examples | Indeed.com
Ground rules are standards set by a team to help them function in the future. In order to work effectively, the team should...
Read more >PDCA Cycle - What is the Plan-Do-Check-Act Cycle? - ASQ
The Plan–Do–Check–Act cycle is a four-step model for carrying out change. Learn more about the PDCA cycle and how to implement the model...
Read more >Part 2 - Definitions of Words and Terms | Acquisition.GOV
Change order means a written order, signed by the contracting officer, directing the contractor to make a change that the Changes clause ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
as close to the first use as possible
- not entirely.should declare like this
not
so it should be
as close as possible without breaking the code or violating the sane block scoping rules in other languages
ABAP is a dangerous place, anyhow, I’m having a go at it https://github.com/abaplint/abaplint/pull/933