Refactoring is great. So is optimization. In fact I'd say I enjoy it more than I enjoy actually writing code. It's fun to tear something down and build it back up. What is dead may never die, but rises again, harder and stronger. Though, I am Chris' complete lack of surprise over the ending of that show which will remain nameless.
Anyway, now that I've confused my only reader (Hi Humphd) with stupid Game of Thrones references, welcome to this week's OSD600 blogpost.
A little backstory before we begin: this week we learned about rebasing in git, something that will confuse me for at least the foreseeable future. So here's a picture explaining it:
Essentially rebase
, an alternative to merge, packs commits into a single commit for better organization, and merges one branch into another at a new starting point, whereas merge
simply takes all the changes and merges them into another branch in one commit.
Confused? Me too.
Anyway. The previous week had another student work on our project to implement a feature. Unfortunately for me, that student (who also will remain nameless) also decided to tidy up my code while he was down there (Down where, where is he exactly?) This left me in a pickle because now I needed to find additional points to refactor.
The first thing I wanted to do was add a __main__
to my program. I didn't want to actually add a main to the script until I was ready to outsource some of the work to different files to make the program even more modular. Given this I jumped on the opportunity and separated the concerns as much as I could.
I split the new main into three separate files: a utility file, a fileio file, and a checker file. Now the project's code is split .
I used this guide a lot, which is also thanks to @humphd as I believe he linked it to us Python users early in the semester. Really helped me learn more about structuring actual applications the Pythonic way rather than in a more scripting manner. This was exceeding useful too. And interesting. I'll have to bring it up on my next date, surely they'll find it fascinating too. And if not, well, I'll be separating my own concerns... and the bill.
Nonetheless, you can see the main commit here. The refactoring process was a lot of fun, and learning about how to use rebasing was interesting too. I broke the code a lot but was always able to fix it with just a few tweaks. The rebase with off without a hitch and fast-forwarded after fixing a slight merge conflict with the main file, which makes sense given how much of it was changed recently. I still need to get a better handle on merge conflicts, but all in due time I suppose.
Top comments (0)