Questions on Juval Lowy's IDesign C# Coding Standard

Posted by Jan on Stack Overflow See other posts from Stack Overflow or by Jan
Published on 2011-10-20T09:31:41Z Indexed on 2012/09/09 15:38 UTC
Read the original article Hit count: 295

Filed under:
|
|
|

We are trying to use the IDesign C# Coding standard. Unfortunately, I found no comprehensive document to explain all the rules that it gives, and also his book does not always help.

Here are the open questions that remain for me (from chapter 2, Coding Practices):

  1. No. 26: Avoid providing explicit values for enums unless they are integer powers of 2
  2. No. 34: Always explicitly initialize an array of reference types using a for loop
  3. No. 50: Avoid events as interface members
  4. No. 52: Expose interfaces on class hierarchies
  5. No. 73: Do not define method-specific constraints in interfaces
  6. No. 74: Do not define constraints in delegates

Here's what I think about those:

  1. I thought that providing explicit values would be especially useful when adding new enum members at a later point in time. If these members are added between other already existing members, I would provide explicit values to make sure the integer representation of existing members does not change.
  2. No idea why I would want to do this. I'd say this totally depends on the logic of my program.
  3. I see that there is alternative option of providing "Sink interfaces" (simply providing already all "OnXxxHappened" methods), but what is the reason to prefer one over the other?
  4. Unsure what he means here: Could this mean "When implementing an interface explicitly in a non-sealed class, consider providing the implementation in a protected virtual method that can be overridden"? (see Programming .NET Components 2nd Edition, end of chapter “Interfaces and Class Hierarchies”).
  5. I suppose this is about providing a "where" clause when using generics, but why is this bad on an interface?
  6. I suppose this is about providing a "where" clause when using generics, but why is this bad on a delegate?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET