5 ms·
Not all language cruft is created equil. I find the more more that happens within a line the easer it is to write but the harder it is to read. x = (a = 7 * (
by Retric 18y ago
Not all language cruft is created equil. I find the more more that happens within a line the easer it is to write but the harder it is to read.
x = (a = 7 * (b = 14)) + (c = 9 * ((d > 7)? e:f));
Now toss in some casts and the line becomes harder to read, but at the same time it's considered poor from to have 4 assignments on one line. Yet that's valid C, C++, Java, C# etc and it's got fewer symbols so it must be better according to the arc view of the world.
So is reqiring one assignment per line cruft or a good idea? How about those assignments? I would argue that one of the most useful mesures of a language is how easy it is to read other peoples code, but then you end up with something like Pascal...
PS: I acutaly like mantaining pascal code more than most languages then again it could have more to do with the experence of the people who use Pascal.
- philwelch 18y agoThat's one line, yes, but what a line! That's 20 tokens or so, many of which are weird and hairy (the ? operator, multiple assignments). And in Lisp style you'd have that as multiple lines anyway.
- Retric 18y agoTrue, but my point is it's more tokens if you write it as several lines. a = b = c 2; vs b = c 2; a = b; So token count is still not really what we want to measure even if it's better than line count.
- philwelch 18y ago"it's more tokens if you write it as several lines" As several lines or several statements? x = ____(a = 7 * ________(b = 14)) ____+ ____(c = 9 * ________((d > 7)? e:f)); Same statement, same token count, multiple lines.
- Retric 18y agoStatments, that's in no way easer to parse than that some code on a single line. (Assuming you have collar coding for the ()'s in your IDE.) c = 9 * ((d > 7)?e:f); x = ( a = 7 * (b = 14)) + c; IMO is not that bad, it's the mixing of all the assignments and the conditional that makes it hard to parse, and c = 9 * ((d > 7)?e:f); x = c + (a = 7 * (b = 14)); is fairly readable even if some of the ()'s are not needed. PS: ;'s I thought it was clear that the ;'s denoted lines not the whitespace which is meaningless.
- philwelch 18y agoSemicolons do denote statements, but that doesn't prevent you from clever use of line breaks. I still think my version is more readable.
- Retric 18y agoEdit: NM, reply is now working. I just wanted to say that personaly I have tryed learn to ignore indention and other clues becasue it's far more costly to misunderstand what the code is doing than try and use hint's that may have become old over time. To paraphrase: in that way lay bugs that look like dragons. I also tend to do the same thing with comments on the first pass though. It's only when I don't understand the code or or it looks "odd" that I start to notice the extras like that.
- Retric 18y agoI can't reply to: "Semicolons do denote statements, but that doesn't prevent you from clever use of line breaks. I still think my version is more readable." for some reason. I just wanted to say... Edit: NM, reply is now working so I moved the comment.
- deleted 18y ago[deleted]
- silentbicycle 18y agoJust because such code parses, it doesn't mean you should write that way. Rather than requiring a ludicrously dense or terse style, most real projects will just have fairly reasonable coding standards (whether formally specified or just commonly understood) and expect you to exercise good judgment. Besides, I don't think anybody is really expecting you to cram as much into one line as possible.