I opened a discussion on Github titled allow user to define tab sizes: 2, 3, 4, … spaces on what they can do to help make sure we don’t have endless fights about spaces. Please add an emoji to that discussion and feel free to comment. Perhaps we can get their attention to solve this perennial problem.
I like that this has happened. It increases pressure considerably on finally moving more firmly towards AST editors driving the editing (like IntelliJ’s Scala plugin) as opposed to simple text editing.
Every single new bikeshedding discussion about a syntax evaluation and/or change just elevates this pressure towards AST editing further. I find it fascinating there is so much psychological energy burned about the emotionally intense rationalization (philosophically reasoned and justified nature) of a particular concrete text character representation versus another. The only way back to objectivity is to get to the compiler’s essential requirements which live in the eventual ASTs with which it must operate unambiguously.
Shades of paulp’s closing argument, years ago…
But yeah, the idea of working in an AST-centric environment seems like its time has come, and I look forward to more experiments in that direction. I’m curious about your IntelliJ reference, through. I think of that as just a typical IDE – is there something more AST-centric that I haven’t noticed, or do you mean the underpinnings?
You want an AST-centric IDE? How would that look like, like Scratch?
I honestly don’t know – hence “experiments”. But the idea has been floating around out there for many years (if I’m remembering correctly, it was a major topic of paulp’s last talk on the subject of Scala before he left the community), and now that we have an AST at the center of the ecosystem, it seems appropriate to explore what avenues that opens to us.
awwright pointed out in the Github discussion I posted that one can in fact set tab widths on github. Following his pointer I set that project’s .editorconfig with guidance from this StackOverflow Question, and indeed it works! The Scala3 file now shows tabs with 3 spaces! All that is needed is for Github to make that a user-settable preference, not just a project one.
Was I blind or have they just added this? On the edit tabs of a resource there is a menu to allow one to select tab sizes it seems. If you look at this Scala file that uses tabs you can change the tab spacing
An indentation size of π would set the lines very clearly apart, even if the beginning of the line is not visible. It would be possible to take the position of any character and deduce the indentation level, as long as the font is fixed-width. Why be like Python if you can be better.
pi*6 is only 0.009 away from an integer, whereas
e doesn’t have a close collision until 7, and it’s 0.028 away!
So π is clearly inferior and e is the only
rational choice transcendental choice for indentation width.
I’ve accepted 2-space indentation by now, but 3-space indentation is actually a good compromise between structural readability and line wrapping.
The problem with it is that, in the computer world, 3 cannot compete with 2 and 4. Think about it. While 3 is “odd”, 2 and 4 are not just even but are powers of 2 – and powers of 2 are special in the binary world of computing. Not that it should matter for indentation, but there is a strong psychological bias against 3 – as evidenced by the little cartoon above.
The good thing about tabs is that you can switch between 2,3,4 spaces without changing the code. So I am trying 3 spaces, but from time to time I try out 2. People with wider screens may be happy to go for 4. And perhaps someone will come up with a clever alignment algorithm that does something else
The problem with tabs is that they have to be used with absolute consistency or else someone with different tab stop settings will see misaligned code. I’ve seen many instances where a mixture of tabs and spaces was used and that makes nobody happy.
About 3 spaces… it’s fine. Sure it’s not 2 or 4, but so what? I do a lot of programming in Ada and 3 spaces is pretty well standard for indentation in the Ada community. It’s all good.
Interesting to hear that 3-space indentation is standard in Ada.
As for mixing tabs and spaces, Scala 3 has that covered. You can mix them all you want, and there will never be a misalignment no matter how you set your tab width. That is because you are required to use the same tab/space pattern for each block. Of course it makes no sense to mix tabs and spaces, but at least it can’t cause misalignment problems.