Knowledgebase

Strong and Weak Typing Print

  • programminglanguages, programming, guide, howto, solution, zillionkinghost, hosting, support
  • 0

How strictly types are enforced.

WHAT STRONG TYPING MEANS

Types are enforced, and conversions must be explicit.

WHAT WEAK TYPING MEANS

Values are converted automatically between types.

WHY THAT MATTERS

Automatic conversion produces surprising results.

WHAT THAT LOOKS LIKE

Text and a number compared, or added, producing something unintended.

WHAT THAT CAUSES

Bugs that are difficult to trace, because nothing appears wrong.

WHAT TO DO IN WEAKLY TYPED LANGUAGES

Use strict comparison, which checks type as well as value Convert explicitly Validate input types

WHAT IS INDEPENDENT OF STATIC AND DYNAMIC

Strength. A language can be dynamically and strongly typed.

WHAT THAT MEANS

Adding text to a number fails, rather than producing something.

WHY THAT IS PREFERABLE

Failing is better than silently continuing with a wrong value.

WHAT TO ESTABLISH IN ANY LANGUAGE

Where implicit conversion happens.

WHY

That is where the surprises are.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot