Talk:Invariant (computer science)

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WikiProject Computer science  
WikiProject icon This article is within the scope of WikiProject Computer science, a collaborative effort to improve the coverage of Computer science related articles on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
 ???  This article has not yet received a rating on the project's quality scale.
 ???  This article has not yet received a rating on the project's importance scale.
 

Are final/const variables like in C++/Java not also a form of invariants? Wouter Lievens 12:00, 30 Mar 2005 (UTC) In Java, final primatives are indeed invariants. However, final object references are not unless the referenced class is immutable.

An invariant is a logical predicate really. It usually is a statement about a program, not part of it. For constants and finals, the invariant is simply that these variables don't change value. E.g. if we have int f(const int i) { ... } then an invariant throughout function f(n) should be { i == n }. For the same function f(int i) this would still be the invariant without the const qualifier in the declaration, the const qualifier just helps the compiler realize this, and may act as a hint to the caller.Pieter-Bas 13:21, 7 June 2007 (UTC)

final references[edit]

A final reference is an invariant. The object it references may not be. If the object is mutable, the reference can be considered an invariant and the object not an invariant. If the object is immutable, both become invariants. This is an important distinction when a program needs a reference to remain constant, yet needs the data it references to be mutable.

The Object Invariant page seems to be saying the same as the Class Invariant page, but even less coherently. A class invariant is something that is always maintained over the lifetime of every instance of that class. It's enforced by the language's runtime system or sometimes (e.g. in C++) it has to be enforced using various tricks or explicit code. I would just delete it and beef up the article on Class Invariance. Wouter - const (in C++) is a kind of invariance, but class invariance is guaranteed by private data - state that can be guaranteed to be consistent no matter what clients do with the public interface.

Are constant invariants?[edit]

The explanation doesn't tell about the difference between constants and invariants althoughj it seems that const. r also a form of invariants oly. —The preceding unsigned comment was added by Rohitm 001 (talkcontribs) 13:26, 19 January 2007 (UTC).


A constant is not an invariant, but a the fact that a constant must have a value is.

What kind of Latin is that?[edit]

In Latin, in means "in" or "on" or "into" or "onto," but not "not." LandruBek 20:30, 4 October 2007 (UTC)

did i miss something?[edit]

"Given that there is a single I in the starting string MI, and one is not a multiple of three, it's impossible to go from MI to MU as zero is a multiple of three."

Zero is a multiple of three? —Preceding unsigned comment added by 75.79.69.67 (talk) 19:03, 21 January 2010 (UTC)

Yes, this part is a bit confusing. Could anyone clarify this bit

yes, 0 is a multiple of every integer since 0=x.z where z can represent every number and x must be 0. Ethereal1m (talk) 07:15, 13 December 2011 (UTC)

Edit or eliminate example?[edit]

The article on this puzzle is stated using a valid typeface for the capital "I" (the letter after "H") that makes it unambiguously not an "L" (as in Louis) or a digit "1" (half of two). The same should be done here, or the entire example should be scrubbed in favor of a reference to the puzzle and a brief summary used here. (This reader's default browsing typeface shows all of the above as an unadorned vertical bar also indistinguishable from the symbol for "or" in many computer languages.)MartinRinehart (talk) 13:24, 9 April 2011 (UTC)