Can the code be more user friendly?

Can the code be more user friendly?

Old forum URL: forums.lhotka.net/forums/t/7837.aspx


rxelizondo posted on Wednesday, October 21, 2009

Hello,

I was just wondering, is there really a benefit from having code that looks like this?

if (desiredType.GetGenericTypeDefinition() == typeof(Nullable<>))
    if (value == null)
        return null;
    else if (valueType.Equals(typeof(string)) && System.Convert.ToString(value) == string.Empty)
        return null;

Rather than something like this:

if (desiredType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
    if (value == null)
        return null;
    else if (valueType.Equals(typeof(string)) && System.Convert.ToString(value) == string.Empty)
        return null;
}

Note the curly open/close braces “{}”.

To me the second version *clearly* tells you what’s going on while on the first one it may get a little confusing. I mean, is the “else if” supposed to be for the first “if” or the second “if”?

Yes, yes, I know that programmers should know the answer to that, or that you can read the compiler documentation to see how it behaves or that you can step through the code etc, etc. But seriously, is there any practical point on the reason for why obsessing to save an extra line of code here and there?

I am not trying to be critical about it, just that I think it would make going through the vast CSLA code a little easier! :)

Thanks.

JoeFallon1 replied on Wednesday, October 21, 2009

Well,

You have to remember that Rocky is an old time VB programmer.

So extra curly braces are very easy to forget! <g>

Joe

 

 

Copyright (c) Marimer LLC