• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please explain this

 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to know what the statement below means and what is the meaning of the word "invariant".
Whenever you would have written a comment that asserts an invariant.
 
Rajinder Yadav
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Was there something more to that line, hard to tell what context this statement was being used in?
The word 'invariant' means unchangable, something that is constant.
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rajinder
Thanks Rajinder for the prompt reply. Sorry for the incomplete question. The question was asking about when should an assert statement be used. So we can say that final vars. and Strings are invariant.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An invariant is a rule that applies throughout the life of a data structure or procedure, and all changes must maintain the correctness of the invariant.
Say you have a program which is simulating some card game. You know that each pack of cards must have 13 cards of each suit, and that the suits are spades, hearts, diamonds and clubs. So, it is appropriate to use assertions which test the above, eg there cannot be more than 13 cards of the spade suit.
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rajinder and Roger.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic