Braintique.com header
Left Navigation Bar

Understanding Strong Typing

Why would a development environment bother with strong typing, anyway, since it seems to be such a bother?

When working in a strongly typed environment, the programmer needs to be very clear about the type of information that will be stored in a variable. Strong typing enforces good programming discipline and clarity on the part of the programmer about the contents of variables. It also prevents bugs that can occur when a weakly typed compiler “makes a mistake” about the kind of value in a type—and incorrectly converts it.

To put this another way, weak typing allows a programmer to be lazy—by not clearly thinking about the types of variables, and not specifying the appropriate conversion if there is any possible doubt. In this scenario, the compiler “guesses” what the programmer meant, most of the time correctly, but sometimes introducing errors.

The trade-off for the benefit of extra accuracy introduced by strong typing is more work for the programmer. Of course, you must explicitly declare all variables (a good practice even in weakly typed environments). In addition, you must pay close attention every time your code converts a value of one type to another—in many cases providing explicit conversion guidance to the compiler using casting or a conversion method.

Explicit conversion, discussed in detail in the second part of this article, is achieved using the cast operator, which is the name of the type being converted to inside parentheses placed before the expression being converted. Here’s an example that uses casting to explicitly convert the long variable L to an integer variable I:

int I = (int) L;

Previous Table of Contents Next


Google
 
Web www.braintique.com
www.digitalfieldguide.com www.googleplexblog.com


Home | Barticles | Blogs | Books | Services | FAQ | Contact

© Braintique.com. All rights reserved.

Search Engine Optimization







RSS 2.0 Syndication feed

Syndication Viewer

Our Web host:
IX WebHosting



Food for Your Brain! Get a Barticle! Questions Answered Books for You What We Can Do For You Contact Us Brain Food Questions Answered Books for You What We Can Do For You Frequently Asked Questions About Us Google Research Photoshop Wi-Fi and Wireless Networking The Natural Way to Write