How to restrain one's self from the overwhelming urge to rewrite everything?

后端 未结 20 716
遥遥无期
遥遥无期 2021-01-30 12:50

Setup

Have you ever had the experience of going into a piece of code to make a seemingly simple change and then realizing that you\'ve just stepped into a wasteland tha

相关标签:
20条回答
  • 2021-01-30 13:32

    It's not quite an answer, but reading the beautiful article The Narcissism of Small Code Differences might help.

    0 讨论(0)
  • 2021-01-30 13:32

    Joel has an article about this:

    There's a subtle reason that programmers always want to throw away the code and start over. The reason is that they think the old code is a mess. And here is the interesting observation: they are probably wrong.

    0 讨论(0)
  • 2021-01-30 13:34

    How to restrain one’s self from the overwhelming urge to rewrite everything?

    Become old*

    As this has happened to me, I've gradually lost the urge to rewrite everything. Why?

    • Once you've done it a few times, you realise that you often end up worse off than you started.
    • Even if you're god's gift to programming and your brilliant rewrite introduces no new bugs, you'll simply fail to notice or implement about 30% of the small edge-case features/bugs which things rely on. This will cost you months in fixing
    • Nothing wears down your irrational exuberance like time. Often this is a sad loss, but in this case, it's a win.

    *(more experience may also be a suitable substitute if you lack the free time to become old)

    0 讨论(0)
  • 2021-01-30 13:37

    I've found that spending two months fixing bugs caused by my "harmless" re-write was enough to cure me of the urge to do these sorts of things without a clear mandate/project plan to do so.

    0 讨论(0)
  • 2021-01-30 13:37

    Refactor only if your boss/company actually encourages it, otherwise you'll end up doing frequent extra time to bring up code to perfection... Until someone less dedicated touches it again.

    0 讨论(0)
  • 2021-01-30 13:39

    I'm a big fan of making lists!

    As soon as the urge takes you to re-write something - spend 10 minutes making a list of the things that need re-writing. Follow all of the alleys that take you further into the code that needs attention and list those, too.

    Hopefully within a relatively short space of time you'll have one of two things:

    • A really long list that completely puts you off wanting to rewrite anything ever again.
    • A list which actually isn't that long, so why not indulge yourself and go for a re-write?!
    0 讨论(0)
提交回复
热议问题