What are the key aspects of a strongly typed language?

前端 未结 8 2057
后悔当初
后悔当初 2020-12-09 17:26

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, b

相关标签:
8条回答
  • 2020-12-09 17:51

    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 :-(

    0 讨论(0)
  • 2020-12-09 17:51

    Strongly typed means you declare your variables of a certain type, and your compiler will throw a hissy fit if you try to convert that variable to another type without casting it.

    Example (in java mind you):

    int i = 4;
    char s = i; // Type mismatch: cannot convert from int to char
    
    0 讨论(0)
提交回复
热议问题