Comments (9)
While the statement's name CHECK
does describe that it evaluates a condition, it unfortunately does not hint at what happens if the condition fails.
Previous discussions suggested that the ABAP community would prefer a name like:
RETURN IF <condition>.
from styleguides.
CHECK
is a beautifully self-describing statement - it does exactly that - checks some condition.
From my perspective, it's ok to use it to execute some initial consistency checks, like empty parameters, validation, etc.
But it's not ok to interrupt the method in other cases.
from styleguides.
I like CHECK as the first statement in BAdI implementations. For example to check if the implementation should be called in the current client.
from styleguides.
To make my point clear: I promote the use of CHECK in a functional method. In this use case, it should not be the first Statement of the method.
from styleguides.
IMHO depends on context
A check in the middle of a very long method is frowned upon because it interrupts the flow and is hard to spot.
I agree, but that's mostly a consequence of the method being too long.
In a short one is not a big deal IMHO
At any rate, I will always favour
check a is not initial.
over
if a is initial.
exit. " or return when equivalent
endif.
The argument about the statement name is not an issue for ABAP developers. Has some merit when a colleague looks at our code
from styleguides.
While CHECK is useful in some cases, as people said before, I usually suggest to avoid using it inside LOOPs where the CHECK is used but could be replaced with a LOOP WHERE.
from styleguides.
I see this In the context of methods, outside LOOPs as in "Replace Nested Conditional with Guard Clauses" (cf. Refactoring (c) 1999 by Martin Fowler:
conditional expressions have different intentions: The first form is a check whether either course is part of the normal behavior. The second (called a guard clause) is for a situation in which one answer .. is normal behavior, the other an unusual condition.
from styleguides.
Check is something which should never be used in my eyes. Doesn't make sense to me. When I have methods and other stuff done very small (3 to 5 lines only) where is the argument to use a check... a if-condition works always fine.. as stated by @HrFlorianHoffmann a few comments above.
from styleguides.
CHECK outside of LOOP is mostly used as the first statement in a method. This is an established pattern to enforce the method contract. The extended syntax check will not complain in this case.
Now another usage of CHECK outside LOOPs, verbatim from ABAP Scheme:
CLASS lcl_lisp_number DEFINITION INHERITING FROM lcl_lisp ABSTRACT.
PUBLIC SECTION.
METHODS is_exact RETURNING VALUE(result) TYPE REF TO lcl_lisp.
METHODS is_inexact RETURNING VALUE(result) TYPE REF TO lcl_lisp.
DATA exact TYPE flag READ-ONLY.
ENDCLASS.
CLASS lcl_lisp_number IMPLEMENTATION.
METHOD is_exact.
result = false.
CHECK exact EQ abap_true.
result = true.
ENDMETHOD.
METHOD is_inexact.
result = true.
CHECK exact EQ abap_true.
result = false.
ENDMETHOD.
ENDCLASS.
from styleguides.
Related Issues (20)
- Strategy for handling dependencies to system releases HOT 4
- Text on logo not readable in dark mode (Code Review Guide) HOT 3
- [Exploit the test tools] Add CL_AUNIT_AUTHORITY_CHECK to the list? HOT 6
- [Consider decomposing complex conditions] bad use case example HOT 1
- German Translation: Typo HOT 1
- Use assert class instead of ASSERT HOT 12
- Are comments bad or not?
- [Use CHANGING sparingly, where suited] Is it ok to use IMPORTING REF instead of CHANGING? HOT 7
- New rule: prefer inferring types HOT 1
- Abap Exception categories HOT 3
- Use READ-ONLY sparingly - new abap command FINAL HOT 2
- How to add sample code to Clean ABAP? HOT 1
- Unclear explanation of [Use LOCAL FRIENDS to access the dependency-inverting constructor] HOT 5
- Follow rules when abbreviating HOT 1
- "Dead" link at section "split-method-instead-of-boolean-input-parameter" HOT 3
- Chapter "Avoid abbreviations" HOT 7
- [Prefer RAISE EXCEPTION NEW to RAISE EXCEPTION TYPE] In defense of RAISE EXCEPTION TYPE HOT 6
- Prefer ENUM to constants interfaces HOT 1
- [Use | to assemble text] Is a caveat needed in case of translatable texts? HOT 7
- "New rule" Tables > Prefer a Table Expression to READ TABLE
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from styleguides.