-
Notifications
You must be signed in to change notification settings - Fork 463
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
Deprecate unsafe "j" string interpolation #6067
Conversation
j
$(a)$(b)
`` interpolation861e02b
to
ed39677
Compare
What makes it unsafe? |
It's untyped: this is compiles OK: let add = (x,y) => x+y
let v = add(3)
Js.log(j`$(v)`) Easy to overlook type errors. |
What type error? This doesn't crash, nor will it result in any undefined behaviour or some such. It's no more unsafe than This doesn't seem to be the real reason... |
The type error it does not give, that is. That's the issue. False sense of security, where it's easy to think you're passing a string when you are not. |
The consequence for doing so is extremely benign though. It'll still end up as a string, just not the string that was expected. But that could be said about a lot of features. The unsafety here is on the level of a logic error, and if we're going to start shielding users against that, I'm afraid there won't be much language left. That's not to say it shouldn't still be removed, I just think this is a bad reason for doing so. And I think it's unwise to dilute the meaning of "unsafe" by applying it in this way. |
What would this say about polymorphic compare, for example? This will happily stringify functions. Polymorphic compare will crash. I still wouldn't say polymorphic compare is "unsafe", in the stricter sense that it goes into undefined territory, but it's certainly less safe than this feature. |
That's the way I see it, too. We were actually bitten by this in production in our (at the time) Reason codebase where we were using this kind of string interpolation to construct some strings shown in the UI, and ended up with This caused me to actually remove all string interpolation from our code at the time and replace it with explicit string concatenations. I am glad that the new ReScript string interpolation actually enforces all values to be strings. Apart from that, it does not make sense to maintain two slightly different kinds of string interpolation in the language. Also, the |
Ok, yeah I buy that. It's error-prone and it's badly designed. To add one more, the way it parses identifiers can sometimes lead to some unexpected results as well. A better designed feature might have some kind of format specifier to specify the type and |
This is biting me hard in my efforts to upgrade to ReScript 11. Template strings in JS will coerce variables to string, so we didn't see any problem doing the same in ReScript. It'll probably take me less than an hour to fix, but that's an hour I didn't expect to have to spend on the upgrade. Arguably the conversion here is more risky than the problems it's avoiding. I have a lot of interpolated strings, and now I need to use regex to find the ones with |
Deprecate unsafe
j`$(a)$(b)`
interpolation