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

Automated Conversion from Old String Concatenations to String Templates #116

Open
BenjaminWeisheit opened this issue Sep 27, 2023 · 6 comments
Assignees

Comments

@BenjaminWeisheit
Copy link

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

@jmgrassau
Copy link
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

@jmgrassau
Copy link
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

@ConjuringCoffee
Copy link
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.

@jmgrassau
Copy link
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

@ConjuringCoffee
Copy link
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

@jmgrassau
Copy link
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

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

No branches or pull requests

3 participants