abap-cleaner
abap-cleaner copied to clipboard
Statements alignment
Hey,
I still have an issue with the alignment of statements that are NOT separated by an empty line:
I would expect that the = signs should be aligned although the first line belongs to one structure (gs_status) and the last two belongs to another structure (is_adrc_sugg).
What do you think?
Thanks!
Regards, Vlad
Hi Vlad,
actually the Styleguide is quite clear on that, saying Align assignments to the same object, but not to different ones, and I have already come across quite a number of hard-to-read real-life cases where only this restriction helped to realize that two different structures are used:
ls_struc_p_with_long_name-component_a = 1
ls_struc_p_with_long_name-component_b = 2
ls_struc_q_with_long_name-any_component = 3
ls_struc_q_with_long_name-other_component = 4
This could much more easily be missed if all lines were aligned:
ls_struc_p_with_long_name-component_a = 1
ls_struc_p_with_long_name-component_b = 2
ls_struc_q_with_long_name-any_component = 3
ls_struc_q_with_long_name-other_component = 4
Kind regards, Jörg-Michael
Hi Vlad,
actually the Styleguide is quite clear on that, saying Align assignments to the same object, but not to different ones, and I have already come across quite a number of hard-to-read real-life cases where only this restriction helped to realize that two different structures are used:
ls_struc_p_with_long_name-component_a = 1 ls_struc_p_with_long_name-component_b = 2 ls_struc_q_with_long_name-any_component = 3 ls_struc_q_with_long_name-other_component = 4
This could much more easily be missed if all lines were aligned:
ls_struc_p_with_long_name-component_a = 1 ls_struc_p_with_long_name-component_b = 2 ls_struc_q_with_long_name-any_component = 3 ls_struc_q_with_long_name-other_component = 4
Kind regards, Jörg-Michael
Hi JM,
thanks for the reply!
Hmmm... for me your lower alternative is definitely more readable, but again, maybe that's just me: If I would like to differentiate the statements more I would insert an empty row between them (and still align the = ;-)
How do you see this?
Thanks again!
Regards, Vlad
In the case Jörg-Michael mentioned it would be possible to control that via line breaks thus the statements mentioned could be aligned like this:
ls_struc_p_with_long_name-component_a = 1
ls_struc_p_with_long_name-component_b = 2
ls_struc_q_with_long_name-any_component = 3
ls_struc_q_with_long_name-other_component = 4
The developer decides which statements are to be aligned together.
@mraht On the one hand, this is exactly what I've got initially (without the line break)
ls_struc_p_with_long_name-component_a = 1 ls_struc_p_with_long_name-component_b = 2 ls_struc_q_with_long_name-any_component = 3 ls_struc_q_with_long_name-other_component = 4
On the other hand…
In the case Jörg-Michael mentioned it would be possible to control that via line breaks
… controlling through line breaks will permit something like what I've asked for
> ls_struc_p_with_long_name-component_a = 1
> ls_struc_p_with_long_name-component_b = 2
> ls_struc_q_with_long_name-any_component = 3
> ls_struc_q_with_long_name-other_component = 4
(I hope they get aligned in the end :-) by only inserting a line break after the above block of code.
The developer decides which statements are to be aligned together.
This is the idea, yes (a man can dream... ;-)
… controlling through line breaks will permit something like what I've asked for
Ok, to clarify my idea as I'm not sure I explained it correctly: In case of line break (single ENTER) everything is being aligned together. In case of two line breaks (new paragraph; 2x ENTER) the next lines are aligned together but not the ones of the previous paragraph:
" two paragraphs
ls_struc_p_with_long_name-component_a = 1
ls_struc_p_with_long_name-component_b = 2
ls_struc_q_with_long_name-any_component = 3
ls_struc_q_with_long_name-other_component = 4
" vs. one paragraph
ls_struc_p_with_long_name-component_a = 1
ls_struc_p_with_long_name-component_b = 2
ls_struc_q_with_long_name-any_component = 3
ls_struc_q_with_long_name-other_component = 4