Is ruby strongly or weakly typed?

后端 未结 7 1362
Happy的楠姐
Happy的楠姐 2020-12-14 01:10

Is ruby strongly or weakly typed ?

Presumably the same is true for Javascript.

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-14 01:57

    I just stumbled-on this old thread but thought it proper that I could offer my opinion. (No, I'm not "hijacking" a zombie-thread.)

    My colloquial interpretation of the term "strongly typed™" specifically refers to "compile time." (Which is something that many languages today, including Ruby, "simply do not have.")

    For instance, a simple assignment statement such as a = b; could be judged by the compiler to be acceptable or not, based on its assessment of the "types" of a and b, and based on provisions for type-conversion (if applicable) provided by the programmers. If the statement was judged unacceptable, a compile-time error would be thrown and no "executable" would ever be produced.

    This notion, of course, is not compatible with the fundamental design precepts of languages such as Ruby, PHP, Perl, JavaScript, or a great many other languages that are in extremely-wide (and, extremely-successful) use today. (Mind you, I do not mean this as a "judgment" either for or against them. They are what they are, and they sure do bring home the bacon.)

    Because these languages do not have a "compile time," to my(!) colloquialism they cannot be called, "strongly typed." They are obliged to make decisions at runtime which, by their design, could not have been made sooner.


    (Also please note that I am specifically excluding from consideration the various "lint tools" that have emerged for this-or-that language in an effort to catch more bugs in advance. These are very useful, yes yes, but not the same thing.)

    (I am also purposely excluding various excellent(!) tools that generate source-code in the various target-languages in question ... for the same reasons.)

    And – I say once again – I am making a classification, not a judgment.

提交回复
热议问题