Comparing CodeRush Refactor! Pro and Resharper 4, part 1 or N — first glance.

Metadata view of code in referenced assemblies
This is a big one for me.  For whatever reason, Refactor 4 (and prior) completely disables this and sends you to the Object Browser instead.   You get metadata view with CodeRush Refactor! Pro. 


Keyboard layout
As you might imagine, CodeRush Refactor! Pro and Resharper had completely different keyboard layouts.  So, if you’re used to R# then Refactor! Pro will take a bit of getting used to.


One thing I don’t like with the default Refactor! Pro keyboard layout, is they’ve replaced Ctrl-. with Quick Navigation.  I use Ctrl-. (instead of Shift-Alt-F10 to get at the smart-tag menu).  Shift-Alt-F10 for smart-tag menu seems more common; so I’ll have to get use to Shift-Alt-F10.


Refactor! Pro’s Editor enhancements
R# doesn’t change to how the editor looks as much as CodeRush Refactor! Pro.  It has the Marker Bar, error/warning/info colouring, and action light-bulbs.  Refactor! Pro with CodeRush has many more, like region painting, flow-break evaluation, Visibility Icons, structural highlighting, etc.


Real-time analysis
Both R# and CodeRush Refactor! Pro do real-time code analysis.  R# has text colouring and the right-hand marker bar.  CodeRush Refactor Pro has a marker bar on both the left and the right.  The left marker bar in CodeRush Refactor! Pro highlights issues for each line, and the right (as does R#) shows a file-wide view of issues.  I find the R# marker bar sometimes doesn’t align with the scroll bar so that an issue may be beside the scroll-bar in the marker bar but is actually scrolled off the screen.  CodeRush Refactor Pro doesn’t do that and in fact shows the visible portion of the document in its marker bar.  i.e. the marker bar is beside the Visual Studio Indicator Margin (where the breakpoint bullets appear).


Refactorings
They both have many of the same refactorings.  When it comes to non-refactorings the two sometimes approach things differently.  For example R# deals with adding members to a class through “Generate Code” list; whereas CodeRush Refactor Pro uses templates.  E.g. in R#, to add a constructor you hit Alt-Ins and select Constructor.  With Refactor you simply enter “cc “(that ‘c’, ‘c’, space).


Smart-Tags
Both approach smart-tags slightly differently.  With R# they use the actions light-bulb at the left margin.  This includes fixes for warnings, errors, plus refactorings, but doesn’t include code generation options.  CodeRush Refactor Pro uses an ellipsis-like icon that appears right at the site of the potential refactoring. Code Refactor Pro is a richer experience.  It will show you the result of a refactoring with arrows showing where things will move, red strike-out showing what will be removed, and highlights for things that will be changed/renamed.

Entity Framework Petition of Vote of Non Confidence

I had intended to be happy simply being a signatory of ADO .NET Entity Framework Vote of No Confidence.  But, there’s people suggesting signatories of this petition are wackos or on the fringe.


Do yourself a favour and read the petition.  Read what we have issues with and how we think Entity Framework (EF) can be improved to be a better product.  Read seminal material by industry leaders on entity-oriented and object-oriented application development like Domain Driven Design, and Agile Principles, Patterns and Practices in C# (and the predecessor Agile Software Development: Principles, Patterns and Practices) and Applying Domain-Driven Design and Patterns: With Examples in C# and .NET.  If after you have understand this information, you think being forced to use EF on a software development team would mean it would be hard to implement generally accepted object-oriented and entity-oriented design, the sign the petition.


Yes, you have the choice no to use EF; but you also have the choice to help people to not have to deal with the issues detailed in the petition simply because they were not made aware of them.


And despite the naysayers of people who think EF should improve, the ADO.NET team is listening and agrees.

kick it on DotNetKicks.com

Fundamentals of OOD Part 3: Method Cohesion

Single Responsibility Principle (SRP) helps us write more cohesive types and methods.  Cohesion is the relatedness of the members of a type to each other and the relatedness parts of a method’s code to other parts.

Method cohesion
Often times a method is not very cohesive, meaning the code that it executes relates to more than one thing.  This can often be seen with a method that contains a large switch statement.  For any invocation of the method only one case statement may be executed; meaning that blocks of code within the method don’t relate to all the other blocks.  Switch statements are often an indication that the design should be changed to be more polymorphic or introduce a pattern like the Strategy or Template Method patterns.  Likely a concept of the design is implicit instead of explicit (at least no more explicit than an enum).  For example:

    public class Set {

        public enum Operation {

            Unknown,

            Union,

            Intersection,

            RelativeComplement,

            And,

            Conjunction = And

        }

 

        public static IList<int> PerformOperation(IList<int> one, IList<int> two, Operation operation) {

            List<int> result = new List<int>();

            switch (operation) {

                case Operation.Union:

                    result.AddRange(one);

                    result.AddRange(two);

                    break;

                case Operation.Intersection:

                    foreach (int x in one) {

                        if (two.Contains(x)) {

                            result.Add(x);

                        }

                    }

                    break;

                case Operation.RelativeComplement:

                    foreach (int x in one) {

                        if (!two.Contains(x)) {

                            result.Add(x);

                        }

                    }

                    break;

                case Operation.And:

                    foreach (int x in one) {

                        if (two.Contains(x)) {

                            result.Add(x);

                        }

                    }

                    break;

                default:

                    throw new ArgumentOutOfRangeException(“operation”);

            }

            return result;

        }

    }


This code works; but it’s far from cohesive.  There are many combinations of execution paths this method can take, and each path is unrelated to the other paths.  For example, the Union case has no relation to any of the other cases.  Methods like this are also hard to maintain and prone to errors.  Obviously if another member were added to Operation PerformOperation would have to change–making PerformOperation tightly coupled to Operation–not very object oriented.

This can be made more object-oriented by through Dependency Inversion and the Strategy Pattern:

    public class Set2 {

        public abstract class Operation {

            public abstract IList<int> Execute(IList<int> left, IList<int> right);

        }

 

        public class UnionOperation : Operation {

            public override IList<int> Execute(IList<int> left, IList<int> right) {

                List<int> result = new List<int>();

                result.AddRange(left);

                result.AddRange(right);

                return result;

            }

        }

 

        public class IntersectionOperation : Operation {

            public override IList<int> Execute(IList<int> left, IList<int> right) {

                List<int> result = new List<int>();

                foreach (int x in left) {

                    if (right.Contains(x)) {

                        result.Add(x);

                    }

                }

                return result;

            }

        }

 

        public class RelativeComplementOperation : Operation {

            public override IList<int> Execute(IList<int> left, IList<int> right) {

                List<int> result = new List<int>();

                foreach (int x in left) {

                    if (!right.Contains(x)) {

                        result.Add(x);

                    }

                }

                return result;

            }

        }

 

        public class AndOperation : Operation {

            public override IList<int> Execute(IList<int> left, IList<int> right) {

                List<int> result = new List<int>();

                foreach (int x in left) {

                    if (right.Contains(x)) {

                        result.Add(x);

                    }

                }

                return result;

            }

        }

        public static IList<int> PerformOperation(IList<int> left, IList<int> right, Operation operation) {

            return operation.Execute(left, right);

        }

    }

Now each operation is encapsulated, explicit, PerformOperation need not change as new strategies are added, and we’ve completely avoided the InvalidOperationException.

kick it on DotNetKicks.com

.NET Framework Source Code License.

This license applies to the .NET Framework components that Microsoft makes available to you in source code form.  To print these terms, select the contents of this area and copy then paste into an application that can print text.


MICROSOFT .NET FRAMEWORK REFERENCE LICENSE
.NET FRAMEWORK REFERENCE SOURCE CODE



This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.
1. Definitions
The terms “reproduce,” “reproduction” and “distribution” have the same meaning here as under U.S. copyright law.
 
“You” means the licensee of the software, who is not engaged in designing, developing, or testing other software, for a non-Windows operating system, that has the same or substantially the same features or functionality as the software.


“Your company” means the company you worked for when you downloaded the software.
“Reference use” means use of the software within your company as a reference, in read only form, for the sole purposes of debugging and maintaining your products to run on a Microsoft Windows operating system product.  For clarity, “reference use” does NOT include (a) the right to use the software for purposes of designing, developing, or testing other software, for a non-Windows operating system, that has the same or substantially the same features or functionality as the software, and (b) the right to distribute the software outside of your company.
“Licensed patents” means any Licensor patent claims which read directly on the software as distributed by the Licensor under this license.


2. Grant of Rights
(A) Copyright Grant- Subject to the terms of this license, the Licensor grants you a non-transferable, non-exclusive, worldwide, royalty-free copyright license to reproduce the software for reference use.


(B) Patent Grant- Subject to the terms of this license, the Licensor grants you a non-transferable, non-exclusive, worldwide, royalty-free patent license under licensed patents for reference use.



3. Limitations
(A) No Trademark License- This license does not grant you any rights to use the Licensor’s name, logo, or trademarks.


(B) If you begin patent litigation against the Licensor over patents that you think may apply to the software (including a cross-claim or counterclaim in a lawsuit), your license to the software ends automatically.


(C) The software is licensed “as-is.” You bear the risk of using it. The Licensor gives no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the Licensor excludes the implied warranties of merchantability, fitness for a particular purpose and non-infringement.