Jokes aside, this week we dealt with an important part of software engineering; maintenance.
For our own personal one-person projects, we don't have much of an issue. We know how our code works, what it does, and the logic behind what we did.
However, if we have a long, complicated project, or multiple people, or we're revisiting an old project of ours, we may not remember (or even know!) what the function does, if it even works, and if our changes or modifications will make or break it.
Previously, we had comments to explain certain things to outsiders in our code, but comments won't save us if we tweak an algorithm, and assume it still works.
Thankfully, we've learned an incredibly useful operation this week; "Assert".
Assert is, as the name implies, an assertion. While niche in itself, it's extremely useful in something we've seen a lot in our CS career so far at U of T: Doctests.
When writing a function, our style of commenting has us write a docstring before each function, including an ideal situation that shows the output for a successful implementation of the function.
Assert lets us test this; if we assert that function foo() will return "bar", and foo() doesn't return "bar", then when we run it, we're given a reminder that our function didn't pass our test case. Our syntax may be right, but our logic may have flaws in some places.
Assert (as we've learned it) will allow us to catch issues like that, to make our code all the more organized and well-running.
No comments:
Post a Comment