Checking Struct State with the Compiler
There are times when a state of a struct and certain processes are just not appropriate anymore. A nice clear example would be a database transaction. While a database transaction is in progress, certain processes are appropriate such as adding another operation into the transaction. You may also want to commit your transaction or roll it back. However, once we have committed our transaction, we cannot roll it back or add another operation to the transaction, we need another transaction for this. Considering this, I would want my compiler to check and ensure that I am not passing in a transaction into certain functions once the transaction is no longer in progress. The compiler will not only give me instant feedback, it will also be safer, as it could be that only certain edge cases could cause a bug, increasing the chance of the bug slipping through tests.
To get this compiler checking, I need a state in my struct. I then need that state to change...