Test boolean methods implicitly

images/thumbnail.jpg - Thumbnail

A quick reminder. I thought this was obvious but I keep seeing IF statements that explicitly test the result of a boolean method against ABAP_TRUE or using INITIAL. There’s no need! ABAP is clever in this regard.

Instead of this:

IF dog->is_happy( ) = abap_false.
  dog->feed( treat ).
ENDIF.

Just do this:

IF dog->is_happy( ).
  dot->feed( treat ).
ENDIF.

Simpler, cleaner, more readable.

Abapinho sends his regards.