Monday, March 20, 2017

Why should we use assertions when programming ?

Because the only real documentation for the code you're working on is the code itself. Comments become stale over time, test cases aren't always executed and developers come and go. If your code uses assertions or similar mechanisms, it is documenting itself by stating at the onset what are some of its assumptions.

That said, it's important to write readable code. If there's no style enforcement and no care for making code that reads well, it's like reading a book where each paragraph was written by a completely different person.

No comments:

Post a Comment