Hacker News new | ask | show | jobs
by Twey 316 days ago
And what if you do want to include two spaces at the beginning of the block (but not any of the rest of the indentation)?

Choice of specific line-start marker aside, I think this is the best solution to the indented-string problem I've seen so far.

1 comments

I think Java's solution is much cleaner.
For 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-...

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.

Why couldn't you have it?

You just put the ending """ where you want it relative to the content.

Ah 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.)
Right, 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.