Software Engineering
programming-languages javascript dynamic-typing static-typing
Updated Wed, 07 Sep 2022 17:09:50 GMT

is JS a gradually typed language?


I was researching on statically typed and dynamically typed concepts and found out there is another type system called gradually typed.

From wikipedia

Gradual typing is a type system in which variables may be typed either at compile-time (static typing) or at run-time (dynamic typing), allowing software developers to choose either type paradigm as appropriate, from within a single language.

In particular, gradual typing uses a special type named dynamic to represent statically-unknown types and gradual typing replaces the notion of type equality with a new relation called consistency (aka. compatibility) that relates the dynamic type to every other type. The consistency relation is symmetric but not transitive

If I understand those concepts correctly, "Javascript" is a gradually typed language. Am I correct?




Solution

Mixing static and dynamic typing is still very much an open research issue with several competing approaches, including but not limited to Jeremy Siek's Gradual Typing (which you mentioned), Quasi-Static Typing, Soft Typing, Hybrid Typing (Flanagan), Optional Static Typing (championed for example by Gilad Bracha), Blame Calculus (Wadler and Findler), Coercion Calculus (Henglein), Contracts (Findler and Felleisen), Manifest Contracts (Greenberg, Pierce, and Weirich) and many more.

ECMAScript / JavaScript is not gradually typed. It would be stupid to add something that is still an open research problem to a production language such as ECMAScript. A language design committee is not the place to do cutting-edge research.

Actually, the ECMAScript committee tried to do cutting-edge research by mixing static and dynamic typing in ECMAScript 4 and that was a spectacular failure.

ECMAScript / JavaScript are dynamically typed. There are no static types, nor is there syntax for type annotations.





Comments (5)

  • +0 – > I think this is the best explained answer. I went through some of the other type systems also. Thank you for sharing those... — Jun 23, 2014 at 11:42  
  • +0 – I would say "dynamically weakly typed" or "loosely typed". Just saying "dynamically" is a (undeserved) compliment. — Jun 23, 2014 at 11:42  
  • +1 – @Den: Unfortunately, those terms are not well-defined. There are at least a dozen contradictory definitions in the wild. It just doesn't make sense to use those terms. — Jun 23, 2014 at 12:23  
  • +0 – @JörgWMittag: In a proper weakly-typed language, variables may be of any type, but the meanings of operators won't change with the types of things upon which it is invoked. In Apple's HyperTalk language (1990s), the expression (1 & 2) + 3 would concatenate "1" and "2" as strings, and then add the result as a number to 3, thus yielding 15. In a strongly-dynamically-typed language like Python, using the "+" operator on two numbers will add then, using it on two strings will concatenate them, and using it on one of each is an error. — Sep 28, 2014 at 22:55  
  • +0 – @JörgWMittag: JavaScript's behavior is worse than that of HyperTalk or Python, since it uses the "+" operator for two different purposes, but doesn't cleanly separate the cases where those purposes apply. This, 12+"X" yields "12X" and "X"+34 yields "X34", but 12+34 yields 46. — Sep 28, 2014 at 22:58  


External Links

External links referenced by this document: