Where to put the comma?

I spend most of my work programming Oracle SQL and PL/SQL. Ofcourse much time is consumed by maintaining existing code. Here it is essential the code is readable and many times I start with reformatting the code. Put it in a format that I like. This refactoring also helps me in understanding the code, it’s structure. So the reformatting is not wasted time. On the contrary!

But many times I note that my preferences differ from most(?) tools or programmers. For instance the immense important question¬†ūüėČ :¬†¬†Where to put the comma?

I find, in a continued statement the comma should always be at the beginning of a line and never at the end of the prior line.

Why? Simple! Just ask yourself the question: to what part of the code does the comma belong to? It is a character that indicates the next part is separated from the prior part. If there would be no next part, then there would also be no  comma!

Other advantages of the comma in the beginning:

  • If you would have to add a parameter value to a list, you only have to insert a new line, start with the comma¬†and code the value. Would you have your comma’s at the end of¬†lines, you would have to go to the end of the line, code the comma, insert a new line and only then code the value.
  • The “comma-at-the-end” style also has the disadvantage that when you compare two versions of a piece of code, you also get the¬† lines where only the comma was added; with the comma at the begin, you get only the inserted lines!
  • Often I generate code from some SQL statement. It’s much easier to add a comma at the begin of each new line, then figuring out if the last line has been reached …
select decode(rownum,1,' ',',') || column_name as stmt_part
from user_tab_columns
where table_name = upper(:table_name)
  • If I have to comment a line, I do not need to bother about whether I have to remove the “continuation comma” at the end of the prior line. And when I un-comment the line again… but that comma back.
  • You immediately see that the line is part of the statements on prior lines(s).
  • It eases the method of “vertical code reading”;¬† you need less time to read it because you don’t have to read the whole line, scroll horizontally or move your eyes to the end of the line (of these ever increasing monitors)

Code is not natural language. Or didn’t you notice the different punctuation: Statements ending with a semicolon and not a period? The indendation? Color coding? Camel case?Aligning statement parts? Brackets, braces and curly braces? Abbreviations? …

Let’s make it more easy and efficient to understand and maintain!

Comments are closed.

Herman Mol is powered by WordPress.  Staypressed theme by Themocracy