Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the key aspects of a strongly typed language?

What makes a language strongly typed? I'm looking for the most important aspects of a strongly typed language.

Yesterday I asked if PowerShell was strongly typed, but no one could agree on the definition of "strongly-typed", so I'm looking to clarify the definition.

Feel free to link to wikipedia or other sources, but don't just cut and paste for your answer.

like image 735
Chris Sutton Avatar asked Sep 23 '08 14:09

Chris Sutton


2 Answers

The term "strongly typed" has no agreed-upon definition.

It makes a "great" argument in a flamewar, because whenever someone is proven wrong, they can just redefine it to mean whatever they want it to mean. Other than that, the term serves no real purpose.

It is best to just not use the term, or, if you use it, rigorously define it first. If you see someone else use it, ask him to define the term.

Everybody has their own definition. Some that I have seen are:

  • strongly typed = statically typed
  • strongly typed = explicitly typed
  • strongly typed = nominally typed
  • strongly typed = typed
  • strongly typed = has no implicit typecasts, only explicit
  • strongly typed = has no typecasts at all
  • strongly typed = what I understand / weakly typed = what I don't understand
  • strongly typed = C++ / weakly typed = everything else
  • strongly typed = Java / weakly typed = everything else
  • strongly typed = .NET / weakly typed = everything else
  • strongly typed = my programming language / weakly typed = your programming language

In Type Theory, there exists the notion of one type system being stronger than another. In particular, if there exists an expression e1 such that it is accepted by a type system T1, but rejected by a type system T2, then T2 is said to be stronger than T1. There are two important things to note here:

  1. this a comparative, not an absolute: there is no strong or weak, only stronger and weaker
  2. there is no value implied by the term; stronger does not mean better
like image 98
Jörg W Mittag Avatar answered Oct 11 '22 02:10

Jörg W Mittag


According to B.C. Pierce, the guy who wrote "Types and Programming Languages and Advanced Types and Programming Languages" :

I spent a few weeks trying to sort out the terminology of "strongly typed," "statically typed," "safe," etc., and found it amazingly difficult... The usage of these terms is so various as to render them almost useless.

So no wonder why your collegues disagree.

I'd go with the simplest answer : if you can concatenate a string and an int without casting, then it's not strongly typed.

EDIT: as stated in comments, Java just does that :-(

like image 34
e-satis Avatar answered Oct 11 '22 03:10

e-satis