Skip to content
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

From Relational Operator to Predicate Function #352

Open
lucasborin opened this issue Apr 5, 2021 · 3 comments
Open

From Relational Operator to Predicate Function #352

lucasborin opened this issue Apr 5, 2021 · 3 comments
Assignees
Labels
style guide Clean ABAP related

Comments

@lucasborin
Copy link
Member

How about a new check to convert a relational operator to a predicate function?

‏Relational Operator Predicate Function
o1 CO o2 NOT contains_any_not_of( val = o1 sub = o2 )
o1 CN o2 contains_any_not_of( val = o1 sub = o2 )
o1 CA o2 contains_any_of( val = o1 sub = o2 )
o1 NA o2 NOT contains_any_of( val = o1 sub = o2 )
o1 CS o2 contains( val = to_upper( o1 ) sub = to_upper( o2 ) )
o1 NS o2 NOT contains( val = to_upper( o1 ) sub = to_upper( o2 ) )

Source: https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abencontains_functions.htm

Most of the non-ABAP developers do not understand the ABAP-specific relational operators.

@lucasborin lucasborin added the new check New check label Apr 5, 2021
@lucasborin lucasborin self-assigned this May 14, 2021
@lucasborin
Copy link
Member Author

The operators CP and NP can be replaced by the predicate function contains and a suitable regular expression. The differences in case handling must also be respected here. Generally, a simple mapping like in CS and NS is not possible, but is also not usually required.

@pokrakam
Copy link
Contributor

pokrakam commented May 15, 2021

Just my opinion, but I find the relational operators far shorter and readable, as is obvious from the list above. Yes, they're not common in other languages but are not hard to learn. Consider a real-world usage:

IF contains_any_of( val = sy-msgty sub = 'AEX' ). 
vs.
IF sy-msgty CA 'AEX'. 

String predicate functions are one of the few new ABAP features I have not fully embraced, I just find them awkward and only use them if a functional position is really required.
If we want to compare to other languages, we can add JS to the example above:

IF sy-msgty CA 'AEX'.

if(msgty.match(/(A|E|X)/))

IF contains_any_of( val = sy-msgty sub = 'AEX' ).

I am not aware this is in the style guides either. As I said this is just my opinion though, perhaps some may find it useful but I would likely disable this check. I just can't see any benefit to limiting the use of relational operators.

@lucasborin
Copy link
Member Author

lucasborin commented Aug 13, 2021

Let's start a thread in the Clean ABAP.

@lucasborin lucasborin added the style guide Clean ABAP related label Aug 13, 2021
@bjoern-jueliger-sap bjoern-jueliger-sap removed the new check New check label Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
style guide Clean ABAP related
Projects
None yet
Development

No branches or pull requests

3 participants