Legacy Code: The best way to learn how to do things better
I've been working a lot with some copy and pasted legacy code. It's rife with poor coding conventions (read lack of) and "let's get it working first, then we'll go back and do it right." Unfortunately, as everyone knows (except those who speak those words) those days never come.
In Michael Feathers' book Working With Legacy Code, he calls legacy code "code without unit tests." The code I've been working on definitely falls in that category. Due to the nature of the code, I'm finding it very difficult to write unit tests for it. Combine that with the fact that I haven't read all of Michael Feathers' book, it makes for some pretty challenging days spent looking at this debacle.
In refactoring some of the code in an effort to better understand what the code is doing, I've found ReSharper to be extremely valuable. I'm so glad I splurged for that software.
Hopefully some of the minor changes I've made to the code will help the person maintaining this software to get up to speed a little sooner than it took me. Hopefully I left the code in a state better than what I found it.
Anyway, I've learned a lot about coding and how not to implement business rules and other logic. It could have been marginally better if all this stuff was encapsulated in the web service(s) but it probably would have been even harder to test.. Maybe some time in the future, we can take the time to properly re-code the entire application. Until then, however, I guess I will continue to take the opportunity to learn some more coding techniques.
In Michael Feathers' book Working With Legacy Code, he calls legacy code "code without unit tests." The code I've been working on definitely falls in that category. Due to the nature of the code, I'm finding it very difficult to write unit tests for it. Combine that with the fact that I haven't read all of Michael Feathers' book, it makes for some pretty challenging days spent looking at this debacle.
In refactoring some of the code in an effort to better understand what the code is doing, I've found ReSharper to be extremely valuable. I'm so glad I splurged for that software.
Hopefully some of the minor changes I've made to the code will help the person maintaining this software to get up to speed a little sooner than it took me. Hopefully I left the code in a state better than what I found it.
Anyway, I've learned a lot about coding and how not to implement business rules and other logic. It could have been marginally better if all this stuff was encapsulated in the web service(s) but it probably would have been even harder to test.. Maybe some time in the future, we can take the time to properly re-code the entire application. Until then, however, I guess I will continue to take the opportunity to learn some more coding techniques.
Comments
Post a Comment