In “technology actually making my life easier” news…
I recently started working with a new-to-me but rather old code base, and quickly found that coding styles varied wildly across the files (ick), and some of the files (including some third-party libraries which aren’t really fair game for editing) had some very long code comment lines. The authors clearly weren’t fans of breaking comments over multiple lines, and when they did it was clear that they were using a very wide editing screen.
I invariably have at least two side-by-side editing windows, and I use large fonts compared to most folks (and hence fewer columns – with a two-window layout I get 92 in each), and so the comments were frequently a mess to read unless I dropped back to only a single window, which I didn’t want to have to do. I could enable word-wrapping in the buffer, but then the code would be wrapped as well as the comments, which I find hinders code comprehension. All in all, I could see this being a highly frustrating issue for me.
Fortunately my text editor is programmable, so I set about writing an extension to make it wrap code comments smartly (before words whenever possible, and with a wrap prefix based on a variety of common patterns to make things line up nicely).
In short, it’s working great! It even re-wraps dynamically when I change the window size (thanks to some prior art which taught me how to approach that), so it’s always wrapping at the edge of the window. So while the actual text might contain things like:
/**
* @param string|object $v is a timestamp string in YYYY-MM-DD HH-NN-SS format
*
* @return mixed date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format
*/
and
$QUOTE_FIELDNAMES; // Allows you to force quotes (backticks) around field names in queries generated by getinsertsql and getupdatesql.
My editor will display it to me something like this:
/**
* @param string|object $v is a timestamp string in
* YYYY-MM-DD HH-NN-SS format
*
* @return mixed date in unix timestamp format, or 0 if
* before TIMESTAMP_FIRST_YEAR, or false if
* invalid date format
*/
and
$QUOTE_FIELDNAMES; // Allows you to force quotes
// (backticks) around field names in
// queries generated by getinsertsql
// and getupdatesql.
(Albeit not normally quite that narrow, but it emphasised it better. If the comments were multi-line paragraphs then it might not look as clean as that – some of the fake lines might be “too short” – but it’s always more readable than it would have been otherwise.)
Naturally, after I had it mostly working I thought of a better way of doing it :). I’m not sure if I’ll pursue that, though – I’m pretty happy with the current version.