1
$\begingroup$

The Wikipedia page for strong and weak typing says:

"Strong typing" generally refers to use of programming language types in order to both capture invariants of the code

What is "invariants of the code"? There is no link for that

$\endgroup$
2
  • $\begingroup$ Please note all the hedging and disclaiming in that article: "generally", "colloquially", "no precise technical definition", "different authors disagree", etc. Also, statements like "Advocates of dynamically typed (generally "weakly typed") languages" are highly problematic, since many dynamically typed languages are indeed considered to be strongly typed by their communities (e.g. Ruby, Python), whereas C is generally considered to be weakly typed, despite being statically typed. $\endgroup$ Jun 13 '21 at 5:08
  • $\begingroup$ I wrote a little "rant" about those terms here: stackoverflow.com/a/122751/2988 $\endgroup$ Jun 13 '21 at 5:19
1
$\begingroup$

An invariant is a statement that holds during the execution of a piece a code. For instance, you might often encounter loop invariants (statements that hold on every iteration of some loop) or class invariants (statements preserved by every method call).

In particular, what I believe the article is referring to here is static type checking, i.e., statements which enforce conditions on the types of variables. Indeed, saying it "excludes certain classes of programming errors" would include errors stemming from (the lack of) type safety. For example, if you have weak typing, a function expecting an argument n to be an integer will only fail at runtime if you pass it a string. With strong typing, you can catch such errors before running the program.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.