What are the benefits (and drawbacks) of a weakly typed language?

后端 未结 7 875
情书的邮戳
情书的邮戳 2020-12-11 00:52

I\'m a big fan of PHP and it\'s obviously a very weakly-typed language. I realize some of the benefits include the general independence of changing variable types on the fly

相关标签:
7条回答
  • 2020-12-11 01:56

    Weak and Strong are loaded terms. (Do you want to be a weak language programmer?) Dynamic and Static are better but I would imagine most people would rather be a dynamic programmer than a static one. I would call PHP a promiscuous language (Thats not a loaded term ;) )

    PHP:

    garbage_out = garbage_in * 3; // garbage_in was not initialized yet
    "hello world" + 2; // does this make sense?
    

    Allowing uninitialized variables creates very hard to find errors from misspellings. Allowing operations on unrelated types is also almost always an error that should be reported. Most interpreted dynamic languages do not allow these things for good reason. You can have dynamically typed language without allowing garbage.

    0 讨论(0)
提交回复
热议问题