Here are some examples of static and dynamic processing:
All languages include some kind of syntax error checking in static processing. For example, in Python it's an error to say
2 print) 17.$because this doesn't even make sense!
All languages keep track of the values of variables as part of dynamic processing. Some languages, such as Java and Ruby, keep track of the type of each value. Others, such as C, do not.
C/C++: static processing is compile errors such as not allowing an
intto be passed to
char *. You see dynamic processing in action when you accidentally pass a
strlenand the program crashes. C++ also has extra type-related dynamic processing features such as "run time type information" (RTTI), which lets you find out limited information about a value at runtime, and
dynamic_cast, which lets you tell the compiler that a value is a more specific type than it can infer (that's static processing), but you might get back a null pointer at runtime (that's dynamic processing).
// Either "Hello, John" or "Hello, John Smith" var field = polite ? "fullName" : "firstName"; return "Hello, " + user[field];
- Java: Like C/C++, static checking includes compile errors when you try to pass an
intto a function that wants a
String. It also goes beyond that with generics - so it's an error to pass an
List<User>is wanted. Java also has a lot of dynamic checking: you can find out the exact type of an object at runtime, as well as the names and types of its methods and fields.