Closed larshp closed 1 year ago
There's no rule in Clean ABAP regarding the use of cx_assert
, right? I think you should open a thread in the abap-cleaner repository instead.
oh, so there is no relation between abap-cleaner rules and clean abap? its difficult to figure out when its all under the same "SAP banner"
The alignment so far, was more about ensuring that the essential profile of ABAP cleaner is not in conflict with Clean ABAP
@jmgrassau: Hi Jörg-Michael, do you want to add more information with regards to the issue?
ABAP cleaner is a configurable tool with the “ambition to automate whatever can be automated” with respect to Clean ABAP code style.
ie. its automating things that are not in respect to Clean ABAP, or in the reference to "Clean ABAP" is not referencing the documentation in this repository?
It allows to automate more than is defined in Clean ABAP. Similar to ESLint, which allows to check and fix many more things, than is defined in basic check configurations.
okay, however its not what it says in the text, it says "with respect to Clean ABAP", and we have established that this rule is directly not in respect to Clean ABAP
which is okay, its just difficult to navigate
Hi Lars,
thanks for raising this! Let me try to answer your first question first:
What is the motivation for using cx_assert over ASSERT?
The motivation is to make code testable, so if you'd ask what this ABAP cleaner rule "Use assert class instead of ASSERT" relates to in the Clean ABAP style guide, it would be the chapter Write testable code. (Admittedly, that's a rather concise chapter on a huuge topic which you could write a whole book about.)
The point is that you cannot write a test which ensures that an ASSERT in the product code really works on error cases – such a test would simply cause a Runtime Error whenever you execute it. By contrast, if you use an (application-specific) assert class CX_…_ASSERT (inheriting from CX_NO_CHECK), you can write tests to ensure that error cases really trigger this. In my team, there has indeed been a refactoring effort about this at some point.
And for the more general question:
so there is no relation between abap-cleaner rules and clean abap?
If you click "Edit Profiles and Rules…" on the interactive ABAP cleaner UI and select a rule from the list, you can see in the "References" section what this particular cleanup rule is based on. In many cases, you will find (clickable) references to the Clean ABAP Styleguide, the Clean Code Checks (i.e. Code pal) or the ABAP Keyword Documentation, for example:
You will also find rules for which currently the only reference is "ABAP cleaner" itself, as in this case:
Actually I think referencing the chapter Write testable code would make a lot of sense here, but of course this reference would not be as specific and compelling as in the case of the "Replace CALL METHOD" rule.
we have established that this rule is directly not in respect to Clean ABAP
Maybe we could agree that "Clean ABAP" is the ideal that we are all striving for – as ABAP developers, as contributors to the Clean ABAP style guide, as authors of blogs etc. concerned with the topic, as developers of various tools that try to help and so on. So, "Clean ABAP" would be bigger than any one of these initiatives, and in this sense, I do think this cleanup rule contributes to Clean ABAP (but happy to hear counter-arguments). And in an ideal world, good ideas from one of the initiatives (no matter which) would sooner or later be discussed and reflected in other initiatives.
Note, however, that there are nuances in the objectives of those projects: The README of the ABAP cleaner project intentionally starts with the heading What the ABAP cleaner tool offers – so ABAP cleaner is meant (at least by me) as a friendly offering to automate things that developers or development teams will hopefully find helpful and convincing; and that's very much inspired by, but not limited to the Clean ABAP style guide. Whatever doesn't convince them (yet ;-), they can deactivate with a few clicks, and ABAP cleaner won't be insulted about it (not me, anyway). By contrast, the self-concept of the style guide, as I understand it, is (by nature) to be much more binding than that.
In ABAP cleaner, our attempt to reconcile these different objectives is reflected in the two profiles ('default' and 'essential'), as described at the end of the section What the ABAP cleaner tool offers.
Hope this explains things a bit. I really appreciate that you and many others care so much about these topics!
Kind regards, Jörg-Michael
Maybe we could agree that "Clean ABAP" is the ideal that we are all striving for
Well, not really, Clean ABAP is a SAP internal community project.
Why do you see it as internal? It allows e.g. for much more external involvement than the Google Code Style does
Hi Lars,
wait, that's not what I meant. Please do not assume that whenever someone says "clean ABAP", what they mean is completely identical with, and limited to the "Clean ABAP style guide".
Let's assume for a moment that "clean ABAP" is NOT a concrete text, NOT a website with a concrete URL, but first and foremost a great idea, an ideal of ABAP code in a form that is perfectly readable, testable, maintainable etc.
Now people start pondering and discussing this great idea:
None of these efforts is ever complete and perfect, they will never be completely consistent, they will always leave room for improvement, discussion and criticism; but ideally, each progress in one of the efforts will inspire progress in the other efforts. That's what I meant when I said,
Maybe we could agree that "Clean ABAP" is the ideal that we are all striving for
So, if you want it philosophically, "clean ABAP" would be the Idea in the sense of Plato's theory of Ideas (or "theory of Forms"), while the style guide, code pal, ABAP cleaner, and many other efforts (whether under the "SAP banner" or not) would be the "physical" attempts to implement this Idea. And like all physical things, they are never perfect, never exhaustive, never finished.
That's why I think a concrete cleanup rule in ABAP cleaner can serve the Idea of "clean ABAP", even if there is no exact match for it in the Clean ABAP style guide, or the Code Pal for ABAP checks.
Kind regards, Jörg-Michael
well, okay, that opens more questions
"Clean ABAP" is the title of the concrete text, and the title of a concrete book. If SAP as such considers Clean ABAP to be the idea of writing nice code, then I'd suggest renaming the style guide to "Clean ABAP styleguide" and adding a chapter on how to use the terms.
I as such use "Clean ABAP" to refer to the concrete text, and try searching for "follow Clean ABAP" on google, to me it looks like multiple more use the term for the actual content and not the idea.
Hi Lars,
thanks for your reply! I do, of course, in no way claim to be speaking on behalf of "SAP as such". Nevertheless, very helpful discussion (at least for me as such) to understand potential sources of misunderstanding.
Apart from discussing how terms are used, I hope that the above reference to the style guide's chapter Write testable code, as well as the comments on the different objectives between a style guide and a code cleanup tool do make some sense to explain why there are cleanup rules such as "Use assert class instead of ASSERT" in ABAP cleaner.
And as always with the functionality offered(!) by ABAP cleaner: If you're not convinced, simply deactivate it, or use the 'essential' profile!
Kind regards, Jörg-Michael
Relevant sections of the style guide https://github.com/SAP/abap-cleaner/blob/main/docs/rules/AssertClassRule.md
Question What is the motivation for using
cx_assert
overASSERT
?also nothing mentioned in the documentation, https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-us/abenassertions_guidl.htm
and it does not exist and is not released?