styleguides icon indicating copy to clipboard operation
styleguides copied to clipboard

Relational Operator vs Predicate Function

Open lucasborin opened this issue 4 years ago • 2 comments

https://github.com/SAP/code-pal-for-abap/issues/352

I haven't found anything on this matter in the style guide. In your perspective, which one is the "cleanest"?

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: ABAP - Keyword Documentation

lucasborin avatar Aug 13 '21 18:08 lucasborin

I definitely prefer the operator, but that's because I've been using them for many years and they're instantly recognisable to most experienced developers. Worst case, there's always F1.

On the other hand, something like contains_any_of is clearer to the casual reader, but any benefits in readability are immediately negated by the mental acrobatics required for the weirder ones like NOT contains_any_not_of.

If SAP would provide simple functions for all of them then I may make the switch, but for now I shall continue to use the operators for consistency. CO is shorter to read and it needs minimal mental processing power to figure out the intended logic behind Contains Only.

pokrakam avatar Aug 13 '21 19:08 pokrakam

Personally I prefer to use Predicate Functions. I think that it is more readable.

ruthiel avatar Aug 16 '21 09:08 ruthiel