News for hackers. Stuff that matters.
Re:The complete guide to working with strings in modern Java... by eyelidlessness on Wednesday April 14, 2021 @08:23PM (#26814814)
I’m surprised to see no mention of tagged literals, a much more complex version of template literals. For users they may seem ~like a function call without parentheses. But they do quite a bit more.

Short version: they accept an array of raw substrings and a variadic set of arguments corresponding to the runtime values provided in template positions, each positional value corresponding following the raw string preceding it.

That raw array is more than what it seems, it also has a getter of raw string values for the template expressions. This is what String.raw (also not mentioned) uses to treat those arguments essentially the same way an untagged template literal would.

It’s an odd design/interface but it can be used to do some pretty cool stuff. For example, Zapatos[1], a type-safe SQL library for TypeScript.

My only complaints:

- I can’t think of a real reason for it to be variadic, and this makes authoring them a little more error prone. You should be able to expect one array of strings with a length N, and one array of (type checkable/inferrable) values with a length N-1.

2. Likewise I can’t think of a real reason for the raw values to be bolted onto a weird array subclass. It could just as easily have been an iterable third argument.

1: https://github.com/jawj/zapatos

Re:The complete guide to working with strings in modern Java... by davethedevguy on Thursday April 15, 2021 @04:34AM (#26817690)
Thank you, I didn't know about this!

I've added a section on it:

https://www.baseclass.io/guides/string-handling-modern-js#ta...