generics - 为什么选择在 Dart 中输入?

标签 generics covariance dart type-systems

http://www.dartlang.org/docs/spec/dartLangSpec.pdf

Dart 的语言规范在下面提到

Dart supports optional typing based on interface types. The type system is unsound, due to the covariance of generic types. This is a deliberate choice (and undoubtedly controversial). Experience has shown that sound type rules for generics fly in the face of programmer intuition. It is ..


  • 有人可以进一步详细说明类型系统不健全的原因吗?
  • 当 Dart 语言规范的作者说泛型的健全类型规则违背直觉时,他们在想什么?
  • 最佳答案

    从吉拉德布拉查 [1]:

    You can write a tool that will scream bloody murder about these things, but what you can’t do is stop people from running their programs.



    或者,换句话说[2]:

    The problem is that expressing type flow fully and explicitly is more difficult for most programmers than writing code that passes values around and deals with runtime type errors when and if they happen. The word chosen for this difference in difficulty is that the latter is more "intuitive" than the former - I don't think it's a particularly bad choice of word. The phenomenon is one of the biggest reasons dynamic languages have become a lot more popular over recent years, a rejection of complexity in specifying static types.

    It's like there's another triangle tradeoff: expressive, sound, simple: choose any two for your type system. Almost everyone is unwilling to forgo expressiveness - the object graphs weaved in modern software can be quite tangled indeed - while any language that hopes to have large-scale success cannot start out being anything but fairly simple. So they give up some measure of (statically-typed) soundness, and expect lots of runtime type errors during debugging and testing.



    [1] http://blog.sethladd.com/2011/11/transcription-of-quick-tour-of-dart-by.html

    [2] http://lambda-the-ultimate.org/node/4377#comment-67589

    关于generics - 为什么选择在 Dart 中输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8169141/

    相关文章:

    java - 如何使用泛型避免类型安全警告

    android - 未处理的异常: '_InternalLinkedHashMap<dynamic, dynamic>'类型不是 'Map<String, dynamic>'类型的子类型吗?

    C# 派生泛型方法

    c# - 泛型允许按类型对哪些元素进行参数化?

    c# - 使用双泛型时出错

    c# - 反方差的常见编程用途是什么?

    r - 如何运行控制 R 中多个变量的多重 t 检验或方差分析?

    c++ - 绕过 C++/STL 中的容器协变

    android - Flutter AppBar标题与动画进度条重叠

    flutter - grpc-web安全在生产中如何工作?