“弱类型”语言的优势
为什么编程语言想要使用弱类型而不是强类型?
Why would a programming language want to use weak typing over strong typing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
为什么编程语言想要使用弱类型而不是强类型?
Why would a programming language want to use weak typing over strong typing?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
在非常基础的层面上,它也将使初学者更容易上手。 (这可能是 PHP 成功的原因之一,无论您是否欣赏 PHP。)
也就是说,内存管理、指针等健全的操作知识的普遍侵蚀是一个令人担忧的趋势,如果只是因为您可以人不能总是站在巨人的肩膀上。 (仍然需要有人编写微代码、高性能设备驱动程序等)
At a very basic level, it'll also make it easier for beginners to pick up. (Probably one of PHP's reasons for success, irrespective of whether you appreciate PHP or not.)
That said, the general erosion of sound operational knowledge of memory management, pointers, etc. is a bit of a worrying trend, if only because you can't always stand on the shoulders of giants. (Someone still has to write microcode, high performance device drivers, etc.)
据说优势之一是开发时间。它允许程序员在编写代码时花更少的时间考虑和键入变量类型。当您不知道变量应该是什么类型时,这是否可以抵消潜在的错误增加和理解代码的困难,这本身就是一个问题。
另一个原因是它使某些类型的多态性更容易处理。给定一个接受两个参数并将它们相加的函数,无需将它们都指定为
int
甚至某些接口addable
。如果+
运算符可以处理两个参数的组合,那么它就可以工作。One advantage is supposedly in development time. It allows programmers to spend less time considering and typing out variable types when writing code. Whether or not this offsets the potential increase in mistakes and difficulty understanding the code when you don't know what type a variable is supposed to be, well, that's a question unto itself.
Another reason is that it makes certain kinds of polymorphism easier to deal with. Given a function that takes two arguments and adds them, there's no need to specify them both as
int
or even as some interfaceaddable
. If the+
operator can handle the combination of the two args, then it just works.