Splitting in smaller functions
After fixing variable names, it's the next step towards improving readability
One of the mistakes I made when writing the Easter program was that I chose to write it in JavaScript. The reason I made this choice was so that you could easily run it in your browser.
It turns out that running it isn’t that important. What is important is for readers to be able to read it. While Python is easy for uninitiated to read, JavaScript is much less so, not because it’s a worse language, but because it has variable declarations; some people will say that this is a good thing, but it definitely creates some noise.
This shows that there’s no such thing as a language that is universally better than other languages. Which one to choose depends. I’ve written about this in the past.
In any case, after fixing the variable names, and before going on to improve its readability further by splitting it in smaller functions, I rewrote it in Python. You can see it (split in smaller functions) here. Here’s an extract:
def calculate(self):
self.find_days_from_equinox_to_full_moon()
self.find_days_from_full_moon_to_sunday()
self.find_easter_sunday()
While the program is getting much better, it still has many improvements that need to be made. But the thing is, it’s quite long. More on this next time.