5 ms·
> Using a formatter eliminates this problem because all white-spaces are normalized. That's only true most of the time, not all of the time. If you ever want
by nordsieck 4y ago
> Using a formatter eliminates this problem because all white-spaces are normalized.
That's only true most of the time, not all of the time.
If you ever want to output source code programmatically, then indentation becomes a big pain all over again.
- WJW 4y agoCan you expand on this? Prepending spaces (or tabs) to strings is one of the most basic operations there is, so that can't be where the difficulty is. Keeping track of what the current indentation level should be also seems like something that any tool which outputs source code already does.
- nordsieck 4y agoThere is a whole range of programs that fit in between "output a single block string of text" and "yer a compiler, Harry!". And maybe the right answer is to import a compiler's worth of tooling to output a bit of code. But to me that seems like needless overhead, since meaningful whitespace isn't really a positive to begin with.
- MadcapJake 4y ago> Keeping track of what the current indentation level should be also seems like something that any tool which outputs source code already does. The challenge you are refuting is about building said tools. Just because existing tools have pushed through this challenge doesn't mean it's not both tech debt for those existing tools and a challenge for any new tool in the space. I think the best argument imo is that whitespace has to be properly maintained per line which adds computational cost and statefulness.
- TylerE 4y agoHow hard is it really? Instead of write(“{“) it’s indent += 1 and write(“ “*indent) and the start of each line. Decrement where you’d have a }
- still_grokking 4y agoOnly if you "output code programmatically" by concatenating strings… That's why code gen should be done on the AST level. Just use the right tool for the job.
- deleted 4y ago[deleted]