Juval Lowy's C# Coding Standards Questions

后端 未结 8 2092
无人共我
无人共我 2021-01-30 18:07

I enjoy and highly recommend Juval Lowy\'s - C# Coding Standard. Juval explicitly avoids rationale for each directive in order to keep the standard tight (see the preface). Howe

8条回答
  •  清歌不尽
    2021-01-30 18:34

    This is my best stab at the questions you've listed. For the ones that I can't really say, I've omitted.

    1.13 Avoid fully qualified type names. Use the "using" statement instead.

    Readability. It's must harder to read code when you have to read fully qualified type names.

    2.19 Avoid defining custom exception classes

    The .NET framework comes with a good set of exceptions built into the system. Unless the exception you're modeling is business domain specific, you'll probably be able to use one of the existing exception classes.

    2.29 Avoid using the ternary conditional operator

    I think this is most likely because he thinks people may not understand the operator, but I disagree.

    2.47 Avoid interfaces with one member.

    He might be warning people of building interfaces that are too thin. However, I would actual say the converse, warning people of making interfaces too verbose. If you've ever had to deal with ASP.NET MembershipProvider, you know what I'm talking about.

    2.31 Avoid function calls in Boolean conditional statements. Assign into local variables and check on them.

    A couple of reasons I can think of here. Readability. It can make conditional statements hard to understand if you are making function calls in them. Also, it's harder to debug if you're not watching.

    2.53 Prefer using explicit interface implementation

    I believe his reasoning here is to for brevity. However, I don't actually agree with this assessment. I think Jon is correct, implicit interface should be used when you can, and explicit when appropriate.

提交回复
热议问题