Computer Programming Types determine the kinds of values and how they can be used in the given programming environment. In most cases, a programming language defines a set of basic data types, e.g. for numbers, characters or strings. In higher languages, it is often possible to define new data types from the existing ones, for example, to represent a postal address (consisting of strings for street and city and integers for the postal code). When communicating data between different programs and computer systems it is important to either use types that both can recognize, or have a means of translating between them.
Type Definition[edit | edit source]
A complete definition of a data type consists of up to three things:
- Physical representation
- how is the data stored
- what can you do with the data type (the meaning); what can you not do, such as divide by zero or string manipulation; and what happens if you "overflow" the buffers to do actions with results falling "outside" the space allotted
- Automatic Functions
- what activities, outside program control, can change the data (hardware, user, system clock)
Primitive Types[edit | edit source]
There are a few basic data types seen in some programming languages:
- Unlimited in some languages, limited to 8-bit, 16-bit, 32-bit, 48-bit, 64-bit sizes in most languages (C, C++, C#, w:DDS, Java, w:RPG). In some languages (Ada, w:FORTH, PL/I) size can be freely defined.
- e.g. 2/3, only a few languages have these.
- Floating point, most languages offer single and double precision (C, C++, C#, DDS, Java, w:RPG). In some languages (Ada, PL/I) precision can be freely defined.
- Base 10 (human) fixed point, often used for monetary values. Only a few languages (Ada, PL/I, w:SQL, COBOL, w:RPG, DDS) offer fixed point. Precision can usually be freely defined.
- Base 16 available on IBM Systems. Digits are zero through F. Most modern languages don't need a separate Hexadecimal type, they use integers and specialized I/O routines.
- Packed Decimal
- Two digits can fit into same space as one character. Look at definition of character set for w:ASCII, w:EBCDIC, or similar conceptual system. Note letters and special characters are represented by two hexadecimal half bytes so with packed data, two digits can fit in same space as one letter. Usually one half byte is reserved for numeric sign (plus or minus).
- A complex value usually consisting of two Float values. Only a few languages (C99, Fortran) have these. In Object Oriented languages often implemented by a library (C++, Ada).
- A character, usually of 8, 16 or 32 bit size. Some Characters sets, like UTF-8 are for a variable length.
Composite Types[edit | edit source]
- An assorted combination of primitive types.
- Type is determined at runtime.
- In Object Oriented languages.
- See article Arrays.
- A sequence of characters. Often implemented as Array of Characters.
Type Attributes[edit | edit source]
- Null Support
- In addition to data blank or zero, we can have null value, meaning we not yet know what belongs there.
- DBCS Double Byte Character Set
- Some nations and cultures "alphabets" (such as Chinese, Japanese, Korean, Russian (Cyrillic)) can use graphical characters called ideograms to perform a role similar to the letters A to Z in western nations languages when constructing meanings, except each ideogram carries more meaning than each A to Z letter. Data types are available to store these graphical character sets, which contain more symbols than can be represented by the 256 combinations found in traditional western character sets, thus a double byte character set (DBCS) exists to account for every combination.
- Some special fonts use a similar system.
- Some bar coding uses similar concept.
- Date Time and Duration
- These are special data types used to support date math, such as calculating number days between two dates.
- Flags or Indicators
- They contain value like True / False or Yes / No. They are often used to recognize use of a keyboard function (which special keys got pressed); printer condition (ready for a new page); file access (we got the record we were looking for, we're now at end-of-file). These special conditions mean that special actions needed.
- Variable Length
- Width of data is controlled by the content.
Language Specifics[edit | edit source]
- Ada Programming/Type System
- C Programming/Types
- C++ variables
- Haskell/Type basics - the language Haskell is often used as a platform for programming language researchers to develop new, advanced type systems. This wikibook could give you insight into what types might look like in the near future for the common programmer. (Note: see also the advanced section of the Haskell wikibook)