There is this code base, some note in a readme but no general docs. Wow, god bless we have some tests - but integration only. Nice, changing "internal structure without external behavior" ...yeah, refactoring. But do not tell anyone. You have written spagehetti code in the first place, why, what for - you thought you will be gone the day someone realizes - thats also a reason just to stay for 2 to 4 years as a dev in same company.
But yeah. Back to spahgehtti. Touching and moving parts and thinking for some hours didn't work. Even worse it was a mess and the code was broken. Stash and again. This time structured, methode by methode. The code works. Changing minor parts should not break the tests.
Extract Method refactoring by moving parts of the flow out into new functions.
Hmm. And comments missing everywhere. But code written in a rush, on pressure, not
# -*- coding: utf-8 -*- if __name__ == '__main__': import doctest doctest.testmod()
Using python doctest create a seperate file and load the new methods from there. Using this I figured out new structure about the small parts and added these new methods in bundles to a file for each minor sructure. Yeah.
Doctest is not super handy with some more difficult inputs but the level of abstaction where we handles ... but documenting and testing in one is just as writing API-specs and turn into code and documentation automatically. Easy, easy, ...
Or using an IDE with refactoring support, but I am not so much into IDEs
Prevent this by coding together with others, use merge requests and plan your code as structured and future you will be grateful. And yeah I made this experience not the first time, but it gets better every time ;)
At the end it feels much better to hand over this peace. Or at least I would like get code like this handed over. Thanks.