dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.05k stars 4.03k forks source link

Elimination of the use of semicolon at the end of every statement in C# 7 #9793

Closed josejmoran closed 8 years ago

josejmoran commented 8 years ago

Version Used: C# 6

Steps to Reproduce: We all have to put the ; at the end of every statement. The compiler complain if we don't. Could it be possible to eliminate the need of adding the semicolon?

It is a dramatic request, but I think at this point we can get rid of it. The compiler knows when we missed it, it give us an error. Since it knows, could the IDE analyzer add it automatically or better just not expect us to type it anymore. F# do not have it, Swift do not have it. C# can get rid of it :)

Expected Behavior: Love to see this: Console.Write("No more semicolons, yeah!!") Actual Behavior: Console.Write("Hating the semicolon at the end, yeah!!");

stonecodemonkey commented 5 years ago

Late to the game here, but I don't think it has anything to do with preferences, optional terminations, mandated or anything else. Language designers have to make a decision on whether white space is important to the language or not . If the choice is that it is not then EOL also has to be NOT important.

When white space becomes irrelevant then it opens up new possibilities in the IDE. However you still need a reliable standard way to parse the input stream. For C# and other languages, the tokens '{', '}', and ';' are significant to the parser.

I've been studying / writing an interpreter for fun and it surprised me how little the syntax of a language has do with the programmers need to manipulate data. I think (sometimes) that the majority of decisions made by language designers are based on how the parser is going to work.

Tokenization is fairly trivial, even an AST is trivial once you understand postfix and which part of the language actually works with a syntax tree. Everything else is in place solely for the parser. Syntax and semantic analysis are what make a good IDE. I've came to the conclusion in writing a parser and interpreter that most constructs in a language have little to do with the end user, but are there for compiler designers.

My 2 cents.

JeroMiya commented 5 years ago

You don't necessarily need to have whitespace/endline/indentation significant syntax to not need semicolons but you need a grammar that is unambiguous w.r.t the end of a statement or expression in all cases. I suspect this would need to be built into the language from the beginning.