[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] Re: string formatting notation



> That’s not the same as impossible.

What Julian suggested is not string interpolation. It is runtime code evaluation. Proper string interpolation would not require a separate method call, otherwise you could hack together the same thing in Java using reflection and call it string interpolation.

> Given SC is soft-typed interpreted language, let’s say I find that argument less compelling than you seem to (same goes with ‘invoking the interpreter for such a simple task’), but we can agree to disagree I suppose.

Really? Instead of evaluating your code normally, go try writing it all in a string and calling .interpret on it. What we're discussing is exactly the same dichotomy. No syntax highlighting available. Runtime checking of syntax. The only difference between that situation and this one is that you don't like the syntax here.

> If you’re totally opposed to a method approach I’d prefer InterpString”…”

I definitely wouldn't prefer that variant, unless you intend to also introduce string"...", hexnumber0F877, float0.38, etc. It looks way too much like a new function call notation that way, as you already pointed out, or (thinking about highlighting) looks like a new keyword except with different tokenization rules (interpString".." allowed, but interpString ".." with a space not).

I respect the desire to be straighforward and unobscure in notation. But the tempering principle to that is to make common cases simple. This is a common case. People print things with .format and ++ all the time in SC. Just because you don't use it yet, or wouldn't use it frequently, doesn't mean it deserves a long name. Go look at the Wikipedia article for string interpolation. Most of the variants use a different quote character (', ", `) to allow interpolation. Some (Scala, Python) use a single-letter prefix as we've been discussing. This should not be burdensome for the developer to write or read.

Python is also taught to a lot of non-programmers as a first programming language, and has a (well-earned) reputation as intuitive and easy to pick up. It's not that I'm saying SC should look exactly like Python, but rather that I think they've made many good language design choices and that there's no need to reinvent the wheel.

> At the moment I think a method approach, using the back end Julian mentioned would be most generally useful.

This has none of the syntax highlighting benefits and all of the efficiency and runtime error issues. We are talking about a speed difference in runtime on the order of 100, probably more. Precompiled bytecode vs a full invocation of the interpreter and then evaluation of JIT bytecode. It's an incredibly bad solution to force on people just because you are uncomfortable with new notation. What would be the benefit of Julian's suggestion over .format, overall?

One other thing I wanted to mention while it's on my mind is that this would also set a good precedent from a language syntax perspective if we also decided to add raw strings or unicode string literals. I'm not sure of the top of my head if the latter would arise since it's already possible to insert unicode characters directly into string literals, but raw strings would definitely make life easier for Windows users. IME it's a too-common problem that new users forget about backslashes in their path strings and then have to manually escape each one. With raw strings, you could just write r"C:\Users\me\doc.scd".

-Brian

On Sat, Dec 23, 2017 at 11:01 AM, <i@xxxxxxxxxxxxxx> wrote:

On 23 Dec 2017, at 17:01, <brianlheim@xxxxxxxxx> <brianlheim@xxxxxxxxx> wrote:

> Again sorry if I’ve misunderstood, but why is it impossible?

The difference is run-time vs compile-time checking. If you need more, read back up for the explanation I gave Julian, or try it out in another language for yourself.

That’s not the same as impossible. Given SC is soft-typed interpreted language, let’s say I find that argument less compelling than you seem to (same goes with ‘invoking the interpreter for such a simple task’), but we can agree to disagree I suppose.

> What you are talking about is not a literal. 0x11 is always the same thing.

So is the "Value = " in f"Value = ${value}". Obviously, the whole thing is not a literal. But, the literal value that is produced by that _expression_ is different from the literal value produced by plain "Value = ${value}", just like the value of the literal produced by 0x34 is different than the value of 8r34. Yes, parts of how it works are new, but stylistically it's not that different from these other prefix-based literals.

If you want a precedent, I’d say a closer one is the collections variants. e.q. [ ] vs IdentityDictionary[ ]. If you’re totally opposed to a method approach I’d prefer InterpString”…” or something like that, as at least that looks like existing collections variants.

Remember, the criticism was not that it's new in some way, just that it doesn't match "existing conventions and style.”

Well, put generally the very first point I made in this thread is something like don’t put an unnecessary burden of learning and complexity on users unless the benefit is very substantial. This is especially true when talking about syntax variants and/or duplicating functionality.

This would be good maxim to include in a guide…

Anyway, I’m not opposed to adding this in some form, I just think it should be as easy to learn and understand as possible. At the moment I think a method approach, using the back end Julian mentioned would be most generally useful.

S.