-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chained Methods/Constants #256
Comments
Personally I follow the same principle and only chain closely related entities if it aids readability (i.e. short declarations). In practice I don't chain often, and usually break up the generated declarations that quick-fix insists on chaining. In Unit Tests is where chaining is probably the most useful: "OK
METHODS setup.
METHODS:
doc_type_a_is_accepted FOR TESTING,
doc_type_b_fails FOR TESTING.
METHODS:
positive_qty_adds_item FOR TESTING,
zero_qty_no_item FOR TESTING,
negative_qty_raises_exception FOR TESTING. I prefer horizontal density, and find wading through pages of long vertical declarations becomes unhelpful. We should definitely not chain when the "anti-pattern
METHODS:
add
IMPORTING
num1 TYPE i
num2 TYPE i
RETURNING
result TYPE i
RAISING
zcx_not_a_number,
subtract
IMPORTING
num1 TYPE i
num2 TYPE i
RETURNING
result TYPE i
RAISING
zcx_not_a_number,
multiply
IMPORTING
num1 TYPE i
num2 TYPE i
RETURNING
result TYPE i
RAISING
zcx_not_a_number,
divide
IMPORTING
num1 TYPE i
num2 TYPE i
RETURNING
result TYPE i
RAISING
zcx_not_a_number
zcx_not_a_multiple. For a good antipattern, imagine class CL_WB2_REBATE_SETTLEMENT with chained declarations... |
Curiously enough, the identifiers are in plural mode: |
Since the inline declarations reduce the amount of necessary up-front declarations immensely I see no disadvantages in chaining declarations. A grouping of the declarations using comments or empty lines in between seems to me also a proper way to do that. What do you think? |
Do you handle the use of
|
I only use chaining with TYPES. For all others (DATA, CONSTANTS, METHODS) I never use a the colon. Examples:
Deleting or moving method ONE leads to
Otherwise declarations can easily be deleted using CTRL+D or moving lines using ALT+ <cursor up/down> |
In short, we should not chain up-front variable declarations.
But, how about
METHODS
,CLASS-METHODS
,TYPES
, andCONSTANTS
?For instance:
METHODS: get_name, get_age, set_name, set_age.
The text was updated successfully, but these errors were encountered: