Code flag to indicate a need to revisit the code / locate unfinished code?
Petter Reinholdtsen
pere at hungry.com
Mon May 29 23:34:39 CEST 2017
Thanks to the Coverity findings, I came across this code (CID 1437461):
public Series updateSeriesSetFinalized(Long id){
Series series = seriesRepository.findById(id);
if (series == null) {
// throw Object not find
}
String username = SecurityContextHolder.getContext().getAuthentication().getName();
series.setSeriesStatus(STATUS_CLOSED);
series.setFinalisedDate(new Date());
series.setFinalisedBy(username);
return seriesRepository.save(series);
}
This made me wonder if perhaps we should standardize on a flag/marker to
place on code like the block for series == null above, to make it easy
to find code that need to be revisited / fixed.
A fairly common way to do it is by adding 'FIXME' or a similar easy to
search for expression in front of comments like this:
if (series == null) {
// FIXME throw Object not find
}
Another is to add output statements reporting that the unfinished code
was reached. The exact method can differ, but something like this would
probably work:
import static java.lang.System.out;
[...]
if (series == null) {
out.println("FIXME missing throw Object when not found");
}
Note, it must be possible to find all such code blocks, so some unique
indicator should be used also here.. I used FIXME in the string, but a
special function call name could be used too.
Thomas, what do you think? Do you have a better way to keep track of
the unfinished code?
--
Happy hacking
Petter Reinholdtsen
More information about the nikita-noark
mailing list