Wow - who knew I'd have to write about this again so soon - if ever. Please understand, I'm not advocating lack of style. I'm not an anarchist, just a fan of practicality. And practically speaking, most people code on monitors made past 1988.
Time for an example.
I didn't write this code, but here is an example - I searched for all of 10 seconds to find it, I'm sure there are worse ones in our system:
Do you see that? One < 80 column wrapped line - one unwrapped line.
The "data" line is 56 columns wide. Can anyone tell me what the point of wrapping this line was? I know! habit. Were the second line not wrapped, it would have been 104 columns wide - still shorter than the next line. The "out" line is 107 columns.
Let's first try and cram that into an 80-column-width cheerleader's wet dream (I'll even be kind and add spaces):
Now let's keep the above spacing. Some people seem to think I'm advocating no coding standards whatsoever - well, plain not true.
One operation per line. Concise - easy to understand. Get client body, send that body as a soap message, parse the data. No added lines, no added breaks, no added complication just to keep everything crammed into a weird artificial and archaic constraint.
When looking through thousands of lines of code for the first time, I always prefer chunks of code that each execute a single step. I don't care that the regular expression is one long line - because in normal maintenance, I'll never need to know. In the off chance I do need to know what the expression does, well, I'm going to have to read it anyway - but I have to find it first.
Just don't miss the forest (overall project code) for the trees (individual lines).
1 comment:
I had no idea that anybody else cared about this. With you 100% of the way. Why write code for a particular column width when the next person - me, probably, when I change monitors - will have a different one?
Post a Comment