abap-cleaner icon indicating copy to clipboard operation
abap-cleaner copied to clipboard

Statements alignment

Open VladGhitulescu opened this issue 1 year ago • 5 comments

Hey,

I still have an issue with the alignment of statements that are NOT separated by an empty line:

CleanShot 2024-01-19 at 16 52 26

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

VladGhitulescu avatar Jan 19 '24 15:01 VladGhitulescu

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

jmgrassau avatar Feb 09 '24 13:02 jmgrassau

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

VladGhitulescu avatar Feb 09 '24 13:02 VladGhitulescu

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 avatar Mar 12 '24 09:03 mraht

@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... ;-)

VladGhitulescu avatar Mar 12 '24 09:03 VladGhitulescu

… 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

mraht avatar Mar 12 '24 10:03 mraht