
This article contains the necessary minimum of those things that you just need to know about typing, so as not to call dynamic typing evil, Lisp - a typeless language, and C - a language with strong typing.
The full version contains a detailed description of all types of typing, seasoned with code examples, links to popular programming languages ββand demonstrative pictures.
I recommend reading first a short version of the article, and then if you have the desire and complete.
')
Short version
Typing programming languages ββare usually divided into two large camps -
typed and
untyped (
typeless ). The first example includes C, Python, Scala, PHP, and Lua, and the second is assembly language, Forth and Brainfuck.
Since βtypeless typingβ is inherently as simple as a cork, it is not further divided into any other types. But typed languages ββare divided into several overlapping categories:
- Static / dynamic typing. Static is determined by the fact that the final types of variables and functions are set at the compilation stage. Those. the compiler is already 100% sure which type is where. In dynamic typing, all types are found out already during program execution.
Examples:
Static: C, Java, C #;
Dynamic: Python, JavaScript, Ruby.
- Strong / weak typing (also sometimes say strict / weak). Strong typing is distinguished by the fact that the language does not allow to mix various types in expressions and does not perform automatic implicit conversions, for example, it is impossible to subtract a set from a string. Languages ββwith weak typing perform many implicit conversions automatically, even if precision loss can occur or the conversion is ambiguous.
Examples:
Strong: Java, Python, Haskell, Lisp;
Weak: C, JavaScript, Visual Basic, PHP.
- Explicit / implicit typing. Explicitly-typed languages ββdiffer in that the type of new variables / functions / their arguments must be specified explicitly. Accordingly, languages ββwith implicit typing shift this task to the compiler / interpreter.
Examples:
Explicit: C ++, D, C #
Implicit: PHP, Lua, JavaScript
It should also be noted that all these categories overlap, for example, the C language has a static weak explicit typification, and the Python language has a dynamic strong implicit one.
However, there are no languages ββwith static and dynamic typifications at the same time. Although looking ahead I will say that here I am lying - they really exist, but more on that later.
Let's go further.
Detailed version
If the short version was not enough for you, good. No wonder I wrote a detailed? The main thing is that in the short version it was simply impossible to fit all the useful and interesting information, and the detailed information might be too long for everyone to read it without straining.
Typeless typing
In typeless programming languages, all entities are considered simply sequences of bits, of various lengths.
Typeless typing is usually inherent in low-level (assembly language, Forth) and esoteric (Brainfuck, HQ9, Piet) languages. However, it, along with disadvantages, has some advantages.
Benefits
- Allows you to write at an extremely low level, and the compiler / interpreter will not interfere with any type checks. You are free to perform any operations on any kind of data.
- The resulting code is usually more efficient.
- Transparent instructions. With knowledge of the language, there is usually no doubt that this or that code is of itself.
disadvantages
- Complexity. Often there is a need to represent complex values, such as lists, strings or structures. This can cause inconvenience.
- Lack of checks. Any meaningless actions, such as subtracting a pointer to an array from a character, will be considered perfectly normal, which is fraught with subtle errors.
- Low level of abstraction. Working with any complex data type is no different from working with numbers, which of course will create a lot of difficulties.
Strong typeless typing?
, . ( 86/86-64, ) , cx (16 ) rax (64 ).
mov cx, eax ;
, - ? , . , , .

, (static) (dynamic) , , .
, ( , ). , β , ? ? , , ?
.
- β . , , ( , ).
- . , .
- , .
- IDE ( , ).
- β ( , ).
- ( , , ).
- β , .

, β . β ( ) β , .
? 3- : .
β . , ( ) , , β (-1).
(Python):def find( required_element, list ):
for (index, element) in enumerate(list):
if element == required_element:
return index
return (-1)
, , , , . . β - !
():unsigned int find_int( int required_element, int array[], unsigned int size ) {
for (unsigned int i = 0; i < size; ++i )
if (required_element == array[i])
return i;
return (-1);
}
unsigned int find_float( float required_element, float array[], unsigned int size ) {
for (unsigned int i = 0; i < size; ++i )
if (required_element == array[i])
return i;
return (-1);
}
unsigned int find_char( char required_element, char array[], unsigned int size ) {
for (unsigned int i = 0; i < size; ++i )
if (required_element == array[i])
return i;
return (-1);
}
, Python, ? ?
, . , . C++ . :
( , C++):template <class T>
unsigned int find( T required_element, std::vector<T> array ) {
for (unsigned int i = 0; i < array.size(); ++i )
if (required_element == array[i])
return i;
return (-1);
}
! Python . , 3-, !
, β .
, , . - ( Haskell). - ( ), () .
, , :
- C# - dynamic.
- F# ?, .
- Haskell β Data.Dynamic.
- Delphi β Variant.
, :
- Common Lisp β .
- Perl β 5.6, .
, ?

. Β« Β». β strong typing.
, , , . Β« Β». β weak typing.
, . .
, . , , . !
. , , , , , «» ? β , ! (, )
- ? , , , , .
?
- β , .
- β , , , , .
- β -, , , , - -.
- β , . , .
, , ! ?
.
,
β¦ . Β« Β» ?
, . β . β ( , , , -, , ).
. 3.5 β ( β ? ? ? ?).
β , . .
, PL/I . ! !
, . ? , Pascal , . C#, Groovy Common Lisp.
, , . , .
Haskell.
, .
pi + 1
,
pi + 1.0
pi + float(1)
.
pi + 1
!
Haskell, , 1 . , , . !
sum x y
, x y ( 1), β sum , sum , sum , sum sum .
, .
, , . , ( Haskell, Java, C#, Python), ( C, JavaScript, Lua, PHP).
, ?

, , . β explicit typing.
, , . β implicit typing.
- , , β , , .
, , ?
- (
int add(int, int)
) , . - , , .
- β
def add(x, y)
, int add( int x, int y)
. - . - , , .
, , ( - ?), !
-
, - . . β Haskell, , :
add (x, y) = x + y
add :: (Integer, Integer) -> Integer
add (x, y) = x + y
: ,
add :: (Num a) => a -> a -> a
*, .. , Haskell'.
*
int_index .
. , . 18 , !
, Haskell, . ( )
- -?
.
-
C++, C++11 ( C++0x), auto, , :
:
unsigned int a = 5;
unsigned int b = a + 3;
unsigned int a = 5;
auto b = a + 3;
. . ( , , , ):
std::vector<int> vec = randomVector( 30 );
for ( std::vector::const_iterator it = vec.cbegin(); ... ) {
...
}
auto vec = randomVector<int>( 30 );
for ( auto it = vec.cbegin(); ... ) {
...
}
! . , - Haskell, ?
, decltype auto:
int divide( int x, int y ) {
...
}
auto divide( int x, int y ) -> decltype(x / y) {
...
}
, , (templates / generics) .
ββ.
JavaScript - | |
Ruby - | |
Python - | |
Java - | |
PHP - | |
C - | |
C++ - | |
Perl - | |
Objective-C - | |
C# - | |
Haskell - | |
Common Lisp - | |
D - | |
Delphi - | |
( C#
qxfusion):
- C# β , - dynamic 4.0. dynamic var.
- ++ β C++11 auto decltype. , Boost (boost::any, boost::variant). .
- Common Lisp β , .
- D β .
- Delphi β Variant.
- , CL, PHP Obj-C, - β .
. , . ? ? ? , .
!
::