Rust with indents (Python, CoffeeScript, Haskell, F# style)


It’s a sensitive topic, where all have their own prefs and I don’t mean to start a holy war, just wonder how many of us here would like to have an option to write with indents instead of curly braces.

We’ve seen many languages with meaningful indents get fantastic adoption: Python, CoffeeScript, Haskell, F#. The primary reasons behind that are the beauty of syntax and conciseness. Indents force the programmer to write readable code that almost always explain itself and doesn’t require comments.

Now we all know that it’s not gonna happen in the v.1.0 and curly braces will always be the standard in Rust. What we can hope is that Mozilla adds an option to the compiler to compile rust files with a special extension (*.rt for example) where all curly braces are optional and indents are meaningful.

If the option to switch between curly braces and meaningful indents is implemented, Rust will become the first language which have done so. Along with ownership/borrowing concept it will become the greatest selling point of Rust.

I’d like to hear your opinion about this idea. Would you be excited to have this option implemented in Rust or wouldn’t you?

Thank you! Elijah


No, F# has that. It can accept the default OCaml-like syntax and the new indentation based syntax.


+1000. I considered writing a pre-build script that would insert braces for indented blocks, but it was pointed out to me that I’d get fewer contributions and fewer eyes on my code if it wasn’t vanilla Rust. So seeing built-in support for this would be amazing! I also don’t mind some extra syntactic restrictions if it’ll make this easier.




I dislike meaningful indents.


If there will be optional meaningful indent, we’ll end up with two incompatible Rust dialects (unable to compile both code snippets with same compiler settings). And braces aren’t really that bad - and so are meaningful indents. Just, not both!


I would love to see that. But i suppose that would never happen. One of my biggest gripes with low level languages like Rust and C is those darn curly braces. I always thought that this would be because most languages seem to originate in America and nobody cares if it’s just a pain to type {} on a german keyboard. Honestly, i think most languages nowadays wouldn’t have curly braces if the QWERTY keyboard would have them on alt-gr + 7 / 0. Meaningful indentation is, in my opinion, one of the biggest/easiest advances in programming language syntax, yet so many people are opposed to it :frowning:

Anyway, as much as i would love it and think that this would be a genius move, i think it will not happen just because of syntax highlighters, linters and other such tools would be harder to create.


I’m new to rust but don’t think meaningful indentation would add anything to the language. As a system language, explicitness is a feature not a bug and meaningful indentation lends itself more to an implicit nature. With one wrong tab, I could create a syntactically correct statement that might compile and run, even though I may have just scope locked a pointer I was attempting to manipulate. Best case, I get a compile-time error; worst case, my app still runs. With brackets, it’s less likely this would happen as the explicit nature of a bracket block requires two actions to confirm my intention.


I would much prefer a Haskell-style preprocessor with type signatures above definitions, and pattern matching integrated into function defintions… etc…


Every editor I ever used allows to automatically insert closing brackets, so that’s one Acton, too.

Besides, I literally never accidentally pressed tab too much while coding Python.


+1000 from me too. I really líke this peculiarity of python and haskell. It makes the code much easier to the eyes.


How does whitespace Rust interact with anonymous scopes? It’s not uncommon in Rust to create a new scope unconditionally to create some temporaries that will be cleaned up when it ends. How does that work? You can’t just randomly indent, because that would be ambiguous with any scopes that should end before it.


Couldn’t you just create an unindentend label?


Can you explain this more?

if true {
  // do stuff
  let vec = vec![1,2,3];
  // do some work with vec, and then free it at the end of this scope
if true 
  // do stuff

  let vec = vec![1,2,3];
  // do some work with vec, and then free it at the end of this scope


This is getting a thumbs down from me. I don’t care how pretty you think it looks, losing the explicitness of braces around scopes just isn’t going to work. We already require semicolons and give them more meaning than traditional C style languages, and we require braces around every scope, even ones with just a single statement. So to suddenly introduce a world where you can completely disregard braces entirely and make whitespace meaningful would be a complete change to the language. Having two different syntaxes for the language is a maintenance nightmare, and letting you mix and match would be even more confusing, because suddenly existing whitespace would have meaning. And what of code that mixes spaces and tabs? Are we going to ban one or the other? Sure there are languages that work well without braces for scopes, but they’ve been designed that way. Rust was designed to use braces, and changing it now would be an absolute nightmare.

if true
    // do stuff

    scope // keyword that opens a new scope
        let vec = vec![1,2,3];

? Not that I want a whitespace variant of the language at all, just that this particular objection seems pretty easy to overcome.


I wouldn’t mind a whitespace dependent Rust, but I would mind if there were two ways to write Rust.


+1 for optional indents!


+1000! Haskell forever!