[AccessD] CodePlex WCF Community code snippet

Heenan, Lambert Lambert.Heenan at chartisinsurance.com
Tue May 1 08:11:17 CDT 2012


Hi Shamil,

I would be inclined to say that the code from codeplex is better. The logic is a little bit obscure, but then professional c/c++/c# codes have always tended to be a tad brief in their style. However a brief period of study makes it clearly correct. 

The reason I would prefer the codeplex code is that it only has 6 comparison operations, where the mere mortals code uses 10. Where there are many thousands of objects being compared in a tight loop that could significantly increase the execution time.

Lambert

-----Original Message-----
From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Salakhetdinov Shamil
Sent: Tuesday, May 01, 2012 8:34 AM
To: Access Developers discussion and problem solving
Subject: [AccessD] CodePlex WCF Community code snippet

Hi All --

Sorry I'm posting C# code snippet here as my question/quick poll is more about coding style than anything else:

I have occasionally got browsing through the following CodePlex WCF Community source code:

http://wcf.codeplex.com/SourceControl/changeset/view/66aa503c963c#WCFJQuery%2fTest%2fMicrosoft.Runtime.Serialization.Json.FunctionalTests%2fCommon%2fUtil.cs 

...
        public static bool CompareObjects<T>(T o1, T o2) where T : class
        {
            if ((o1 == null) != (o2 == null))
            {
                return false;
            }

            return (o1 == null) || o1.Equals(o2);
        }
...

And I have got stuck first trying to get its logic.

Would you consider the above code more professional and maintainable and effective than the following "mere mortals" code version? If Yes/No - why?

        public static bool CompareObjects2<T>(T o1, T o2) where T : class
        {
            if (o1 == null && o2 == null) return true;
            if (o1 != null && o2 == null) return false;
            if (o1 == null && o2 != null) return false;
            return o1.Equals(o2);
       }

Thank you ;)

-- Shamil 


--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



More information about the AccessD mailing list