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

后端 未结 20 717
遥遥无期
遥遥无期 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:39

    IDon't think you SHOULD stop yourself from this. Mostly if you FEEL for the big rewrite it's mostly correct to do. I insanely disagree with Joel Spolsky on this thing...

    Though it's one of few places where I disagree with him ... ;)

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

    The impulse to rewrite is righteous, provided that:

    • you "freeze" the existing code (with a label)
    • you start the rewrite attempt in a separate branch
    • you prepare first some unit-test in order to ascertain the current behavior and make sure you reproduce the existing features...

    That said, you have to balance the rewriting process with the measure stability of the legacy code.
    "If it is not broken, do not fix it" ;)

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

    As far as I am concerned, if you have nothing better to do than to rewrite the code then you should make everyone else aware and just do it. Obviously, if it's going to take days to get any sort of result and the changes would mean excessive downtime then it's not a good idea, but eventually that code will become a problem. Make others aware that the code is awful and try to get some sort of movement to rewrite it.

    The problem with the above statement is that as a programmer/developer you will ALWAYS have other things to keep yourself busy. Just leave it on the low-priority list of things-to-do, so when you're struggling with some work you can always keep your rhythm going with the rewrite.

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

    Bad code is not something that can be avoided totally, but it can be isolated by proper abstraction. If it is indeed wasteland, which means, there is no landfills around, focusing design process is much more effective than trying to make people write perfect code.

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

    Just don't - The rabbit hole always goes too deep. Make any small local changes that leave the place cleaner than you found it, but leave big refactoring for when you're alert and have plenty of time to burn.

    A nice starter on tackling big refactorings in small stages at sourcemaking.com :

    you have to make like Hansel and Gretel and nibble around the edges, a little today, a little more tomorrow

    0 讨论(0)
  • 2021-01-30 13:50
    1. reread "Refactoring".
    2. Take a piece of paper and itemize the "Bad Smells" list.
      (for each smell in BadSmells() {
      print smell.name;
      }
    3. Add comments to the code including item(s) from the list.
      while( odorPersists() ) {
    4. Work through the list, laser-focused on one smell at a time.
      }
    0 讨论(0)
提交回复
热议问题