- PrometheusMultiple statements on one line a.k.a semicolon2014-09-16T13:16:12
The semicolon at the end of each line is (almost) completely redundant when your code policy is to write only one statement per line.
// Example 1
int main (void)
// Example 2
EXECUTE sp_foo (SELECT 1) -- Does not work, because EXECUTE has a more restricted syntax than the "rest" of T-SQL
// Example 3
DECLARE @i INT = (SELECT 1) -- Works here (SQL Server 2012 or newer)
EXECUTE sp_foo @i -- Variables are allowed
// Example 4
int main (void)
do_b (234324, 324324, 234234, 234234, 234234, 234234, "Hello \ //Statement continues on next line, string literal will contain ' ' instead of '\n'
World", abc * 1000);
In example 1 you have to type a semicolon after every "do_* ()" call which is just annoying, especially when you forget to write it. (Coincidentally the parenthesis is also quite redundant here, but that's another story.)
Many programmers have asked themselves: "Why don't you just add the semicolon yourself, if you know that it should be at this place you stupid compiler?"
The answer ist of course that it is necessary, because the compiler hast to know where a statement ends.
[li]Make the syntax of the language unambigous, so that it's clear without an end symbol where a statement ends. T-SQL did this up to SQL Server 2000 (newer versions still don't require the semicolon, but there are some exceptions where it is mandatory know. For example before a CTE if the CTE is not the first statement in a batch).
This has the drawback that the expressiveness of the language will suffer. That is not a big problem for T-SQL (except the EXECUTE T-SQL syntax inconsistency, see examples 2 und 3!), but may be a problem for a more complex language.
[li]Just make the newline character '\n' the end of the statement.
This has one problem: Some statements span [b]multiple[/b] lines. You have to introduce a line continuation character (like '\\' at the end of a line in C, see example 4)[/li]