While this isn't a very dire or pressing matter, I think it would be interesting to discuss.<p>It's often considered good practice to use trailing commas in multi-line arrays (where language syntax rules permit); e.g.<p><pre><code> [
'a',
'b',
'c',
]
</code></pre>
going further, would it also make sense to start an else-if check train with ``if false; ' ' ? e.g.<p><pre><code> if false;
else if check 1; etc
else if check 2; etc
else if check 3; etc
</code></pre>
for a real-ish world example:<p><pre><code> https://gist.github.com/Syrup-tan/c78f781c9b500b802fec#file-w-sh-L33-L56
https://gist.github.com/Syrup-tan/c78f781c9b500b802fec#file-w2-sh-L33-L56
</code></pre>
the second way grants a refactor-er the ability to re-order the elif checks without modifying any of the statements, reducing the chance of basic errors. It also makes diffs simpler to read.<p>However, in exchange, it sort of violates ``Principle of Least Surprise ' ', as someone reading the code may not understand what the ``if false; then :; ' ' is doing there. ( ``: ' ' is the null-operation in sh)<p>I'd love to hear more thoughts on this practice.<p>edits: readability & highlighted section in gist ( no wording changes )
> It also makes diffs simpler to read.<p>I find that there's a pretty direct conflict between trying to keep diffs 'pretty' and the quality of the ever-growing code.<p>In my experience, code quality is only achieved and sustained by continual refactoring. When this continual refactoring attempts to satisfy easy-to-read diffs the objective stops being to simplify the code itself and rather to simplify the delta -- which limits/checks the simplicity the code can achieve.
Write a better diff! Make the computer do more work, rather than bending over backwards to fit the whims of your diff.<p>Try searching for "semantic diff" or "tree-diff" or "syntax-aware diff".<p><a href="http://martinfowler.com/bliki/SemanticDiff.html" rel="nofollow">http://martinfowler.com/bliki/SemanticDiff.html</a>
<a href="https://www.semanticmerge.com" rel="nofollow">https://www.semanticmerge.com</a>
Not code, but docs, here is what I do:<p>Start each sentence on a new line (I have a perl script that formats text like this).<p>The reason is that when you version control the docs it's easier to pick out the diffs if the sentences are boundaries.<p>It's simple, easy, makes looking at diffs faster.
I have come to prefer putting commas in lists at the beginning of things<p>SELECT<p>field1<p>,field2<p>,field3<p>,field4<p>FROM table<p>More easy to realize you are missing separators and it just looks nicer to me.