<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Not as easy as it looks, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2011/01/17/not-as-easy-as-it-looks-part-two.aspx</link><description>Holy goodness, did you guys ever find a lot of additional ways in which an "eliminate variable" refactoring can go wrong. Just a few of your observations: (again, in every case, "x" is eliminated.) Any situation in which x is being treated as a variable</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Not as easy as it looks, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2011/01/17/not-as-easy-as-it-looks-part-two.aspx#10119383</link><pubDate>Mon, 24 Jan 2011 13:03:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10119383</guid><dc:creator>Shuggy</dc:creator><description>&lt;p&gt;@Reordering.&lt;/p&gt;
&lt;p&gt;Ugh that&amp;#39;s awful. Either work through it to understand what was the connections are and understand it/split it up/ sort it or leave it as is (low risk, no nasty to merge/annotate changes)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10119383" width="1" height="1"&gt;</description></item><item><title>re: Not as easy as it looks, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2011/01/17/not-as-easy-as-it-looks-part-two.aspx#10119309</link><pubDate>Mon, 24 Jan 2011 08:42:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10119309</guid><dc:creator>Reordering</dc:creator><description>&lt;p&gt;Classes get in this state because after x years y people have worked on them and they have added code somewhere.&lt;/p&gt;
&lt;p&gt;You get committed to extend an existing application with new features, the application is already 4 years old, you receive the code and it looks like this one, what do you do? Do you think to refactor it? No, absolutely not! It&amp;#39;s not your duty, nobody asked you to do it and you won&amp;#39;t lose your time doing it, you are paid to add new feature not to reordering a class, moreover, as already said, it&amp;#39;s really dangerous reordering a class by hand, the risk of a copy paste error is very high.&lt;/p&gt;
&lt;p&gt;At the end you add your code at the end or at the top of the class, and so will do the next one who has to add some new code. At this point have a function to reorder classes could be really &amp;nbsp;useful, at least you get a better structure than a tasty spaghetti class.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10119309" width="1" height="1"&gt;</description></item><item><title>re: Not as easy as it looks, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2011/01/17/not-as-easy-as-it-looks-part-two.aspx#10118909</link><pubDate>Sat, 22 Jan 2011 01:31:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10118909</guid><dc:creator>configurator</dc:creator><description>&lt;p&gt;@Reordering: How would a class get that way anyway? Unless you just drop code off at the end of the class when you need to add anything, which is a very bad practice, the class should be organized according to whatever order it is that you like them to be, which would normally not be alphabetic or according to accessibility.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10118909" width="1" height="1"&gt;</description></item><item><title>re: Not as easy as it looks, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2011/01/17/not-as-easy-as-it-looks-part-two.aspx#10118122</link><pubDate>Thu, 20 Jan 2011 13:02:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10118122</guid><dc:creator>Reordering</dc:creator><description>&lt;p&gt;Perhaps, still it could be a starting point, I stopped to use resharper because of the useless comments of the type &amp;quot;make a method static&amp;quot; or &amp;quot;don&amp;#39;t use the &amp;quot;this&amp;quot; keyword&amp;quot; and moreover it had some bugs which make it worst than the built in functions of visual studio, like the find all references, it was replaced with a resharper method which for some reason didn&amp;#39;t find all references.&lt;/p&gt;
&lt;p&gt;But at this point I would suggest to remove also the &amp;quot;sort and remove the using&amp;quot; option from VS because it could order or remove them in an way that somebody doesn&amp;#39;t like, so because somebody doesn&amp;#39;t like it nobody should use it, correct?&lt;/p&gt;
&lt;p&gt;And for me make more sense a class ordered like a in the class diagram than a spaghetti class:&lt;/p&gt;
&lt;p&gt;public class MySpaghettiClass&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; public void OnSpathettiAreUsed(){TheSpaghettiAreUsed(this,EventArgs.Empty);}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;public void GetSomeSause() {....}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; public event EventHandler TheSpaghettiAreThere;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;private int howManySpaghetti=0;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public string TheName {get; set;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp;pubclic void IsSomeSpaghettiThere(){ ...}&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public MySpaghettiClass() : this(11) {}&lt;/p&gt;
&lt;p&gt; public int HowManySpaghettiAreLeft(){return _spaghetti;}&lt;/p&gt;
&lt;p&gt; public event EventHandler TheSpaghettiAreUsed;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public int HowManySpaghetti{ger{return howManySpaghetti;} set{ howManySpaghetti=value;}}&lt;/p&gt;
&lt;p&gt; public MySpaghettiClass(istring name) {TheName=name;}&lt;/p&gt;
&lt;p&gt; public void UseSpaghetti(int spaghetti){howManySpaghetti-=spaghetti; OnSpaghettiAreUsed();}&lt;/p&gt;
&lt;p&gt;....&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10118122" width="1" height="1"&gt;</description></item><item><title>re: Not as easy as it looks, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2011/01/17/not-as-easy-as-it-looks-part-two.aspx#10117597</link><pubDate>Wed, 19 Jan 2011 13:47:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10117597</guid><dc:creator>configurator</dc:creator><description>&lt;p&gt;Reordering: if that happens to you, you&amp;#39;re doing it wrong.&lt;/p&gt;
&lt;p&gt;That said, if you do have a method to reorder a class automatically to an order that doesn&amp;#39;t make sense, it still wouldn&amp;#39;t help you...&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10117597" width="1" height="1"&gt;</description></item><item><title>re: Not as easy as it looks, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2011/01/17/not-as-easy-as-it-looks-part-two.aspx#10117547</link><pubDate>Wed, 19 Jan 2011 10:37:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10117547</guid><dc:creator>Weeble</dc:creator><description>&lt;p&gt;(Sorry if this is a double-post. The first attempt to post seemed to do nothing at all.)&lt;/p&gt;
&lt;p&gt;Resharper does member reordering. I learned this the hard way.&lt;/p&gt;
&lt;p&gt;At a previous company we had a moderate-to-large size of code-base with maybe 20 to 30 developers. We were building a game, but we had lots of associated command-line programs too. At some point the command-line programs&lt;/p&gt;
&lt;p&gt;all&lt;/p&gt;
&lt;p&gt;started&lt;/p&gt;
&lt;p&gt;writing&lt;/p&gt;
&lt;p&gt;their&lt;/p&gt;
&lt;p&gt;--help&lt;/p&gt;
&lt;p&gt;output&lt;/p&gt;
&lt;p&gt;like&lt;/p&gt;
&lt;p&gt;this.&lt;/p&gt;
&lt;p&gt;It seems that nobody noticed or cared for a while, because they rarely invoked the help. I only noticed when I was adding a new command-line tool. It turned out that the help tool, for reasons best known to the original author, used P/Invoke to determine the dimensions of the console (rather than, say, Console.BufferWidth) in order to do word-wrapping. It called GetConsoleScreenBufferInfo, for which it needed to define the structs CONSOLE_SCREEN_BUFFER_INFO, SMALL_RECT &amp;nbsp;and COORD. More recently, somebody had applied what was *supposed* to be a global clean-up using Resharper in order to bring things like spacing, identifiers and comments in-line with our newly agreed coding style. Unfortunately this clean-up also alphabetically sorted the members of every class, and somehow this wasn&amp;#39;t noticed when it was checked in. Since in C# structs default to LayoutKind.Sequential, the original code was correct, but alphabetically sorted it became gibberish.&lt;/p&gt;
&lt;p&gt;I removed all the P/Invoke and replaced them with Console.BufferWidth, grumbled at the people who had re-ordered everything, and wondered why anyone would even *want* to sort their members alphabetically. It makes about as much sense to me as ordering a music collection by the colour of the album art.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10117547" width="1" height="1"&gt;</description></item><item><title>re: Not as easy as it looks, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2011/01/17/not-as-easy-as-it-looks-part-two.aspx#10117535</link><pubDate>Wed, 19 Jan 2011 10:11:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10117535</guid><dc:creator>Reordering</dc:creator><description>&lt;p&gt;At the beginning the class is good organized and the class entropy is very low. Then a few changes are needed, which are added somewhere in the class structure, but still the class is good organized, but those few changes begin to raise the class entropy. After a couple of years of &amp;quot;few changes&amp;quot; the class entropy is so high that it would take too much time to reorganize it and the risk of a copy paste error is concrete. This means the class has already overcome the point of no return, the entropy now will only grow higher, it&amp;#39;s too late, bye bye good organized class, welcome tasty spaghetti class, the can of worms is open and nobody will close it.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10117535" width="1" height="1"&gt;</description></item><item><title>re: Not as easy as it looks, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2011/01/17/not-as-easy-as-it-looks-part-two.aspx#10117416</link><pubDate>Wed, 19 Jan 2011 03:06:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10117416</guid><dc:creator>configurator</dc:creator><description>&lt;p&gt;Reordering: But that would destroy the natural order of a class... Take this example, to make things clear.&lt;/p&gt;
&lt;p&gt;Class RectangleCalculator has a public interface which accept a Rectangle, two Points or four integers&lt;/p&gt;
&lt;p&gt;public int Area(Rectangle r);&lt;/p&gt;
&lt;p&gt;public int Area(Point p1, Point p2);&lt;/p&gt;
&lt;p&gt;public int Area(int x1, int y1, int x2, int y2);&lt;/p&gt;
&lt;p&gt;public int Perimeter(Rectangle r);&lt;/p&gt;
&lt;p&gt;public int Perimeter(Point p1, Point p2);&lt;/p&gt;
&lt;p&gt;public int Perimeter(int x1, int y1, int x2, int y2);&lt;/p&gt;
&lt;p&gt;Each of these does the argument validation, and then they delegate to the private CalculateArea and CalculatePermiter.&lt;/p&gt;
&lt;p&gt;Wouldn&amp;#39;t it make sense to order the class like this?&lt;/p&gt;
&lt;p&gt;public int Area(Rectangle r);&lt;/p&gt;
&lt;p&gt;public int Area(Point p1, Point p2);&lt;/p&gt;
&lt;p&gt;public int Area(int x1, int y1, int x2, int y2);&lt;/p&gt;
&lt;p&gt;private int CalculateArea(Whatever parameters);&lt;/p&gt;
&lt;p&gt;public int Perimeter(Rectangle r);&lt;/p&gt;
&lt;p&gt;public int Perimeter(Point p1, Point p2);&lt;/p&gt;
&lt;p&gt;public int Perimeter(int x1, int y1, int x2, int y2);&lt;/p&gt;
&lt;p&gt;private int CalculatePerimeter(Whatever parameters);&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10117416" width="1" height="1"&gt;</description></item><item><title>re: Not as easy as it looks, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2011/01/17/not-as-easy-as-it-looks-part-two.aspx#10117413</link><pubDate>Wed, 19 Jan 2011 03:01:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10117413</guid><dc:creator>configurator</dc:creator><description>&lt;p&gt;Weeble: That&amp;#39;s a good point! Nobody mentioned that...&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10117413" width="1" height="1"&gt;</description></item><item><title>re: Not as easy as it looks, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2011/01/17/not-as-easy-as-it-looks-part-two.aspx#10117412</link><pubDate>Wed, 19 Jan 2011 03:00:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10117412</guid><dc:creator>configurator</dc:creator><description>&lt;p&gt;DRBlaise: Static variables can still be disambiguated although not as easily - B.y here would disambiguate just fine.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10117412" width="1" height="1"&gt;</description></item></channel></rss>