Skip to content

do we avoid dead code? #13

@szaghi

Description

@szaghi

From a note on another thread...

avoid dead code, do not write code that has no effect

Is this an agreed guideline?

The discussion is open 😄

Summary from other thread

@zbeekman

  • about select constructs if it's actually impossible to enter that branch of the select statement (even with potentially incorrect user input, corrupted data files, or out of memory errors) then it is "dead" code, and exists for no other reason than to give you a warm fuzzy feeling that you have been a diligent defensive programmer. Additionally this also means there is no way to test its correctness.
  • strive to get 100% test coverage during unit tests
  • don't build it until you need it

@rouson

  • Dead code also violates the agile development method of test-driven development (TDD) in which one writes only enough code to pass the test. The test is the specification for what must be written. If one wants more code to be written, then one must say so in a test.

@tclune

  • about select constructs I’d recommend “always” having a default block, but putting it at a low priority.

@LadaF

  • My practice is to add the name after the end subroutine if the subroutine
    gets longer than one page in my editor. It's a subjective criterion and
    sometimes I forget and add it later when I find end subroutine for which
    I can't immediately see the beginning with the name.

@nncarlson

  • avoid dead code
  • about select constructs If the intent is that one of the case stanzas is always executed but it is not completely clear from the immediate context that this will be the case, then I do add the default clause with an assertion:
case default
      ASSERT(.false.)
end select

Here ASSERT is part of a simple macro-based DBC system that I use. ASSERT asserts that its argument is true, so the strange idiom ASSERT(.false.) will trigger an error. In this case the default clause serves to document to the reader the intent that one of the case clauses is supposed to be executed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions