SAP / abap-cleaner

ABAP cleaner applies 95+ cleanup rules to ABAP code at a single keystroke
Apache License 2.0
457 stars 48 forks source link

perhaps interesting for ABAP Cleaner too: Sort combined DATA statements (ABAP Quick Fixes 1.1.5)? #346

Open VladGhitulescu opened 3 months ago

VladGhitulescu commented 3 months ago

Hey,

After updating Eclipse & Co. I've just discovered an useful update to ABAP Quick Fixes (version 1.1.5): "Sort combined DATA statement":

CleanShot 2024-07-30 at 13 52 00

CleanShot 2024-07-30 at 13 52 02

CleanShot 2024-07-30 at 13 52 03

What do you think?

Regards, Vlad

ghost commented 1 month ago

I think first of all we have "Do not chain up-front declarations" and we should not encourage deviating from the recommendation by implementing what you proposed.

Secondly, I don't have a resource at hand, but I also think that it is recommended to declare your variables right before you use them, not at the very top in a very big block like in the example. "Prefer inline to up-front declarations" is related to that.

jmgrassau commented 1 month ago

Hi Vlad,

I'm not sure whether an alphabetical order is really what you'd want? What ABAP cleaner currently offers is the rule "Rearrange local declarations", which sorts 1. by declaration keyword (TYPES, CONSTANTS, STATICS, DATA, FIELD-SYMBOLS) and 2. among the same keyword, "in order of appearance", so the local variable that is used first will be declared first. IMHO, this helps readability of long methods with many variables, because variables that are used in the same section of the method are then declared together. Looking at the configuration options, you can also move variables to the innermost blocks. It would be possible, of course, to add another option for alphabetical sorting here.

Kind regards, Jörg-Michael

P.S.: A true clean code advocate would of course tell you that there is never the need for more than 2-3 variables in a method. But judging from reality, I doubt that's true for ABAP…