Python was the first programming language I learned and I really liked the way it used indentation and newlines to cut out some of the clutter that other languages have. It made it feel a lot less intimidating to me when I was first learning how to program. I also believe that it is important to maintain block indicators when using less full featured IDEs that do not make it easy to distinguish spaces from tabs as this can create very hard to find bugs. Because of this the individual nature of style preferences I do think having the language use braces and semicolons by default is the right way to go.
However I think that adding a way to opt into significant whitespace would be a nice feature for rust to have. I'm not quite sure how much work this would entail on the backend from the compiler but I do think it is feasible as something that could be done.
I think this could almost be done with a macro if not for the requirement that the input for a macro be encapsulated in braces or something similar which defeats the purpose. I suppose the entire contents of the file could be enclosed and input into a proc_macro but there are rules about what you are allowed to replace with what and I'm not sure how that works when the entire file is your input. Something that adds braces when indentation levels change starting when appropriate (following an if
, while
, fn
... ect) and ending when the indentation level matches the previous.
If this is not possible with a macro I think it could be implemented with a tag at the top of the file like #![feature(significant_whitespace)]
or with something like a single colon operator to indicate where to start.
this:
if (blue):
color = "Blue"
println!("I'm blue!")
would become this:
if (blue) {
color = "Blue";
println!("I'm blue!");
}
It might be worth seperating out the feature of inserting simicolons on line endings as it allows things like this:
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");
instead of:
io::stdin().read_line(&mut guess).expect("Failed to read line");
Whereas in my opionion the first version is easier to parse than the second. I might try to take a stab at implimenting this as a macro myself. What do other people think?