Skip to content

[Close Brackets at Line End] Is this always a good thing? #353

@pokrakam

Description

@pokrakam

Relevant sections of the style guide
Close Brackets at Line End

Description
I would like to challenge this rule. For starters, the default behaviour in ADT is the opposite. But there are numerous languages (JavaScript, C++ and Java) where closing on a new line is widely recommended. Personally I used to dislike it, but since learning more JavaScript I've gotten accustomed to it and also caved in and started to use the ADT defaults in ABAP. I was pleasantly surprised to find it increases readability and maintainability in ABAP for complex parameters with multiple brackets. It's fewer lines vs clarity, and I think sometimes clarity is better.
It makes sense in functional-styled languages as there can be several lines and nesting levels in between brackets, and functional ABAP is also evolving in this direction.

See for example SAP's own JS Guidelines and Google's Java Style Guide

I would suggest softening this rule, or recommending that the outermost brackets (and only those) can be on the last line.

Examples
The current examples in the ABAP Style Guide are simple, and it makes sense to have the brackets at line end if there are no additional brackets within the parameters.
But, especially with the shift to functional ABAP, more complex parameters become harder to read, especially with multiple method calls after another. I often find myself counting brackets, and having the outermost one separated JS-Style reduces the perceived bracket depth by one level.

I find this one harder to read:

myobj->do_stuff( 
  key   = item->key
  value = COND #( WHEN date > sy-datum
                  THEN get_estimate( )
                  ELSE get_current( ) )
  data  = CONV #( get_something( ) ) ).

Better (and ADT default):

myobj->do_stuff( 
  key   = item->key
  value = COND #( WHEN date > sy-datum
                  THEN get_estimate( )
                  ELSE get_current( ) )
  data  = CONV #( get_something( ) ) 
).

Or maybe the rule could be further qualified along the lines of "no more than two levels of nesting on one line".

This is not without precedence in ABAP either, we do see closing brackets on a new line in chained method calls (although I must admit I find this less visually appealing):

result = add( a 
  )->add( b
  )->add( c 
  )->add( d ).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Adjustment Of RuleThe issue or PR proposes an adjustment of a rule or set of rulesclean-abap

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions