-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
The proposal #17145 seems to be hinged on the idea that we're leaning entirely on zig fmt
and giving up manually formatting our code. After all, who in their right mind would manually align everything outside of niche cases like giant switch cases or array literals? I don't mind this (I personally use format-on-save), but this opens the floodgates to other zig fmt
changes that "no human ... is capable of handling ... correctly." Specifically, I'm referring to "tabs for indentation, spaces for alignment" AKA "smart tabs" which has previously been dismissed for being unfeasible for mere mortal developers to correctly type.
The indentation war is a stale meme; Zig has long decided on spaces for indentation. However, just as #17145 suggests shedding longstanding practicalities rooted in the status quo in favor of forward-thinking improvements, smart tabs are in the same boat. Smart tabs appear identical to space indentation to 99% of viewers and would have little to no impact on their workflow, but by using exclusively tabs for indentation and spaces for alignment, visually impaired (or otherwise differently opined) developers can configure their editor to use their preferred indentation width without misaligning any intentionally aligned text or needing to constantly reformat their code between zig fmt
and their more visually accessible style. This is a proven style that JetBrains IDEs have offered for many years.
Because no human and no contemporary code editor is capable of handling tabs correctly. Humans tend to mix tabs and spaces on accident, and editors don't have a way to "indent with tabs, align with spaces" without pressing the space bar many times, leading programmers to use tabs for alignment as well as indentation.
Tabs would be better than spaces for indentation because they take up fewer bytes. But in practice, what ends up happening is incorrectly mixed tabs and spaces. In order to simplify everything, tabs are not allowed. Spaces are necessary; we can't ban spaces. But tabs are not strictly needed, so the null hypothesis is to not have them.
Maybe someday, we'll switch to tabs for indentation, spaces for alignment and make it a compile error if they are incorrectly mixed. But if we did that today, writing Zig code would be too hard. For now your options are to configure your editor to insert spaces when you press the tab key, or configure your editor run zig fmt on save (recommended).
Currently, the stage1 parser rejects tabs and the stage2 parser accepts them. What will make it into the final language specification? It isn't decided yet and it doesn't really matter. Just run zig fmt on save.
Writings on the matter:
- https://dmitryfrank.com/articles/indent_with_tabs_align_with_spaces
- http://lb-stuff.com/tabs
- https://old.reddit.com/r/javascript/comments/c8drjo/nobody_talks_about_the_real_reason_to_use_tabs/
Of course, the real icing on the cake is pissing off both tab purists and space purists with an objectively richer (and more accessible!) alternative.