Skip to content

Please consider deleting commented code #8

@rouson

Description

@rouson

I strongly recommend against including commented code in a release and usually recommend against committing commented code at all. Some examples start in geometry.f90 at lines 113 and 159 and there's a roughly 100-line block in grid.f90 at line 239 and roughly 200-line block at grid.f90 line 633. The blog post "Please don't commit commented-out code" details a few reasons.

In the rare case in which I'm confident the code will serve some useful purpose but is not needed now, I bracket it with an unconditional branch:

logical, parameter :: hell_freezes_over=.false.
if (hell_freezes_over) then
  call speculative_future_useful_code()
end if

which should pose no runtime penalty at least at the highest optimization levels because an optimizing compiler will remove the entire branch during a dead-code-removal phase of optimization based on the fact that the branch is hardwired to always skip the code. Even this I only do extremely rarely if I'm trying to leave breadcrumbs that I'm confident someone will want in the future.

Useful code has a long life and that can be a good thing. Sadly, however, commented code can have an infinite life because it can't be tested, fixed, or even broken. I guess this is the software equivalent of the old physics description of an untestable theory as being "not even wrong." Presumably commented code is thought of as temporary, in which case, it's worth noting that a few years ago, someone found and republished 50-year-old code from NASA's Apollo-11 moon landing and it contained temporary code that has now survived more than half a century. If the code has no current purpose, I suggest deleting it or putting it on some unreleased branch named something like code-cemetery or where-useful-code-goes-to-die. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions