styleguides icon indicating copy to clipboard operation
styleguides copied to clipboard

Don't avoid `check` in all 'other' positions

Open jdgx opened this issue 4 years ago • 0 comments

Hi all,

this is regarding the section Avoid CHECK in other positions, which recommends to only use check in the initialization of a method. I think there are several good (and clean) examples, which have check in other positions, e.g.:

method i_am_ready_to_go.

  result = abap_false.

  check bags_are_packed( ).
  check i_have_got_my_wallet( ).
  check not windows_are_open( ).
  check i_have_got_my_keys( ).

  result = abap_true.

endmethod.

In this example, the alternatives to check (if/return or putting the four individual conditions into a single statement or decorating every check line with a pseudo comment) would not improve the code (imho).

My feeling is that in general having the check statement at the "highest level" (not nested inside any other control structure such as if, case, loop etc.) of a method is should not be an issue.

Best, Jonathan

PS: One (meta-)remark: I don't think that each and every of such cases needs to be part of the CleanABAP styleguide. The styleguide clearly says that "There is no consensus on whether you should use CHECK or RETURN [...]". and it also says that it is not entitled to impose binding rules on other developers. So the styleguide leaves such decisions to the developers on purpose. I think this is a very good approach, but the problem is that some organizations think that it's a good idea to enforce the styleguide by means of code pal checks. In case my organization decides to switch on a certain check which I don't like, I have to approach them. They will tell me that this is a code pal check and code pal will tell me that they follow CleanABAP guidelines. I know that this is not the fault of code pal or Clean ABAP, but this is the fault of my organization. I just have the fear that due to a rigid enforcement of code pal checks/Clean ABAP, we could end up discussing lots of tiny little details, which is not really what is intended by code pal/Clean ABAP. Not sure what could be done to prevent this...

jdgx avatar Oct 11 '21 08:10 jdgx