Philwelch wrote:Xanthir wrote:Philwelch wrote:Good luck with machine-generated code.
Um, what? I have no idea what that is supposed to mean as a response to my comment
It's easy to machine-generate brace-delimited blocks. Machine-generating whitespace-delimited blocks is more of a challenge: it turns your code generator (which is one project) into a code generator with a pretty-printer attached (which is two projects).
I thought that's what you meant, but that still has nothing to do with my statement. I said that whitespace is sufficient for human comprehension of the code; you countered with "but machines have a hard time generating that code". And?
For one, the other brace styles aren't *un*readable, just *less* readable to me. For two, you're actually looking at machine-generated code? The whole point of machine generation is that you don't look at it. If you're talking about machine-generated *scaffolding*, then you're working in the wrong language. Learn to use a functional language and stop making our eyes bleed.
As well, pretty-printers can be produced once and then reused everywhere, so there's no need to double the work in every project for that. So you have a code generator, which runs the generated code through an external pretty-print library once, at the end.
Xanthir wrote:Don't whine to me about wasting whitespace, we aren't using teletypes anymore. Whitespace is cheap.
Um, no. Whitespace is *expensive* in terms of comprehension. The more you can comprehensibly fit into your eye, the better. Stretching a function out over a whole page when it can be compressed into less than half that space without losing comprehensibility is a crime.
Yes, but that's a question-begging way of putting it. "Without losing comprehensibility" is exactly the question here. And the better question is, "when and where does whitespace enhance comprehensibility"?
For instance:
- Code: Select all
function(a, b, c){foo(a); bar(b); baz(c);}foo(x){fred(x+10)}fred(a){function(a, a, a);}
has no whitespace, and is thus unreadable, even though it fits within 80 columns or so.
Indeed, that *is* unreadable. Which is why I would never encourage it (thanks for the strawman, though!). My comments that you responded to explicitly recommended whitespace, in order to delimit blocks. If I was writing that code, it would be:
- Code: Select all
function( a, b, c ) {
foo(a);
bar(b);
baz(c);}
foo( x ) {
fred(x+10)}
fred( a ) {
function(a, a, a);}
Now look over BOTH blocks of code and tell me: where is the missing semicolon more apparent? (Yes, even if your compiler helpfully informs you what column your missing semicolon is on, and not just what line.)
Now that we've disposed of the false dilemna you attempted to employ to support your point, we can see that the error is equally obvious in both our code. Mine'll say "missing semicolon on line 6", and when you look at line 6, there it is!
Consider:Phil's shopping list wrote:Bagels
Dishwasher soap
Bratwurst
K-Y Jelly
vs.kriel's shopping list wrote:Bagels, dishwasher soap, bratwurst, and K-Y jelly.
In code:
- Code: Select all
if (
gotBagels() &&
gotDishwasherSoap() &&
gotBratwurst() &&
gotKYJelly() &&
)
leaveStore();
vs.
- Code: Select all
if (gotBagels() && gotDishwasherSoap() && gotBratwurst() && gotKYJelly())
leaveStore();
At this point neither are good. The correct way to do this is:
- Code: Select all
if( gotAllOnList( list, cart ) ) {
leaveStore();
}
If you have to worry about how to format a conditional, you're doing it wrong. Refactor. There's no need to have formatting wars over conditionals, because by the time it becomes necessary you've already lost.
