Open larshp opened 1 year ago
While I generally agree that #
-inference should be used in most cases I am torn about your particular example:
When it comes to CONV
I would personally favor the explicit repetition of string
. ABAP's conversion from, to, and between char-like types is notorious for causing headache or even subtle bugs. I dislike the fact that in this instance there is program logic at work on the consumer side (CONV string( ... )
does serious work, has implications and special cases) which would change its behavior if the API (unexpectedly and contrary to the best practice of stable public interfaces) changed its types.
Besides this caveat, however, I vote in favor of such a rule. In all places where type inference would work (and is not tied to inferred conversion logic) noting down the type is noise that can be avoided. The reader must be able to understand that "what" of a given piece of code without precise type information.
Proposed Rule Prefer inferring types where possible, instead of specifying the same type twice.
Example:
In this example
lcl=>foo( CONV string( 2 ) ).
can be replaced withlcl=>foo( CONV #( 2 ) ).
, making it easier to change the type of "val". Note, if the type is changed, the compiler will give a syntax error(for most cases?)