Skip to content

Adding flags is very WET right now #928

@KernelDeimos

Description

@KernelDeimos

If DRY means "Don't Repeat Yourself", you could think of "WET" as meaning "Write Everything Twice".

Well, to counter my own point, suggesting that "write everything twice" is always bad is a fallacy; considering Rule of three suggests that anything repeated twice does not require refactoring. I however disagree further and see this as depending on context:

  • is the duplicate close to the source? (will a careful developer see it immediately)
  • is the repeated code a 1-to-3-liner, or 30 lines of nuanced branching?

This issue isn't a duplicated section of code, but something of similar consequence: adding to a logical list in the software (in this case, the list of flags that exist) requires changes in multiple places:

  • two places in bin/http-server
    • documentation for --help
    • check argv['snake-case'] to assign options.camelCase
  • entry in defaults.json
  • three locations of opts.js
    • variable initialization at the top with the default
    • assignment to local variable from opts
    • export at the end
  • two places in lib/http-server.js:
    • assignment from options to instance variable
    • passing from instance variable as argument to httpServerCore

In total, that's adding the same information ("this is a boolean flag called --my-flag") as slightly different code in: 4 files, 8 individual locations.

This is an anti-pattern called shotgun surgery

note: I realize that the description of DRY is disjunctive to the rest of the contents of this issue description. I was going to write this description differently and changed course, but left this description related to DRY intact because the quantification of duplicate code might follow similar rules/guidelines to the quantification of multiple points of code required for a specific change (I don't think anyone is going to write "rule of three but specifically for shotgun surgery rather than DRY")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions