What is the advantage of semicolons in programming languages?

Asked

Viewed 1,419 times

15

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

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

However, there are still languages in which the semicolon is not necessary (nor 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 performatic that VB.NET on compilation?

1 answer

17


It doesn’t change in performance, it’s just syntactic, it’s even semantic.

The first obvious advantage is that it allows instructions (statements) can be written in more than one line, which can better organize and make the code more readable in some situations. This is a way to end the "sentence". At the same time it allows more than one statement on the same line.

Some languages preferred to establish that it could only have one line and the new line indicator marks the end of the "phrase".

Of course it is possible to have other solutions to this need, such as indicating a specific marker when you need to continue on another line.

Another less obvious advantage is redundancy. Incredible as it may seem code redundancy can make it more reliable that it is expressing the right idea and avoids making mistakes by some carelessness. In addition the compiler can identify errors more easily and perhaps give a message closer than it needs to fix. It is possible to give good messages without having an instruction terminator, but it complicates quite the compiler.

The same occurs with the human who will read. Having something visual that shows that the closed instruction helps the eyes give a "parse" in the text.

And we can’t help but consider the advantage that popular languages have used for a long time, and having something that people are already used to help with the acceptance of new languages.

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

But I think it’s cleaner without it. I think it pollutes and makes mistakes unnecessarily in many cases because one forgot to put the terminator. Being cleaner doesn’t mean it’s better, but it’s indisputable that less information is cleaner. Of course too much cleaning can bring other problems. When cleaning takes away the protection can be bad.

But if the language was created to use it, it should use it, even if it is optional. I’m talking about the Javascript that people now "solved" that no longer need the semicolon.

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

  • "There are religious quarrels because of this and other syntax topics of programming languages" Unfortunately it is true. Some people prefer nonending (explicit) line languages and fight over bullshit. Personally I have programmed in the last 30 years from basic on a Z80 to C# going through Java, Delphi, VB6, Borland C, Javascript with a little PHP, Haskell... I personally find languages with "end of line" have a more organized and clean syntax.

  • @jean our background is incredibly similar. Lacked Clipper for you :P I took advantage and edited to disagree a little bit with you, without taking your reason :P

  • Blz, I love debating without dogmatism. I think (with;) it gets cleaner in the sense of lack of dubiousness. Yes I played a little with Assembly, Clipper, Cobol, the list is big =). Now we have strings with @ in C#t and for me it was the only thing missing =D

  • In ADVPL (Totvs) indicates a line continuation ...

  • @Motta Actually since the Clipper. I can’t remember if the dBase accepted, I think not. That’s what I said in the 4th. paragraph in a generic way.

  • I just wanted to give a hint here you are changing an advpl and a plsql Function at the same time ; becomes an enemy ... :)

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.