2 ms·
I think Java's solution is much cleaner.
by gf000 1y ago
I think Java's solution is much cleaner.
- IshKebab 1y agoFor those of us that haven't used Java for a decade... > In text blocks, the leftmost non-whitespace character on any of the lines or the leftmost closing delimiter defines where meaningful white space begins. From https://blogs.oracle.com/javamagazine/post/text-blocks-come-to-java https://blogs.oracle.com/javamagazine/post/text-blocks-come-... It's not a bad option but it does mean you can't have text where every line is indented. This isn't uncommon - e.g. think about code generation of a function body.
- Twey 1y agoRight, this is a pretty common syntax, but doesn't address the same problem as Zig's syntax. I've only seen two that do: the Zig approach, and a postprocessing ‘dedent’ step.
- gf000 1y agoWhy couldn't you have it? You just put the ending """ where you want it relative to the content.
- IshKebab 1y agoAh I see - didn't notice it includes the trailing """. Tbh I still prefer Zig's solution. It's more obvious. (Though they should have picked a less intrusive prefix, I'd have gone with a backtick.)