C#(.NET)设计缺陷 [英] C# (.NET) Design Flaws

查看:211
本文介绍了C#(.NET)设计缺陷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是一些最大的设计缺陷,在C#或.NET Framework有什么看法?

What are some of the biggest design flaws in C# or the .NET Framework in general?

例如:有没有非空的字符串类型,你必须从IDataReader的获取值时检查的DBNull

Example: there is no non-nullable string type and you have to check for DBNull when fetching values from an IDataReader.

推荐答案

我同意用强调的这个帖子(对于那些大便,pooing缺乏的ToString,有一个调试器属性,为你的类自定义格式)。

I agree emphatically with this post (for those poo-pooing the lack of ToString, there is a debugger attribute to provide a custom format for your class).

在上面的列表的顶部,我还要补充以下合理的要求:

On top of the above list, I would also add the following reasonable requests:

  1. 在非空的引用类型为补充空值类型,
  2. 允许覆盖一个结构的空构造,
  3. 允许泛型类型的限制指定密封类,
  4. 我同意在这里的另一个海报要求任意构造特征作为约束条件,即使用时。其中,T:新的(字符串),或在T:新的(字符串,INT),
  5. 我也与其他海报同意此有关解决事件,无论是空的事件列表和同步设置(尽管后者是棘手的),
  6. 在运营商应定义为扩展方法,而不是静态方法(或不只是作为静态方法至少),
  7. 在允许的静态属性和方法接口(Java有这个,但是C#不)
  8. 允许对象初始化事件初始化(只字段和属性,目前允许的),
  9. 为什么在创建对象时是对象初始化语法仅可用?为什么不让它可在任何时间,即。变种E =新的Foo(); Ë{吧=巴兹};
  10. 修正二次枚举的行为,
  11. 在所有集合应该有不变的快照迭代(即突变的集合中的迭代器应该不坏),
  12. 元组很容易添加,而是一种有效的封闭的代数类型,如要么不是,所以我很想某种方式来声明一个封闭的代数类型和实施详尽的模式就可以匹配(基本上是为了提供一流的支持访问者模式,但更有效);所以只取枚举,用详尽的模式匹配支持扩展它们,并且不允许无效的情况下,
  13. 在我喜欢的图案,一般配套支持,但最起码​​的对象型式试验;我也有点像开关的语法提出了另一篇文章在这里,
  14. 我同意另一篇文章的System.IO类,如流,都有些设计不当;这需要一些实现抛出NotSupportException任何接口是一个不好的设计,
  15. 的IList要简单得多比它;事实上,这可能对很多具体的集合接口是真实的,就像ICollection的,
  16. 在太多的方法抛出异常,像IDictionary的,例如,
  17. 我会preFER检查异常比这更好的提供的Java(见如何可以做到这一点的类型和影响系统的研究),
  18. 的形式
  19. 在解决各种讨厌的角落案件泛型方法重载;例如,尝试提供两个重载扩展方法,可以操作的引用类型,以及其他的可空结构类型,看看你的类型推断怎么喜欢的是,
  20. 提供了一种安全的反思像INotifyPropertyChanged的接口,即把字段名作为一个字符串字段和成员名称;您可以通过使用扩展方法,该方法具有MemberEx pression一个lambda做到这一点,即。 ()=>富,但是这不是非常有效,
  21. 在允许的接口操作,使所有核心数字类型实现IArithmetic;其他有用的共享操作界面也是可能的,
  22. 请更难变异对象字段/属性,或者最起码,让一成不变的注释字段,并进行类型检查执行它(只是把它当作FER chrissakes吸气只读属性,它并不难!);事实上,统一字段和属性以更合理的方式,因为有具有两个毫无意义; C#3.0的自动性能是朝着这个方向迈出的第一步,但还远远不够,
  23. 在简化申报的构造;我喜欢F#的做法,但这里的其他职位,需要简单的新,而不是类的名字比较好,至少,
  1. non-nullable reference types as a complement to nullable value types,
  2. allow overriding a struct's empty constructor,
  3. allow generic type constraints to specify sealed classes,
  4. I agree with another poster here that requested arbitrary constructor signatures when used as constraints, ie. where T : new(string), or where T : new(string, int),
  5. I also agree with another poster here about fixing events, both for empty event lists and in the concurrent setting (though the latter is tricky),
  6. operators should be defined as extension methods, and not as static methods of the class (or not just as static methods at least),
  7. allow static properties and methods for interfaces (Java has this, but C# does not),
  8. allow event initialization in object initializers (only fields and properties are currently allowed),
  9. why is the "object initializer" syntax only usable when creating an object? Why not make it available at any time, ie. var e = new Foo(); e { Bar = baz };
  10. fix quadratic enumerable behaviour,
  11. all collections should have immutable snapshots for iteration (ie. mutating the collection should not invalidate the iterator),
  12. tuples are easy to add, but an efficient closed algebraic type like "Either" is not, so I'd love some way to declare a closed algebraic type and enforce exhaustive pattern matching on it (basically first-class support for the visitor pattern, but far more efficient); so just take enums, extend them with exhaustive pattern matching support, and don't allow invalid cases,
  13. I'd love support for pattern matching in general, but at the very least for object type testing; I also kinda like the switch syntax proposed in another post here,
  14. I agree with another post that the System.IO classes, like Stream, are somewhat poorly designed; any interface that requires some implementations to throw NotSupportException is a bad design,
  15. IList should be much simpler than it is; in fact, this may be true for many of the concrete collection interfaces, like ICollection,
  16. too many methods throw exceptions, like IDictionary for instance,
  17. I would prefer a form of checked exceptions better than that available in Java (see the research on type and effect systems for how this can be done),
  18. fix various annoying corner cases in generic method overload resolution; for instance, try providing two overloaded extension methods, one that operates on reference types, and the other on nullable struct types, and see how your type inference likes that,
  19. provide a way to safely reflect on field and member names for interfaces like INotifyPropertyChanged, that take the field name as a string; you can do this by using an extension method that takes a lambda with a MemberExpression, ie. () => Foo, but that's not very efficient,
  20. allow operators in interfaces, and make all core number types implement IArithmetic; other useful shared operator interfaces are possible as well,
  21. make it harder to mutate object fields/properties, or at the very least, allow annotating immutable fields and make the type checker enforce it (just treat it as getter-only property fer chrissakes, it's not hard!); in fact, unify fields and properties in a more sensible way since there's no point in having both; C# 3.0's automatic properties are a first step in this direction, but they don't go far enough,
  22. simplify declaring constructors; I like F#'s approach, but the other post here that requires simply "new" instead of the class name is better at least,

这就够了,现在我想。这是我在过去的一周运行到所有刺激。我大概可以走了几个小时,如果我真的把我的心给它。 C#4.0中已经增加命名的,可选的默认参数,这是我强调赞同。

That's enough for now I suppose. These are all irritations I've run into in the past week. I could probably go on for hours if I really put my mind to it. C# 4.0 is already adding named, optional and default arguments, which I emphatically approve of.

现在一个不合理的要求:

Now for one unreasonable request:

  1. 这将会是真的,真的很好,如果C#/ CLR可以支持类型构造多态性,即。仿制药比仿制药,
  1. it'd be really, really nice if C#/CLR could support type constructor polymorphism, ie. generics over generics,

pretty的吗? : - )

Pretty please? :-)

这篇关于C#(.NET)设计缺陷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆