Juval Lowy's C# Coding Standards Questions

后端 未结 8 2089
无人共我
无人共我 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:39

    Regarding 1.13 (Avoid fully qualified type names. Use the "using" statement instead):

    It may be a bit more than readability. If you have too many usings at the beginning of the file, you have a class that is coupled with classes from too many namespaces.

    The class is screaming out for refactoring. Using usings instead of fully-qualified class names lets you identify such tightly-coupled classes more easily.

    0 讨论(0)
  • 2021-01-30 18:42

    2.29 Ternary operator

    To start with, if you start to use the ternary operator, there should be a reason for the use of the ternary operator over a regular if-then-else. Observe :

    if (x == 0) {...} else{...} //A set of statements demand a regular If-then-else
    
    //A simple assignment can be handled by the ternary operator
    y = (x == 0)? 1 : 0 //this is readable and how it should be used
    
    
    (x==0)? callSomething() : callSomethingElse() //this is NOT how it should be used
    

    The ternary statement is meant for returning one of two values depending upon the conditional it is evaluating. This is extremely handy when doing FP. For call statements that do not return a value, you should revert to if-then-else.

    0 讨论(0)
提交回复
热议问题