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

New rule: prefer inferring types #333

Open
larshp opened this issue Jul 11, 2023 · 1 comment
Open

New rule: prefer inferring types #333

larshp opened this issue Jul 11, 2023 · 1 comment
Labels
clean-abap New Rule The issue or PR proposes an new rule or set of rules

Comments

@larshp
Copy link
Contributor

larshp commented Jul 11, 2023

Proposed Rule
Prefer inferring types where possible, instead of specifying the same type twice.

Example:

CLASS lcl DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS foo IMPORTING val TYPE string.
ENDCLASS.

CLASS lcl IMPLEMENTATION.
  METHOD foo.
  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?)

@larshp larshp added clean-abap New Rule The issue or PR proposes an new rule or set of rules labels Jul 11, 2023
@N2oB6n-SAP
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clean-abap New Rule The issue or PR proposes an new rule or set of rules
Projects
None yet
Development

No branches or pull requests

2 participants