Significant Indentation: Mixing Tabs and Spaces


I really like the significant indentation syntax due to land in the next release, but given how it is impossible to tell what mixture of tabs and spaces there are in a chunk of whitespace, would it be possible to make the presence of tabs a compile error?

I experienced the ability to mix the 2 as confusing in haskell when I was just starting using it (then I dropped tabs altogether), and even if it would be better in Scala 3 (would it?), we can do much simpler than the below if the language is a bit more opinionated about this.

Indentation prefixes can consist of spaces and tabs. Indentation widths are the indentation prefixes themselves, ordered by the string prefix relation. So, so for instance “2 tabs, followed by 4 spaces” is strictly less than “2 tabs, followed by 5 spaces”, but “2 tabs, followed by 4 spaces” is incomparable to “6 tabs” or to “4 spaces, followed by 2 tabs”. It is an error if the indentation width of some line is incomparable with the indentation width of the region that’s current at that point. To avoid such errors, it is a good idea not to mix spaces and tabs in the same source file. (

I dislike how this inevitably opens up a tabs vs. spaces debate, so to try to short-circuit that: I’m with tabs in principle, this is what tabs are for, but spaces won, that’s what modern tools work well with (e.g. soft tabs in editors). Code with tabs looks like a mess in Gitlab for example, sometimes in IntelliJ too. Maybe it’s configurable, but that’s extra effort and friction, especially when talking about e.g. company Gitlab servers.


Significant indentation will not be a part of Scala 3. It’s just an experiment in the Dotty compiler


You will find it is not a problem in practice. If you mix tabs and spaces the compiler will give you an error with a very specific error message. Here’s an example, from one of our tests:

5 |    println(2)
  |    ^
  |    Incompatible combinations of tabs and spaces in indentation prefixes.
  |    Previous indent : 2 tabs
  |    Latest indent   : 4 spaces

If you get errors like that you will very quickly standardize on either all tabs or all spaces.

And: There’s no decision on significant indentation optional braces in Scala 3, but no ruling it out either. I am personally cautiously optimistic; we are making very good progress on a number of tricky details.

1 Like

I don’t know, people can be quite stubborn when it comes to bikeshedding :slight_smile: But OK, even if it is a relatively small issue, is it counterbalanced by anything we gain if we allow both styles in the same codebase?

That error message is indeed nice and informative, no head scratching there, but the fact that it is a thing still might be an issue. I currently work with a code base full of tab indented Java files. When I change something not realising I’m changing one such file, the mixture looks like a mess outside my editor. Not a big issue in that case and can be left to be governed or not governed by in-house coding standards as it is just a matter of style in that case.

However, once whitespace gains meaning, and wrong combinations can get you bumping into compile errors on edits for no good reason… why not just disallow the variety to be able to have more defined expectations regarding the invisible parts of the unfamiliar code we are looking at?

It would be a quality of life improvement in my opinion, if I imagine finding myself in a remotely similar situation but in a Scala 3 code base.

Thanks for the clarification, I was a bit confused after going through the discussion on Github and reading @kaishh’s comment, looking forward to seeing how this goes.


The debate on tabs vs. spaces been hashed out so many times that it has been parodied on general-audience TV (HBO’s Silicon Valley). I think we’ve all heard all the arguments and no one is likely to be convinced to change their mind. I think this is one of those cases where it’s important for the programming language to not be opinionated in one direction or the other, or else it will alienate a lot of developers.

I will add that I don’t think that the fact that you can’t visually tell the difference between tabs and spaces gives any more legitimacy to tabs or to spaces for being the blessed indentation: one could as easily be surprised to find that a file is indented with spaces as they could be to find it indented with tabs.

1 Like

That’s my point though. Your message reads as if my main argument would be about tabs vs.spaces. I was arguing for neither of the above to be possible to happen.

Anyway, if I interpret the error message posted by @odersky correctly, within a single file you will be forced to choose. (I didn’t find under 3 minutes an editor on my PC that would do hard tabs so I ended up not trying how this works ) If that’s the case then this indeed is not that much of a problem, and might even be a good compromise (e.g. I would prefer that to the ruling going against my preference on the secondary issue of what whitespace should be blessed).


I am dead set against significant indentation, but I’m all for optional braces.

If they could throw in optional parens too, that would be a huge break-through, really sweet.

I’d recommend supporting tabs under -Xsource:anachronistic. The tabs issue comes up at work too frequently because any given tool chain fails to support tabs consistently, let alone line endings aka separators. If Scala could work toward eliminating tabs from source text by the end of the century, that would be a great boon to the next generations of coders. I learned tabulation on the mechanical typewriters in the office where my grandmother worked, approximately a hundred years ago. I think it’s fair to re-evaluate our typing habits every century or so.

1 Like

Scastie inserts tabs and this causes errors.