Skip to content

Automated Conversion from Old String Concatenations to String Templates #116

Open

Description

@BenjaminWeisheit

Hello Jörg-Michael,

The way we currently concatenate strings is quite inconsistent and therefore not always easily readable. Sometimes we use the old concatenations, and other times we use string templates. How about implementing a rule to automatically convert old string concatenations to string templates?

For instance, this code:

DATA(message) = Return code && code && with message && text.

Could be converted to:

DATA(message) = |Return code { code } with message { text }|.

Or even:

CONCATENATE material plant sales_order INTO item SEPARATED BY '-'.

to:

item = |{ material }-{ plant }-{ sales_order }|.

What do you think?

Best regards,
Ben

Activity

  1. jmgrassau commented on Sep 30, 2023

    @jmgrassau
    Member

    Hi Benjamin,

    yes, that would indeed be a nice cleanup rule! The idea was already raised in #36 (point 10), but I think this is worth a dedicated issue!

    Kind regards,
    Jörg-Michael

  2. self-assigned this
    on Mar 25, 2024
  3. jmgrassau commented on Mar 25, 2024

    @jmgrassau
    Member

    Hi Benjamin,

    this idea …

    DATA(message) = `Return code ` && code && ` with message ` && text.

    Could be converted to:

    DATA(message) = |Return code { code } with message { text }|.

    … should be implemented now with the new cleanup rule "Use string templates to assemble text", which was just released as part of version 1.15.0!

    However, we could still keep this issue open to check about CONCATENATE ... INTO ... SEPARATED BY!

    Kind regards,
    Jörg-Michael

  4. ConjuringCoffee commented on Mar 25, 2024

    @ConjuringCoffee
    Contributor

    Great to see, thank you. What does the option "Always convert text literals in concatenations" do exactly? This option isn't represented by the example.

  5. jmgrassau commented on Mar 25, 2024

    @jmgrassau
    Member

    Hi ConjuringCoffee,

    you're right, this option only has an effect if combined with:

    image

    It then means: If the concatenation contains a text literal, always put |...| around it, even if nothing is embedded into the string template (because that wouldn't be shorter):

    image

    Kind regards,
    Jörg-Michael

  6. ConjuringCoffee commented on Mar 25, 2024

    @ConjuringCoffee
    Contributor

    OK, thanks for the explanation! This seems inconsistent to the handling of multi-line string concatenation though. Take a look at the example below. I wouldn't have expected any changes here.
    image

  7. jmgrassau commented on Mar 25, 2024

    @jmgrassau
    Member

    Hi ConjuringCoffee,

    if you use "Embed … if result is shorter" (but NOT equal), then nothing is changed:

    image

    So, "Always convert text literals …" really has this notion of "even convert in cases in which the result is not shorter, but equally long" (while unchecking the option does not necessarily prevent text literals from being converted).

    Kind regards,
    Jörg-Michael

  8. jelliottp commented on Jan 8, 2025

    @jelliottp

    Any updates on expanding this one to include CONCATENATE statements? I would find this really valuable as I still run into it on old code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions