Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you use invariants when you program?

Tags:

invariants

I am taking an intermediate programming course which stresses the use of invariants. I have never used them before and they seem to take up more time to create. Does the software engineering industry stress the use of invariants?

like image 575
Brandon Tiqui Avatar asked Nov 07 '09 09:11

Brandon Tiqui


1 Answers

Depends on who you ask - I use invariants simply because it makes life easier. Learning invariants is like learning blind-typing. Each time you use an invariant, you know more about your code. If you insert the invariant as a comment in your loop, it helps the reader A LOT. I would say that using invariants makes creation and maintenance of source code much cheaper, and makes you able to create much more sophisticated algorithms, which are still maintainable.

And in contrast to OOP, I have never experienced anyone wasting their time by using invariants.

like image 109
Lars D Avatar answered Sep 21 '22 17:09

Lars D