Scala 严格类型系统与 C++类型系统
对于 Scala 严格类型系统的粉丝,以及 C++ 的粉丝:
- 是否可以强迫自己以同样严格的方式进行 C++ 编程? (不使用
void*
,不进行大量转换,装箱简单值类型,即struct Month {int value;};
)。 - 或者默认情况下 C++ 比 Scala 更严格(如果您不努力使用强制转换)?尽管 C++ 模板是“鸭子类型”——如果它不适合,它仍然不会让你编译,对吧?
- 对于那些愿意接受完全类型安全编程的人来说,C++0x(适用于 C++03)是否会添加一些东西?
For fans of Scala's strict type system, but fans of C++:
- Is it possible to force yourself to program C++ with the same strictness? (not using
void*
, not casting a lot, boxing simple value type iestruct Month {int value;};
). - Or is C++ by default even stricter then Scala (if you do not try hard with casts)? Despite the "duck typing" of C++ templates -- it still won't let you compile if it doesn't fit, right?
- Does C++0x (wrt to C++03) add something for someone who is willing to submit oneself to totally typesafe programming?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简短的回答:是的,您可以达到相同级别的类型安全性,但这会给程序员带来负担。这不仅仅是提供相同安全性的问题,类型系统还必须足够强大和灵活,以促进类型安全编程,在这方面,Scala 类型系统优于 C++。
C++0x 将添加 lambda 表达式,这将有助于使用 HOF,例如 map、filter、flatMap 等。
Short answer: yes, you can reach the same level of type safety, but it will place a burden on the programmer. It's not simply a question of providing the same safety, the type system must also be powerful and flexible enough to facilitate typesafe programming and in this regard Scalas type system is superior to C++.
C++0x will add lambda expressions which will facilitate using HOF's like map, filter, flatMap etc.
C++ 类型系统比 Scala 更严格。
C++ type system is stricter than Scala's.