Like many areas
of defining type systems, there are different levels of dynamic typing. Some languages
allow you to specify types where you want to??”possibly still treating them dynamically
apart from assignment??”but let you use untyped variables elsewhere.
EXPLICIT TYPING VS. IMPLICIT TYPING
The distinction between explicit typing and implicit typing is only relevant in statically typed
languages. With explicit typing, the type of every variable must be explicitly stated in the
declaration. Implicit typing allows the compiler to infer the type of the variable based
on its use. For example, the language could dictate that the type of the variable is the
type of the expression used to assign the initial value.
Consider a hypothetical language that uses the keyword var to indicate type inference.
7 Table 2.2 shows how code in such a language could be written in C# 1. The
code in the left column is not allowed in C# 1, but the code in the right column is the
equivalent valid code.
6 This applies to most expressions too, but not quite all of them. There are certain expressions which don??™t have
a type, such as void method invocations, but this doesn??™t affect C#??™s status of being statically typed. I??™ve used the
word variable throughout this section to avoid unnecessary brain strain.
7 OK, not so hypothetical. See section 8.2 for C# 3??™s implicitly typed local variable capabilities.
Pages:
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116