Cannabis Indica

Content deleted Content added
4.30.129.162 (talk)
"5"+6 compiles in c, because "5" (of type char[2]) is converted to char*, and char*+int is defined
mNo edit summary
Line 2: Line 2:


== History ==
== History ==

In 1974, Liskov and Zilles described a strong-typed language as one in which "whenever an object is passed from a calling function to a called function, its type must be compatible with the type declared in the called function."<ref>{{cite paper | id = {{citeseerx|10.1.1.136.3043}} | title = Programming with abstract data types | first1 = B | last1 = Liskov | first2 = S | last2 = Zilles | journal = ACM Sigplan Notices | year = 1974 }}</ref>
In 1974, Liskov and Zilles described a strong-typed language as one in which "whenever an object is passed from a calling function to a called function, its type must be compatible with the type declared in the called function."<ref>{{cite paper | id = {{citeseerx|10.1.1.136.3043}} | title = Programming with abstract data types | first1 = B | last1 = Liskov | first2 = S | last2 = Zilles | journal = ACM Sigplan Notices | year = 1974 }}</ref>
Jackson wrote, "In a strongly typed language each data area will have a distinct type and each process will state its communication requirements in terms of these types."<ref>{{cite journal | title = Parallel processing and modular software construction | first1 = K. | last1 = Jackson | journal = Lecture Notes in Computer Science | year = 1977 | volume = 54 | pages = 436–443 | doi = 10.1007/BFb0021435 | url = http://www.springerlink.com/content/wq02703237400667/ | series = Lecture Notes in Computer Science | isbn = 3-540-08360-X }}</ref>
Jackson wrote, "In a strongly typed language each data area will have a distinct type and each process will state its communication requirements in terms of these types."<ref>{{cite journal | title = Parallel processing and modular software construction | first1 = K. | last1 = Jackson | journal = Lecture Notes in Computer Science | year = 1977 | volume = 54 | pages = 436–443 | doi = 10.1007/BFb0021435 | url = http://www.springerlink.com/content/wq02703237400667/ | series = Lecture Notes in Computer Science | isbn = 3-540-08360-X }}</ref>


== Definitions of "strong" or "weak" ==
== Definitions of "strong" or "weak" ==

A number of different language design decisions have been referred to as evidence of "strong" or "weak" typing. In fact, many of these are more accurately understood as the presence or absence of [[type safety]], [[memory safety]], [[Type system#Static type-checking|static type-checking]], or [[Type system#Dynamic type-checking and runtime type information|dynamic type-checking]].
A number of different language design decisions have been referred to as evidence of "strong" or "weak" typing. In fact, many of these are more accurately understood as the presence or absence of [[type safety]], [[memory safety]], [[Type system#Static type-checking|static type-checking]], or [[Type system#Dynamic type-checking and runtime type information|dynamic type-checking]].


=== Implicit type conversions and "type punning" ===
=== Implicit type conversions and "type punning" ===

Some programming languages make it easy to use a value of one type as if it were a value of another type. This is sometimes described as "weak typing".
Some programming languages make it easy to use a value of one type as if it were a value of another type. This is sometimes described as "weak typing".


For example, Aahz Maruch writes that "''[[type conversion|Coercion]] occurs when you have a [[statically typed]] language and you use the syntactic features of the language to force the usage of one type as if it were a different type (consider the common use of void* in C). Coercion is usually a symptom of weak typing. Conversion, OTOH, creates a brand-new object of the appropriate type.''" <ref name="artima">[http://www.artima.com/weblogs/viewpost.jsp?thread=7590 Typing: Strong vs. Weak, Static vs. Dynamic]{{verify credibility|date=October 2012}}</ref>
For example, Aahz Maruch writes that "''[[type conversion|Coercion]] occurs when you have a [[statically typed]] language and you use the syntactic features of the language to force the usage of one type as if it were a different type (consider the common use of void* in C). Coercion is usually a symptom of weak typing. Conversion, OTOH, creates a brand-new object of the appropriate type.''" <ref name="artima">[http://www.artima.com/weblogs/viewpost.jsp?thread=7590 Typing: Strong vs. Weak, Static vs. Dynamic]{{verify credibility|date=October 2012}}</ref>


As another example, GCC describes this as ''[[type punning|type-punning]]'' and warns that it will ''break strict [[Aliasing_(computing)|aliasing]]''. [[Thiago Macieira]] discusses several problems that can arise when type-punning causes the [[compiler]] to make inappropriate [[optimization]]s.<ref>[http://blog.qt.digia.com/blog/2011/06/10/type-punning-and-strict-aliasing/ Type-punning and strict-aliasing, Thiago Macieira]</ref>
As another example, GCC describes this as ''[[type punning|type-punning]]'' and warns that it will ''break strict [[Aliasing (computing)|aliasing]]''. [[Thiago Macieira]] discusses several problems that can arise when type-punning causes the [[compiler]] to make inappropriate [[optimization]]s.<ref>[http://blog.qt.digia.com/blog/2011/06/10/type-punning-and-strict-aliasing/ Type-punning and strict-aliasing, Thiago Macieira]</ref>


It is easy to focus on the syntax, but Macieira's argument is really about semantics. There are many examples of languages which allow [[implicit type conversion|implicit conversions]], but in a type-safe manner. For example, both C++ and C# allow programs to define operators to convert a value from one type to another in a semantically meaningful way. When a C++ compiler encounters such a conversion, it treats the operation just like a function call. In contrast, converting a value to the C type "void*" is an unsafe operation which is invisible to the compiler.
It is easy to focus on the syntax, but Macieira's argument is really about semantics. There are many examples of languages which allow [[implicit type conversion|implicit conversions]], but in a type-safe manner. For example, both C++ and C# allow programs to define operators to convert a value from one type to another in a semantically meaningful way. When a C++ compiler encounters such a conversion, it treats the operation just like a function call. In contrast, converting a value to the C type "void*" is an unsafe operation which is invisible to the compiler.


=== Pointers ===
=== Pointers ===

Some programming languages expose pointers as if they were numeric values, and allow users to perform arithmetic on them. These languages are sometimes referred to as "weakly typed", since pointer arithmetic can be used to bypass the language's type system.
Some programming languages expose pointers as if they were numeric values, and allow users to perform arithmetic on them. These languages are sometimes referred to as "weakly typed", since pointer arithmetic can be used to bypass the language's type system.


=== Untagged unions ===
=== Untagged unions ===
Some programming languages support [[Union type#C++|untagged unions]], which allow a value of one type to be viewed as if it were a value of another type. In the article titled ''A hacked Boolean'', Bill McCarthy demonstrates how a [[Boolean data type|Boolean]] value in [[.NET Framework|.NET]] programming may become internally corrupted so that two values may both be "true" and yet still be considered unequal to each other.<ref>[http://msmvps.com/blogs/bill/archive/2004/06/23/8730.aspx A hacked Boolean]</ref>

Some programming languages support [[Union_type#C++|untagged unions]], which allow a value of one type to be viewed as if it were a value of another type. In the article titled ''A hacked Boolean'', Bill McCarthy demonstrates how a [[Boolean data type|Boolean]] value in [[.NET Framework|.NET]] programming may become internally corrupted so that two values may both be "true" and yet still be considered unequal to each other.<ref>[http://msmvps.com/blogs/bill/archive/2004/06/23/8730.aspx A hacked Boolean]</ref>


=== Dynamic type-checking ===
=== Dynamic type-checking ===

Some programming languages do not have static type-checking. In many such languages, it is easy to write programs which would be rejected by most static type-checkers. For example, a variable might store either a number or the Boolean value "false". Some programmers refer to these languages as "weakly typed", since they do not ''seem ''to enforce the "strong" type discipline found in a language with a static type-checker.
Some programming languages do not have static type-checking. In many such languages, it is easy to write programs which would be rejected by most static type-checkers. For example, a variable might store either a number or the Boolean value "false". Some programmers refer to these languages as "weakly typed", since they do not ''seem ''to enforce the "strong" type discipline found in a language with a static type-checker.


=== Static type-checking ===
=== Static type-checking ===

In [[Luca Cardelli]]'s article [[typeful programming|Typeful Programming]],<ref>ftp://gatekeeper.research.compaq.com/pub/DEC/SRC/research-reports/SRC-045.pdf page 3</ref> a "strong type system" is described as one in which there is no possibility of an unchecked runtime type error. In other writing, the absence of unchecked run-time errors is referred to as ''safety'' or ''type safety''; [[C. A. R. Hoare|Tony Hoare]]'s early papers call this property ''security''.
In [[Luca Cardelli]]'s article [[typeful programming|Typeful Programming]],<ref>ftp://gatekeeper.research.compaq.com/pub/DEC/SRC/research-reports/SRC-045.pdf page 3</ref> a "strong type system" is described as one in which there is no possibility of an unchecked runtime type error. In other writing, the absence of unchecked run-time errors is referred to as ''safety'' or ''type safety''; [[C. A. R. Hoare|Tony Hoare]]'s early papers call this property ''security''.


=== Predictability ===
=== Predictability ===

Some programmers refer to a language as "weakly typed" if simple operations do not behave in a way that they would expect. For example, consider the following program:
Some programmers refer to a language as "weakly typed" if simple operations do not behave in a way that they would expect. For example, consider the following program:


Line 45: Line 37:


Different languages will assign a different value to 'x':
Different languages will assign a different value to 'x':

* One language might convert 6 to a string, and concatenate the two arguments to produce the string "56" (e.g. [[JavaScript]], [[Java (programming language)|Java]])
* One language might convert 6 to a string, and concatenate the two arguments to produce the string "56" (e.g. [[JavaScript]], [[Java (programming language)|Java]])
* Another language might convert "5" to a number, and add the two arguments to produce the number 11 (e.g. [[Perl]], [[PHP]])
* Another language might convert "5" to a number, and add the two arguments to produce the number 11 (e.g. [[Perl]], [[PHP]])
* Yet another language might convert the string "5" to a pointer representing where the string is stored within memory, and add 6 to that value to produce a semi-random address (e.g. [[C_(programming_language)|C]])
* Yet another language might convert the string "5" to a pointer representing where the string is stored within memory, and add 6 to that value to produce a semi-random address (e.g. [[C (programming language)|C]])
* And yet another language might simply fail to compile this program or run the code, saying that the two operands have incompatible type (e.g. [[Python_(programming_language)|Python]], [[BASIC_(programming_language)|BASIC]])
* And yet another language might simply fail to compile this program or run the code, saying that the two operands have incompatible type (e.g. [[Python (programming language)|Python]], [[BASIC (programming language)|BASIC]])


Languages that work like the first three examples have all been called "weakly typed" at various times, even though only one of them (the third) represents a safety violation.
Languages that work like the first three examples have all been called "weakly typed" at various times, even though only one of them (the third) represents a safety violation.


=== Type inference ===
=== Type inference ===

Languages with static type systems differ to the extent that users are required to manually state the types used in their program. Some languages, such as C, require that every variable be declared with a type. Other languages, such as [[Haskell (programming language)|Haskell]], use the [[Hindley-Milner]] method to infer all types based on a global analysis. Other languages, such as C# and C++, lie somewhere in between; some types can be inferred based on local information, while others must be specified. Some programmers use the term weakly typed to refer to languages with type inference, often without realizing that the type information is present but implicit.
Languages with static type systems differ to the extent that users are required to manually state the types used in their program. Some languages, such as C, require that every variable be declared with a type. Other languages, such as [[Haskell (programming language)|Haskell]], use the [[Hindley-Milner]] method to infer all types based on a global analysis. Other languages, such as C# and C++, lie somewhere in between; some types can be inferred based on local information, while others must be specified. Some programmers use the term weakly typed to refer to languages with type inference, often without realizing that the type information is present but implicit.


== Variation across programming languages ==
== Variation across programming languages ==

Note that some of these definitions are contradictory, others are merely orthogonal, and still others are special cases (with additional constraints) of other, more "liberal" (less strong) definitions. Because of the wide divergence among these definitions, it is possible to defend claims about most programming languages that they are either strongly or weakly typed. For instance:
Note that some of these definitions are contradictory, others are merely orthogonal, and still others are special cases (with additional constraints) of other, more "liberal" (less strong) definitions. Because of the wide divergence among these definitions, it is possible to defend claims about most programming languages that they are either strongly or weakly typed. For instance:
* [[Java (programming language)|Java]], [[Pascal (programming language)|Pascal]], [[Ada (programming language)|Ada]] and [[C (programming language)|C]] require all [[Variable (programming)|variables]] to have a declared type, and support the use of explicit casts of arithmetic values to other arithmetic types. Java, C#, Ada and Pascal are sometimes said to be more strongly typed than C, a claim that is probably based on the fact that C supports more kinds of implicit conversions, and C also allows [[pointer (computer programming)|pointer]] values to be explicitly cast while Java and Pascal do not. Java itself may be considered more strongly typed than Pascal as manners of evading the static type system in Java are controlled by the Java [[Virtual machine|Virtual Machine's]] type system. C# is similar to Java in that respect, though it allows disabling dynamic type checking by explicitly putting code segments in an "unsafe context". Pascal's type system has been described as "too strong", because the size of an array or string is part of its type, making some programming tasks very difficult.<ref>[http://books.google.co.uk/books?id=7i8EAAAAMBAJ&pg=PA66&lpg=PA66&dq=pascal+type+system+%22too+strong%22&source=bl&ots=PGyKS1fWUb&sig=ebFI6fk_yxwyY4b7sHSklp048Q4&hl=en&ei=lSmjTunuBo6F8gPOu43CCA&sa=X&oi=book_result&ct=result&resnum=1&ved=0CBsQ6AEwAA#v=onepage&q=pascal%20type%20system%20%22too%20strong%22&f=false Infoworld April 25, 1983]</ref><ref>[http://www.cs.virginia.edu/~cs655/readings/bwk-on-pascal.html [[Brian Kernighan]: ''Why Pascal is not my favourite language'']</ref>

* The object-oriented programming languages [[Smalltalk]], [[Ruby (programming language)|Ruby]], [[Python (programming language)|Python]], and [[Self (programming language)|Self]] are all "strongly typed" in the sense that typing errors are prevented at runtime and they do little implicit [[type conversion]], but these languages make no use of static type checking: the compiler does not check or enforce type constraint rules. The term [[duck typing]] is now used to describe the [[dynamic typing]] paradigm used by the languages in this group.
*[[Java (programming language)|Java]], [[Pascal (programming language)|Pascal]], [[Ada (programming language)|Ada]] and [[C (programming language)|C]] require all [[Variable (programming)|variables]] to have a declared type, and support the use of explicit casts of arithmetic values to other arithmetic types. Java, C#, Ada and Pascal are sometimes said to be more strongly typed than C, a claim that is probably based on the fact that C supports more kinds of implicit conversions, and C also allows [[pointer (computer programming)|pointer]] values to be explicitly cast while Java and Pascal do not. Java itself may be considered more strongly typed than Pascal as manners of evading the static type system in Java are controlled by the Java [[Virtual machine|Virtual Machine's]] type system. C# is similar to Java in that respect, though it allows disabling dynamic type checking by explicitly putting code segments in an "unsafe context". Pascal's type system has been described as "too strong", because the size of an array or string is part of its type, making some programming tasks very difficult.<ref>[http://books.google.co.uk/books?id=7i8EAAAAMBAJ&pg=PA66&lpg=PA66&dq=pascal+type+system+%22too+strong%22&source=bl&ots=PGyKS1fWUb&sig=ebFI6fk_yxwyY4b7sHSklp048Q4&hl=en&ei=lSmjTunuBo6F8gPOu43CCA&sa=X&oi=book_result&ct=result&resnum=1&ved=0CBsQ6AEwAA#v=onepage&q=pascal%20type%20system%20%22too%20strong%22&f=false Infoworld April 25, 1983]</ref><ref>[http://www.cs.virginia.edu/~cs655/readings/bwk-on-pascal.html [[Brian Kernighan]]: ''Why Pascal is not my favourite language'']</ref>
*The object-oriented programming languages [[Smalltalk]], [[Ruby (programming language)|Ruby]], [[Python (programming language)|Python]], and [[Self (programming language)|Self]] are all "strongly typed" in the sense that typing errors are prevented at runtime and they do little implicit [[type conversion]], but these languages make no use of static type checking: the compiler does not check or enforce type constraint rules. The term [[duck typing]] is now used to describe the [[dynamic typing]] paradigm used by the languages in this group.
* The [[Lisp (programming language)|Lisp]] family of languages are all "strongly typed" in the sense that typing errors are prevented at runtime. Some Lisp dialects like [[Common Lisp]] or [[Clojure]] do support various forms of type declarations<ref>[http://www.lispworks.com/documentation/HyperSpec/Body/04_.htm Common Lisp HyperSpec, Types and Classes]</ref> and some compilers ([[CMUCL]]<ref>[http://common-lisp.net/project/cmucl/doc/cmu-user/compiler.html#toc123 CMUCL User's Manual: The Compiler, Types in Python]</ref> and related) use these declarations together with [[type inference]] to enable various optimizations and also limited forms of compile time type checks.
* [[Standard ML]], [[F Sharp (programming language)|F#]], [[OCaml]] and [[Haskell (programming language)|Haskell]] are statically type checked but the compiler automatically infers a precise type for all values. These languages (along with most [[Functional programming|functional]] languages) are considered to have stronger type systems than Java, as they permit no implicit type conversions. While OCaml's libraries allow one form of evasion (''Object magic''), this feature remains unused in most applications.
*The [[Lisp (programming language)|Lisp]] family of languages are all "strongly typed" in the sense that typing errors are prevented at runtime. Some Lisp dialects like [[Common Lisp]] or [[Clojure]] do support various forms of type declarations<ref>[http://www.lispworks.com/documentation/HyperSpec/Body/04_.htm Common Lisp HyperSpec, Types and Classes]</ref> and some compilers ([[CMUCL]]<ref>[http://common-lisp.net/project/cmucl/doc/cmu-user/compiler.html#toc123 CMUCL User's Manual: The Compiler, Types in Python]</ref> and related) use these declarations together with [[type inference]] to enable various optimizations and also limited forms of compile time type checks.
* [[Visual Basic]] is a hybrid language. In addition to variables with declared types, it is also possible to declare a variable of "Variant" data type that can store data of any type. Its implicit casts are fairly liberal where, for example, one can sum string variants and pass the result into an integer variable.
*[[Standard ML]], [[F Sharp (programming language)|F#]], [[OCaml]] and [[Haskell (programming language)|Haskell]] are statically type checked but the compiler automatically infers a precise type for all values. These languages (along with most [[Functional programming|functional]] languages) are considered to have stronger type systems than Java, as they permit no implicit type conversions. While OCaml's libraries allow one form of evasion (''Object magic''), this feature remains unused in most applications.
* [[Assembly language]] and [[Forth (programming language)|Forth]] have been said to be ''untyped''. There is no type checking; it is up to the programmer to ensure that data given to functions is of the appropriate type. Any type conversion required is explicit.
*[[Visual Basic]] is a hybrid language. In addition to variables with declared types, it is also possible to declare a variable of "Variant" data type that can store data of any type. Its implicit casts are fairly liberal where, for example, one can sum string variants and pass the result into an integer variable.
*[[Assembly language]] and [[Forth (programming language)|Forth]] have been said to be ''untyped''. There is no type checking; it is up to the programmer to ensure that data given to functions is of the appropriate type. Any type conversion required is explicit.
<!-- Please do not grow this list without bound. These examples are intended to illustrate the ambiguity of the term -- NOT to advocate a particular language. Unless a language shows a DIFFERENT sort of ambiguity, please don't add it. For instance, Python is much the same as Lisp. -->
<!-- Please do not grow this list without bound. These examples are intended to illustrate the ambiguity of the term -- NOT to advocate a particular language. Unless a language shows a DIFFERENT sort of ambiguity, please don't add it. For instance, Python is much the same as Lisp. -->


Line 72: Line 60:


== See also ==
== See also ==
*[[Data type]] includes a more thorough discussion of typing issues
* [[Data type]] includes a more thorough discussion of typing issues
*[[Comparison of programming languages]]
* [[Comparison of programming languages]]
*[[Type system]]
* [[Type system]]
*[[Type safety]]
* [[Type safety]]
*[[Memory safety]]
* [[Memory safety]]


== References ==
== References ==

Revision as of 14:00, 9 April 2014

In computer programming, programming languages are often colloquially referred to as strongly typed or weakly typed. In general, these terms do not have a precise definition. Rather, they tend to be used by advocates or critics of a given programming language, as a means of explaining why a given language is better or worse than alternatives.

History

In 1974, Liskov and Zilles described a strong-typed language as one in which "whenever an object is passed from a calling function to a called function, its type must be compatible with the type declared in the called function."[1] Jackson wrote, "In a strongly typed language each data area will have a distinct type and each process will state its communication requirements in terms of these types."[2]

Definitions of "strong" or "weak"

A number of different language design decisions have been referred to as evidence of "strong" or "weak" typing. In fact, many of these are more accurately understood as the presence or absence of type safety, memory safety, static type-checking, or dynamic type-checking.

Implicit type conversions and "type punning"

Some programming languages make it easy to use a value of one type as if it were a value of another type. This is sometimes described as "weak typing".

For example, Aahz Maruch writes that "Coercion occurs when you have a statically typed language and you use the syntactic features of the language to force the usage of one type as if it were a different type (consider the common use of void* in C). Coercion is usually a symptom of weak typing. Conversion, OTOH, creates a brand-new object of the appropriate type." [3]

As another example, GCC describes this as type-punning and warns that it will break strict aliasing. Thiago Macieira discusses several problems that can arise when type-punning causes the compiler to make inappropriate optimizations.[4]

It is easy to focus on the syntax, but Macieira's argument is really about semantics. There are many examples of languages which allow implicit conversions, but in a type-safe manner. For example, both C++ and C# allow programs to define operators to convert a value from one type to another in a semantically meaningful way. When a C++ compiler encounters such a conversion, it treats the operation just like a function call. In contrast, converting a value to the C type "void*" is an unsafe operation which is invisible to the compiler.

Pointers

Some programming languages expose pointers as if they were numeric values, and allow users to perform arithmetic on them. These languages are sometimes referred to as "weakly typed", since pointer arithmetic can be used to bypass the language's type system.

Untagged unions

Some programming languages support untagged unions, which allow a value of one type to be viewed as if it were a value of another type. In the article titled A hacked Boolean, Bill McCarthy demonstrates how a Boolean value in .NET programming may become internally corrupted so that two values may both be "true" and yet still be considered unequal to each other.[5]

Dynamic type-checking

Some programming languages do not have static type-checking. In many such languages, it is easy to write programs which would be rejected by most static type-checkers. For example, a variable might store either a number or the Boolean value "false". Some programmers refer to these languages as "weakly typed", since they do not seem to enforce the "strong" type discipline found in a language with a static type-checker.

Static type-checking

In Luca Cardelli's article Typeful Programming,[6] a "strong type system" is described as one in which there is no possibility of an unchecked runtime type error. In other writing, the absence of unchecked run-time errors is referred to as safety or type safety; Tony Hoare's early papers call this property security.

Predictability

Some programmers refer to a language as "weakly typed" if simple operations do not behave in a way that they would expect. For example, consider the following program:

x = "5" + 6

Different languages will assign a different value to 'x':

  • One language might convert 6 to a string, and concatenate the two arguments to produce the string "56" (e.g. JavaScript, Java)
  • Another language might convert "5" to a number, and add the two arguments to produce the number 11 (e.g. Perl, PHP)
  • Yet another language might convert the string "5" to a pointer representing where the string is stored within memory, and add 6 to that value to produce a semi-random address (e.g. C)
  • And yet another language might simply fail to compile this program or run the code, saying that the two operands have incompatible type (e.g. Python, BASIC)

Languages that work like the first three examples have all been called "weakly typed" at various times, even though only one of them (the third) represents a safety violation.

Type inference

Languages with static type systems differ to the extent that users are required to manually state the types used in their program. Some languages, such as C, require that every variable be declared with a type. Other languages, such as Haskell, use the Hindley-Milner method to infer all types based on a global analysis. Other languages, such as C# and C++, lie somewhere in between; some types can be inferred based on local information, while others must be specified. Some programmers use the term weakly typed to refer to languages with type inference, often without realizing that the type information is present but implicit.

Variation across programming languages

Note that some of these definitions are contradictory, others are merely orthogonal, and still others are special cases (with additional constraints) of other, more "liberal" (less strong) definitions. Because of the wide divergence among these definitions, it is possible to defend claims about most programming languages that they are either strongly or weakly typed. For instance:

  • Java, Pascal, Ada and C require all variables to have a declared type, and support the use of explicit casts of arithmetic values to other arithmetic types. Java, C#, Ada and Pascal are sometimes said to be more strongly typed than C, a claim that is probably based on the fact that C supports more kinds of implicit conversions, and C also allows pointer values to be explicitly cast while Java and Pascal do not. Java itself may be considered more strongly typed than Pascal as manners of evading the static type system in Java are controlled by the Java Virtual Machine's type system. C# is similar to Java in that respect, though it allows disabling dynamic type checking by explicitly putting code segments in an "unsafe context". Pascal's type system has been described as "too strong", because the size of an array or string is part of its type, making some programming tasks very difficult.[7][8]
  • The object-oriented programming languages Smalltalk, Ruby, Python, and Self are all "strongly typed" in the sense that typing errors are prevented at runtime and they do little implicit type conversion, but these languages make no use of static type checking: the compiler does not check or enforce type constraint rules. The term duck typing is now used to describe the dynamic typing paradigm used by the languages in this group.
  • The Lisp family of languages are all "strongly typed" in the sense that typing errors are prevented at runtime. Some Lisp dialects like Common Lisp or Clojure do support various forms of type declarations[9] and some compilers (CMUCL[10] and related) use these declarations together with type inference to enable various optimizations and also limited forms of compile time type checks.
  • Standard ML, F#, OCaml and Haskell are statically type checked but the compiler automatically infers a precise type for all values. These languages (along with most functional languages) are considered to have stronger type systems than Java, as they permit no implicit type conversions. While OCaml's libraries allow one form of evasion (Object magic), this feature remains unused in most applications.
  • Visual Basic is a hybrid language. In addition to variables with declared types, it is also possible to declare a variable of "Variant" data type that can store data of any type. Its implicit casts are fairly liberal where, for example, one can sum string variants and pass the result into an integer variable.
  • Assembly language and Forth have been said to be untyped. There is no type checking; it is up to the programmer to ensure that data given to functions is of the appropriate type. Any type conversion required is explicit.

For this reason, writers who wish to write unambiguously about type systems often eschew the term "strong typing" in favor of specific expressions such as "type safety".

See also

References

Leave a Reply