Everything2
Near Matches
Ignore Exact
Full Text
Everything2

Type checking

created by bis

(idea) by bis (1.1 mon) (print)   ?   (I like it!) Sat Jul 15 2000 at 2:33:51

Type checking is the stage of parsing that a compiler (or interpreter) passes through in order to ensure that data types are all being used correctly and consistently. That is, all assignments are being made correctly, functions are being passed arguments of the correct type, comparisons are only done between variables of the same time, etc. Languages like Perl and C are not very strict about this, wheras languages like Java and SML are.

(thing) by Noung (1.3 hr) (print)   ?   (I like it!) Tue Jan 01 2002 at 18:40:16

Type-checking (or more correctly, static type-checking) is a compile time feature provided by some programming languages.

Apart from in pure OO languages, every piece of data in a programming language has a type. In laymans' terms, the type can be viewed as telling the computer what type of data is going to be stored in a certain place (known as a variable). For instance, it could have the type integer for numbers and string for strings of text.

Static type-checking is a feature that attempts to make sure that certain rules of how to use types are followed. As a simple example, it is clearly wrong to try and put data of type string into a space meant for an integer. As an example of why this is wrong, imagine what would happen if we tried to add two strings together, thinking they were integer numbers!

Static type checking should prevent such things ever happening by throwing an error at compile time. There are disadvantages to this feature, the biggest of which is probably added language verbosity. For any given function, you have to define the return type, arguments and exception types. This makes function definitions somewhat verbose.

There are also dangers to code reuse (something C++ pretty much gets around with templates). Because any given function is so tightly defined, it can only be used for the exact task which it was defined. Imagine we have a function print() that took an argument of type integer and we want to print a string! We'd need another function.

Despite these drawbacks, many people feel that static type-checking is worth it for the plethora of runtime errors it can help avoid. However, the polar viewpoint is that the added language complexity and verbosity can lead to more errors.


(idea) by Rose Thorn (5.4 y) (print)   ?   (I like it!) Sun Sep 01 2002 at 12:58:10

Note that type-checking also happens at run time, at least in strongly typed languages. It is important in OO systems, to see if objects can be assigned to statically-typed variables. It is important in dynamically-typed systems like LISP, to see if any given operation is possible, or if things should break now.

printable version
chaos

type safe SML weakly typed type-checking
Algol 68 SparkMatch personality types C++: true or false? The Objectivist Ethics
?: qualitative comparison of assembly language and unprotected sex type derivation But life is hard when the written word is your first language
Cold hands, warm hearts. Handfasting in London, wertperch and grundoon together. Physical Education possible operation
Vector Angles less than 90 Degrees Dynamically formal language theory check
Java C++ C strict
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
What you are reading:
Roman Britain
Dvorak
Artemisia
Is this the last four years or what?
I left you a note and you replied to it
Existentialists make bad boyfriends
The Skeptical Environmentalist
Forget women - here's what men want
The lightning men
hippopotamus
predicate calculus
tit bits
catting weird things to /dev/audio
New Writeups
Augustine
Vanya on 42nd Street(review)
tentative
Chances Not Taken(idea)
Heitah
Why I love Everything2(person)
trixingee
Dungeon Mastering for the first time(idea)
Netrat0
It's Called Subtext, Honey(person)
eyeofthebeholder
The Dragon(idea)
Heitah
consist, comprise, constitute, or compose(idea)
Meezzio
Gotlandssnus(thing)
argv
Astral Plane(idea)
Madara
One Winged Angel(fiction)
Tom Rook
Talk is cheap(poetry)
shaogo
Adelle Davis(person)
Aerobe
race car g sfjsgsd(poetry)
Binah
Dream Log: July 5, 2008(dream)
StrawberryFrog
Forgotten things in space(idea)
Everything 2 is brought to you by the letter C and The Everything Development Company