Wednesday, November 25, 2015

Testing and Refactoring Legacy Code

Nov. 25, 2015
Testing and refactoring Legacy Code ( Julia rating: very good! Definitely watch again, and practice demo code using C# language. )

Julia watched the video, now she knew better about dependency injection, design, and also unit test. The lecture is excellent. MockitoJunitRunner/ Spring is used in the demo, TripDAO inject is demoed to add for better code. 

The lecture in the video is to work on a legacy code in Java, and then, the code is analyzed, refactored, and test code is also added. Julia follows 100% the thinking process, great time to learn. Will review the part to do refactoring in the video. 

Notes taken down:
Craftsmen at work
. Write readable and maintainable code
 - Code must express business rules
. Strive for simplicity
. Know your tools well (i.e. frameworks, shortcuts)
. Work in small and safe increments
- Commit often
. Embrace changes, be brave
. Boy scout rule / No broken windows

Book reading: software craftsmanship
Professionalism Pragmatism Pride
Sandro Mancuso

The verse I like it as well, "How it is done is as important as getting it done".
The story in early 90s to have his code reviewed by the manager in his 20s, really a good story.
200 lines of code, and the cases are the following:

1: allocate memory in one method and deallocate it in another method - risk of memory leak, temporal coupling
2. block of lines, reduce eight line to 2 by thinking harder
3. Try/ catch block too big
4. name of this variable / method, what do they mean?
5. Hard-coded bit - if we want to change where it points to, need to open it, change it, recompile it, and redeploy the entire application
6. Code duplication all over the place
7. A big method - how much we would need to keep in our heads if every single method were that big? What about making them smaller and naming them according to their behavior.
8. It is not respectful - a few lines of code, no one else could understand. No idea what the code does. some cryptic ode in there, trying to show how clever.

Julia had this kind of experience as well in 2014, but Julia now is a big fan of OO principles, SRP - single responsibility principle is her favorite one. And then, open/ close principle, how to estimate the probability of change and then create new class based on the odds, she just loves the idea.

Ref:


No comments:

Post a Comment