Refactoring & Rewriting

So in the past couple of days I’ve been making a lot of… I suppose I’d call them tweaks, because nothing feels big enough to consider it a major change. Could I even make major changes in a two day timespan without just hunkering down and doing nothing else? Probably not.

So what have I been doing? Mostly refactoring, honestly. Initially I had a couple of methods for updating the wordcount, checking whether to update the day, etc., but I was running a lot of them in multiple lines the __main__ function rather than calling a single clean method. So I wrote a method, getUpdate(), and then subsequently retooled that method to make it more versatile.

Before getUpdate() would ask you for how many words you’d added to your total, then staple those on to whatever your current total was already (right now it’s always 0, because the program doesn’t retain information between sessions). Now the method will ask you whether you want to add words or give your new total (so, stapling words onto the preexisting total, or replacing that preexisting number entirely); then it calls one of two helper methods based on that, in order to do what you want.

Those helper methods also ended up having me refactor and split off more helper methods, which has honestly been a good exercise in thinking through what each line is doing and where it might end up getting reused.

The other biggest “change” has mostly been clearing up my comments, which refactoring has also helped with. Python doesn’t render multi-line comments natively, so the convention is to enclose them in “””s (triple quotation marks), which causes it to register as a multi line string that the computer will just sort of ignore when it comes time to parse. I’ve been using my pre-method comments both as a place to describe what a method is supposed to do — this is good practice — and a place to keep notes about questions/concerns/functionality I might add (this is messy practice). But hey, this project is only for me, right?

Well, a different problem arose, and it feels a little superficial. My text editor, Atom, color-codes everything in order to help with readability, and it renders all of Python’s strings in a bright green. This works great to offset strings from other things, but when I have lines and lines and lines of green, it makes it hard to see anything else, because it draws the eye so much. Refactoring and tweaking has been as much a way for me to strip down my notes to a point where I can use one or two single-line comments and get rid of the green, as it is to improve my code.

The next big questions (that I’m scared to answer) will probably be: how do I store information between sessions? And how do I test multi-day streaks? The multi-day streaks will have to come after the storing-between-sessions question, just on account of I can’t have multi-day updates if I can’t store between sessions, but once I’ve got that… hopefully more things will start falling into place.

More potential avenues for the future, non-immediate: can I/should I practice test driven development with this (might be a bit close to my Model/View/Controller thoughts from last time, haha)? How do I integrate a Python app with Javascript (am I going to need to figure out Flask, which I don’t even know what that is)? Is it possible that I’ll have to “finish” the program, then rewrite it in Java to make it compatible (eek, but I sort of miss Java’s structure compared to Python’s spaghetti-noodle flexibility)? How do cookies work? Should I take a day to just work on building really basic HTML sites with interactive fields and buttons (yes)?

And, just for the sake of long-term organization and consistency, I should probably a) make a more structured planning document and b) get a GitHub where I can keep better records of what I’ve been doing day-to-day.

Leave a Reply

Your email address will not be published.