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

Add support to concat strings and numbers in scripting #771

Closed

Conversation

bochen87
Copy link

Solves #766

@facontidavide
Copy link
Collaborator

The potential issue I see with this is that there are two contraddicting use case:

  1. Someone may want to concatenate string with numbers, so for instance
"path_" + 4 -> "path_4"
  1. Someone may want strings to be interpreted as numbers
"3" + 4 -> 7

What would be probably "wrong" is:

"3" + 4 -> "37"

So, the only sane way to do this, in my opinion is including functions to_number() and to_string():

"path" + to_string(4) -> "path_4"
to_number("3") + 4 -> 37

This is considerably more work, but the only way to avoid technical debt from being created, in my opinion.

@bochen87
Copy link
Author

bochen87 commented Feb 16, 2024

The potential issue I see with this is that there are two contraddicting use case:

  1. Someone may want to concatenate string with numbers, so for instance
"path_" + 4 -> "path_4"
  1. Someone may want strings to be interpreted as numbers
"3" + 4 -> 7

What would be probably "wrong" is:

"3" + 4 -> "37"

So, the only sane way to do this, in my opinion is including functions to_number() and to_string():

"path" + to_string(4) -> "path_4"
to_number("3") + 4 -> 37

This is considerably more work, but the only way to avoid technical debt from being created, in my opinion.

It would be nice, but I guess quite a large amount of work to make it work properly, as your outlined approach also has some potential pitfalls, i.e. "3,14" vs "3.14" vs "8'000". However, in the meantime, this could still be a good enough intermediate solution as it does at least allow for the usecase 1 to be solved.

@facontidavide
Copy link
Collaborator

However, in the meantime, this could still be a good enough intermediate solution as it does at least allow for the usecase 1 to be solved.

Sorry, not adding this feature yet. I can't afford to have side effects that haven't been considered carefully

@seanng-1
Copy link
Contributor

seanng-1 commented Mar 28, 2024

Would a better solution for this be: to add a new operator specifically for string concatenation? Similar to how it is done in Lua.
e.g.

value := 10
message := "The value is " .. value

would result in The value is 10

I can see this avoiding any issues with people wanting to use strings converted to numbers as it is explicitly for string concatenation.

EDIT:
I've made a new PR #802 that works for my needs but can add some changes if required.

@facontidavide
Copy link
Collaborator

closing in favor of #802

@bochen87 bochen87 deleted the bc/add_concat_str_num branch June 25, 2024 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants