Strong-typing vs weak-typing

What is a “type”, anyway?
A type is metadata about a chunk of memory that classifies the kind of data stored there. This classification usually implicitly specifies what kinds of operations may be performed on the data.
Common types include primitive types (strings and numbers), container types (lists/arrays and dictionaries/hashes), and user-defined types (classes). In Python, everything is an object, and every object has a type. In other words, functions, modules, and stack frames are also types.

Weak typing is where a language allows you to treat blocks of memory defined as one type as another (casting). Languages like C and C++, although statically typed, are weakly typed.
Languages like Perl and PHP are weakly typed because you can do things like adding numbers to strings and the language will do an implicit coercion for you.
Languages like Java, C# and Python are strongly typed – there is no way you can add a number to a string without doing an explicit conversion.
In addition, there are many large systems that have been created with dynamic type systems. Catching type errors (typos) at compile time only catches a very small proportion of errors and a strong testing strategy produces much more reliable systems irrespective of the type system in use. (source: http://wiki.answers.com/Q/What_is_strong-typing_versus_weak-typing)

Strong typing prevents mixing operations between mismatched types. In order to mix types, you must use an explicit conversion. Conversely, weak typing means that you can mix types without an explicit conversion (source: http://www.artima.com/weblogs/viewpost.jsp?thread=7590)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s