What is the advantage of a semicolon in programming languages?

11

I know that in programming languages like Java and C #, the semicolon indicates the end of the statement, as in the example below, in C #:

System.Console.WriteLine("Hello, World!");

However, there are still languages in which the semicolon is not necessary (and not possible), as in the case of Visual Basic, F #, Go, among many others.

  • What is the advantage of indicating the end of the instructions?
  • In the case of C # / VB, indicating the end of the instruction makes C # more performative that VB.NET in the build ?
asked by anonymous 27.02.2017 / 01:16

1 answer

14

Nothing changes in performance, this is just syntactic, not even semantic.

The first obvious advantage is that it allows instructions ( statements ) to be written in more than one line which can organize better and make the code more readable in some situations. This is a way to end the "sentence". Some languages preferred to establish that only one line could be present and the new line indicator marks the end of the "phrase". At the same time it allows more than one statement on the same line.

Of course you can have other solutions for this need, such as indicating a specific label when you need to continue on another line.

Another less obvious advantage is redundancy. Incredibly it looks like redundancy in code can make you more reliable that is expressing the right idea and avoid making mistakes by some carelessness. In addition, the compiler can identify errors more easily and perhaps give a message closer to what it needs to correct. It is possible to give good messages without having an instruction terminator, but rather complicates the compiler.

The same goes for the human who will read. Having something visual that shows the statement ended helps the eyes parse the text.

And we can not overlook the advantage that popular languages have used for a long time, and having something that people are already accustomed to is helping to embrace new languages.

Writing compilers for languages without explicit termination of statement is more difficult, so it is an advantage to the other side, that of compiler writings:)

But I find it cleaner without it. I think it pollutes and generates errors unnecessarily in many cases because the person forgot to put the terminator. Being cleaner does not mean it is better, but it is undisputed that less information is something cleaner. Of course too much cleaning can bring on other problems. When cleaning takes out the protection can be bad.

There are religious fights because of this and other programming language syntax topics.

    
27.02.2017 / 02:00