You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Proposed Rule
Prefer inferring types where possible, instead of specifying the same type twice.
Example:
CLASSlcl DEFINITION.
PUBLIC SECTION.
CLASS-METHODS foo IMPORTING val TYPE string.
ENDCLASS.
CLASSlcl IMPLEMENTATION.
METHODfoo.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
lcl=>foo( CONV string( 2 ) ).
In this example lcl=>foo( CONV string( 2 ) ). can be replaced with lcl=>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?)
The text was updated successfully, but these errors were encountered:
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?)The text was updated successfully, but these errors were encountered: