When playing Devil's Advocate, it may be prudent to cancel the question:
Is it always good to use a terminator with a comma?
Some moments:
- Replacing most half-columns with commas will immediately simplify the structure of most C and C ++ code and eliminate some common errors.
- It depends more on functional programming, rather than imperative.
- Javascript's automatic semicolon is one of its controversial syntax features.
Whether this practice will increase the “common mistakes” is unknown, because no one does it.
But, of course, if you do this, you will probably annoy your fellow programmers and become a pariah on SO.
Edit: See AndreyT's excellent answer for 2009 Using C-comma . And Joel 2008 also talks a bit about two parallel syntax categories in C # / C / C ++.
As a simple example, the structure while (foo) a, b, c; understandable, but while (foo) a; b; c; while (foo) a; b; c; misleading in the absence of indentation or curly braces or both.
Change # 2 . As AndreyT says:
[Language] C (like C ++) has historically been a combination of two completely different programming styles, which can be called "statement programming" and "expression programming".
But his claim that “in practice, the statement creates a lot more readable code” [emphasis added] is clearly false. Using his example, in your opinion, which of the following two lines is more readable?
a = rand(), ++a, b = rand(), c = a + b / 2, d = a < c - 5 ? a : b; a = rand(); ++a; b = rand(); c = a + b / 2; if (a < c - 5) d = a; else d = b;
Answer : they are both unreadable. This is empty space that gives readability - cheers for Python !. The first is shorter. But in the double-colon version, there are more pixels of black space or green space, if you have a Hazeltine terminal - what could be the real problem here?