In computer science, an invariant is a value that doesn't change.

learn more… | top users | synonyms

1
vote
1answer
96 views

How to guarantee invariants / Inner logic in setter methods

According to DDD-principles I use factory-methods to create consistent objects and to ensure that the objects are in the right state. Now I'm in doubt about inner logic of setter methods. I'm tied up ...
4
votes
1answer
2k views

Loop Invariants in Python

I have a bit of experience with loop invariants but I'm not really clear on them. I'm trying to learn them through an example in Python. Can someone point one out or help me understand? I've ...
3
votes
1answer
609 views

Loop invariant vs Assertions

I have an exam on Programming Concepts this Saturday and I am struggling to find some information to understand some concepts better. What is the difference between loop invariant and assertion? To ...
13
votes
5answers
2k views

Why are invariants important in Computer Science

I understand 'invariant' in its literal sense. I also recognize them when I type code. But I don't think I understand the importance of this term in the context of computer science. Whenever I read ...
5
votes
4answers
1k views

Why is Invariance, Covariance and Contravariance necessary in typed languages

Ok not really sure if I'm right. I only recently learned that I needed to have contravariant interface to be able to pass that interface as a parameter in C# and this feature was only added in .NET ...
2
votes
3answers
156 views

Common mistakes which lead to corrupted invariants

My main source of income is web development and through this I have come to enjoy the wonders of programming as my knowledge of different languages has increased over the years through work and ...
13
votes
5answers
3k views

What are invariants, how can they be used, and have you ever used it in your program?

I'm reading Coders at Work, and in it there's a lot of talk about invariants. As far as I've understood it, an invariant is a condition which holds both before and after an expression. They're, among ...