4 ms·
const database_year_offset = 7; fix_start_year(year): return year + database_year_offset; process_record(record): record['start year'] = f
by clarry 7y ago
const database_year_offset = 7;
fix_start_year(year):
return year + database_year_offset;
process_record(record):
record['start year'] = fix_start_year(record['record']);
In this version with one less magic constant (and renamed function), the comment would look very redundant.
DougBTX had the same idea, at the same time. I don't think their version needs the comment either. EDIT: Dang you removed a perfectly fine post :)
- nerdponx 7y agoI guess, but I think it's more that my example fails to illustrate the point well. Informative comments cannot always be "factored out" like this. Do you at least agree that a ticket or bug #, or a link to an issue in an issue tracker, would be appropriate?
- clarry 7y agoI think a comment is appropriate if the problem cannot be factored out. But in my experience such things can be factored out most of the time, hence the argument that most code should be boring and immediately obvious.
- Firadeoclus 7y agoFactoring out a comment into code sometimes loses information. I would argue that database_year_offset is not as informative as the original comment. Free form text can say things better than identifier names.
- nerdponx 7y agoMost code, sure. But it's not an ideal to be striven for, or a metric to be used when evaluating code.