<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>Comments for page &quot;In the Defense of Spaghetti Code&quot;</title>
		<link>http://250bpm.com/blog:36/comments/show</link>
		<description></description>
				<copyright></copyright>
		<lastBuildDate>Sat, 01 Aug 2015 21:44:07 +0000</lastBuildDate>
		
					<item>
				<guid>http://250bpm.com/blog:36/comments/show#post-2191604</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/blog:36/comments/show#post-2191604</link>
				<description></description>
				<pubDate>Tue, 30 Dec 2014 05:09:51 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>This article is relevant to discussion. It gives an example of inherently complex real-world system (payroll): <a href="http://c2.com/cgi/wiki?WhyIsPayrollHard">http://c2.com/cgi/wiki?WhyIsPayrollHard</a></p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/blog:36/comments/show#post-2137408</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/blog:36/comments/show#post-2137408</link>
				<description></description>
				<pubDate>Wed, 22 Oct 2014 17:43:32 +0000</pubDate>
				<wikidot:authorName>Chris J.</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>1500 lines that's it? I've been a maintenance developer on code that had functions thousands and thousands of lines lone. The worst was 12000 lines. Management never gave us permission to refactor that crap.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/blog:36/comments/show#post-2017813</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/blog:36/comments/show#post-2017813</link>
				<description></description>
				<pubDate>Wed, 23 Apr 2014 11:26:02 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>One or two exceptions are OK. What I am writing about here is domains that consist almost entirely of exceptions. Think time-zones. Or law.</p> <p>Another thing that's interesting about these domains is that they are typically evolving over time. Thus, what seems to be an invariant today, may not longer be an invariant tomorrow.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/blog:36/comments/show#post-2017777</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/blog:36/comments/show#post-2017777</link>
				<description></description>
				<pubDate>Wed, 23 Apr 2014 11:05:07 +0000</pubDate>
				<wikidot:authorName>Da Critique</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>It is very clear that your definition of spaghetti code is utterly wrong. I would not term a one off exception as spaghetti code. Almost all of the algorithms have some edge cases/base cases to deal with. They form part of the logic and cannot be termed as spaghetti code. It might be a usual case with you, but I have never written and hence not seen spaghetti code in my life.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/blog:36/comments/show#post-2008892</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/blog:36/comments/show#post-2008892</link>
				<description></description>
				<pubDate>Tue, 08 Apr 2014 23:02:46 +0000</pubDate>
				<wikidot:authorName>weethomas</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>I think you are forgetting the definition of spaghetti code.</p> <p>Let me give you a trivial, but real example.</p> <p>You write code for a product that interacts with other products using a published standard. Your product costs $. Another manufacturer's product, which almost all your customers use and you need to interoperate, costs $$$.</p> <p>Other manufacturer makes a breaking change. You don't know when they're going to issue a fix. But, you do know, given a choice over whether to trash other manufacturer or trash your product and use a competitor, customers will simply dump your product.</p> <p>What do you do?</p> <p>You can take the high road and say to yourself, &quot;there is no reason for spaghetti code&quot; and go out of business. Or, you can add in a line of code to handle this one off exception and keep trucking.</p> <p>By definition, that one off line of code (or lines) that exists solely for that one off corner case is spaghetti code. I suppose you could just pretend it's now part of the problem domain and un-spaghetti it.</p> <p>But since when other people look at it, they will instantly recognize it as spaghetti code, your decision to redefine terminology doesn't mean much.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/blog:36/comments/show#post-2008887</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/blog:36/comments/show#post-2008887</link>
				<description></description>
				<pubDate>Tue, 08 Apr 2014 22:56:17 +0000</pubDate>
				<wikidot:authorName>weethomas</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Ha, you've not actually experienced this have you? The original product doesn't need to be broken. You may just be a small player in a big world. If you make a product that interacts with other products over a common standard and big players make a mistake or a specific non-standard implementation and your customers need your product to work with them, then you have to play ball. Even if it means that the big kahuna introduced a change that broke what was otherwise a working product.</p> <p>Imagine about 7 years ago, you need to write code to communicate over one of the non-CAN OBD-II protocols. You grab the spec, rent a lot of vehicles, then write your implementation. In the meantime, GM makes a change which breaks your code.</p> <p>You don't make cars, you make an add-on that's supposed to work with cars. Do you really think you're going to convince your customers that it's GMs implementation that's broken? No. Here's the problem, a few other car companies also have slight tweaks that differ from the standard. Again, you can't just simply finger them as the bad guys. So, you add some spaghetti to your code and make it work.</p> <p>In case you think this is a contrived example, it's not. I've been the poor engineer in the sad position of writing code to hack around major car companies' actual implementation of something vs what the standard says.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/blog:36/comments/show#post-2002848</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/blog:36/comments/show#post-2002848</link>
				<description></description>
				<pubDate>Tue, 01 Apr 2014 05:27:30 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>The things that evolve are more or less unfactorable: Human anatomy. Body of law. Politics. Telco protocols. The old town of Marrakesh.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/blog:36/comments/show#post-2002451</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/blog:36/comments/show#post-2002451</link>
				<description></description>
				<pubDate>Mon, 31 Mar 2014 17:30:59 +0000</pubDate>
				<wikidot:authorName>Johnicholas</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>This blog posts's claim is that spaghetti code is the correct implementation of a domain with complex, human dynamics.</p> <p>It supports that claim with an illustrative example, where someone (foolishly) refactors a spaghetti implementation to a structure that does not reflect the complex, human dynamics, and then suffers thereby.</p> <p>However, the illustrative example only supports the weaker proposition &quot;code structure should reflect the dynamics of how the code changes&quot;.</p> <p>In particular, I think a rule-engine might be more appropriate than spaghetti code for a domain that changes &quot;legalistically&quot;. Alternatively, reifying vendors might be appropriate for a domain (such as device drivers?) where large vendors are long-term stable aspects of the domain.</p> <p>Essentially nothing in the real world is unfactorable. Your example doesn't have a correct architecture ONLY because it is a contrived example that does not have the patterned dynamics that occur in real-world domains - and &quot;doesn't have a correct architecture&quot; is not the same as &quot;spaghetti code is the best available architecture&quot;.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/blog:36/comments/show#post-2002312</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/blog:36/comments/show#post-2002312</link>
				<description></description>
				<pubDate>Mon, 31 Mar 2014 14:03:53 +0000</pubDate>
				<wikidot:authorName>Phil_haynes</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Sorry for the pedantry - wasn't it Fred Brooks who wrote the Mythical Man Month and Rodney Brooks is into robots?</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/blog:36/comments/show#post-2001207</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/blog:36/comments/show#post-2001207</link>
				<description></description>
				<pubDate>Sat, 29 Mar 2014 19:08:24 +0000</pubDate>
				<wikidot:authorName>Da Critique</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>I opine that blaming a domain spaghetti cannot be a sufficient reason to let the code be spaghetti. To give an analogy, just because the ground below is uneven cannot mean that a civil engineer can erect an uneven structure - it would just collapse.</p> <p>Speaking of chaos in human-defined concepts like law, telecom stuff etc, and the domains you might have worked in, they surely cannot as much chaotic as real life phenomena itself, where we have come of an age trying to employ machine-learning techniques to bring order, but not give in, to the 'Spaghetti' nature and immense chaos of enormous amounts data being churned.</p> <p>Engineering need to be based on principles and facts and always should be an endeavor to bring order to chaos - if your code that is split into multiple functions is becoming unwieldy, it surely is asking for a major overhauling or perhaps reached a limiting point(You can't keep adding floors to build an edifice of 100 floors with a foundation for 10 floors), in which case, you either stop working on it further or clone new components as Mr. Garrett D'Amore suggests, but can never relapse into having 1500 line functions, which, evidently is unwieldier.</p> <p>The argument in favor of having 1500 lines of code referring to some 'Spaghetti' domains is apparently myopic and untenable - instructions to computer, either low-level or high-level ought to be organized to be simple and elegant.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/blog:36/comments/show#post-2000618</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/blog:36/comments/show#post-2000618</link>
				<description></description>
				<pubDate>Fri, 28 Mar 2014 19:09:53 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Yes. If there's an invariant in the domain it should be factored out in the software. But how is that blog-worthy? It's a common wisdom.</p> <p>What developers often forget about though &#8212; and what is therefore worth pointing out &#8212; is that after factoring out all the invariants there remains an unfactorable residue, which happens to be pretty big in some unfortunate domains.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/blog:36/comments/show#post-2000593</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/blog:36/comments/show#post-2000593</link>
				<description></description>
				<pubDate>Fri, 28 Mar 2014 18:36:12 +0000</pubDate>
				<wikidot:authorName>Joe</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>It looks all right but then it turns out that foosoft=4 is already being used to identify yet another vendor who uses sequence numbering step of 2. The beautification have actually broken the product!</p> <p>If that was the case, the original product would have already been broken, since there is no explicit case for foosoft=4 to return old_seq+2, it would return old_seq+1. In any case, it seems that you're looking at the problem in the wrong way. The way you changed the function changes its meaning. You're taking a supposed vendor &quot;id,&quot; and using it as something else: a sequence interval. Refactoring is meant to change the code to be more readable without changing its function.</p> <p>This seems like a poor example.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/blog:36/comments/show#post-2000546</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/blog:36/comments/show#post-2000546</link>
				<description></description>
				<pubDate>Fri, 28 Mar 2014 17:16:11 +0000</pubDate>
				<wikidot:authorName>Johnicholas</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>The blog post is confusing, because it sounds like it is arguing for a conclusion something like &quot;the domain is spaghetti-shaped, so the code should be spaghetti-shaped&quot;. Some commenters are trying to point out how silly that argument is. Clearly &quot;the domain is red, so the code should be red&quot; or &quot;the domain is visual, so the code should be visual&quot; or &quot;the domain is three-dimensional, so the code should be three-dimensional&quot; are analogous, false claims.</p> <p>In fact, we should be focusing on the dynamics of the domain - how did it change in the past, and how do we anticipate it changing in the future, and which software architectures support which kinds of dynamics.</p> <p>For example, imagine a domain that changes for various complicated, human reasons that nevertheless preserves a particular rigid concept like a buoy floating on choppy water. Factoring that rigid concept out into some structure (a function, class, module, whatever) is probably a good thing to do.</p> <p>Similarly, when the blog post tells about a change that cross-cuts the existing architecture, leading to no good short-term options for evolving the system, the problem is that the (badly refactored) architecture mismatches the dynamics of the domain. However, that is not an argument FOR spaghetti code - because the spaghetti code may also mismatch the dynamics of the domain, and there may be other (more modular) architectures that do match the dynamics of the domain.</p> <p>For example, if there are a mountain of shipped devices that will not be upgraded, and we need to be compatible with, then the existence of that mountain may be a durable aspect of the domain, and it may be appropriate to factor out a structure (function, class, module, whatever) to deal with it. If there is a big, standards-bending vendor in this market, they may be a durable aspect of the domain, and it may be appropriate to factor out a structure to specialize in that vendor's peculiarities.</p> <p>Focus on the history of changes and likely stabilities in the domain in order to refactor towards maintainability; you cannot just &quot;follow your nose&quot; and narrow your gaze to the source code.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/blog:36/comments/show#post-1999955</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/blog:36/comments/show#post-1999955</link>
				<description></description>
				<pubDate>Thu, 27 Mar 2014 20:14:06 +0000</pubDate>
				<wikidot:authorName>Paul Hammant</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Would refactorings - &quot;introduce interface&quot;, and so on work here? Code in a predicate to that abstraction so the right one can be activated, and avoid the if/else stuff. Not a new idea at all - <a href="https://www.jetbrains.com/idea/webhelp/extract-interface.html">https://www.jetbrains.com/idea/webhelp/extract-interface.html</a> - relates to plugins, DI, and also BranchByAbstraction (but that last is more about migration).</p> <p>And yes, I've worked in spaghetti code before now.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/blog:36/comments/show#post-1998925</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/blog:36/comments/show#post-1998925</link>
				<description></description>
				<pubDate>Wed, 26 Mar 2014 07:27:00 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Great example, thanks!</p> <p>The interesting topic to think about is what tools do we have in our bag to deal with spaghetti domains. Only two of them come to mind readily: limiting the scope (&quot;we'll deal with only this little part of the domain and deliberately ignore the rest&quot;) and using copy+paste instead of more sophisticated problem decomposition tools.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/blog:36/comments/show#post-1998793</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/blog:36/comments/show#post-1998793</link>
				<description></description>
				<pubDate>Wed, 26 Mar 2014 01:55:38 +0000</pubDate>
				<wikidot:authorName>Garrett D&#039;Amore</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>This problem is very common in device drivers. Vendors clone each others chips, and each rev of silicon introduces new warts, features, and outright bugs.</p> <p>The tulip.c linux driver used to be a case in point &#8212; it was several times as large as it would be if it just supported one variant of device &#8212; it was more special cases than actual code flow. (I've not looked at that code in over a decade.)</p> <p>When I wrote drivers for similar chips for Solaris, I quite consciously decided that I would *not* try to cover all the variants in a single driver.</p> <p>Sometimes, its easier to just copy the source to a new driver to support the new chip (or network protocol!), and edit for the new without worrying about preserving compatibility with the old. Its also *safer*, since you've not broken anything that *was* working, and your new test matrix only has to consider the new device/protocol/case.</p> <p>Polymorphism is great. It also kills. Don't be afraid to just *clone* instead. :-)</p> <p>(Btw, this is why my Go version of SP protocols will never have support for ØMQ. If someone wants that functionality in Go, they should just copy my project, modify it for ØMQ, and make no effort to preserve functionality with SP/nanomsg. (I might actually do that work myself.)</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/blog:36/comments/show#post-1998764</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/blog:36/comments/show#post-1998764</link>
				<description></description>
				<pubDate>Wed, 26 Mar 2014 01:08:46 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>It looks like you have never worked in a spaghetti domain.</p> <p>If you are really interested, look for example at telco protocols at 3gpp.org You'll find thousands of pages of completely incoherent stuff.</p> <p>If you value your time you should rather skip that and think about a similar system that we are all familiar with: the legal code. Once again, thousands of pages of incoherent and sometimes even contradictory rules. Then yet more pages to paper over the inconsistencies. Et c.</p> <p>The problem with modeling such domain is that no rule really holds. Any assertion you'll make will have exceptions.</p> <p>Now, without universally valid rules, there's no way to decompose the problem into smaller, manageable chunks. Any boundary you draw between components will be violated by some peculiarity from the domain.</p> <p>From my own experience, what happens in reality is that people start modelling a little subdomain of the whole spaghetti domain and they find some generic rules that hold. They decompose the application according to those rules, only to find out that all their assumptions are violated when the scope of the project extends a bit out of the little subdomain. They may refactor at that point. But then the scope widens again and again and nobody really wants to do any more refactoring, so it all ends as a tangle of incomprehensible functions.</p> <p>What I am trying to say is that you sometimes have to acknowledge that the domain you are modelling is a mess and will remain to be a mess. In such environment it's better not to try to be smart and go for the simplest possible modelling paradigm (e.g. a long function with a lot of 'if' and 'switch' statements).</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/blog:36/comments/show#post-1998725</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/blog:36/comments/show#post-1998725</link>
				<description></description>
				<pubDate>Tue, 25 Mar 2014 23:51:11 +0000</pubDate>
				<wikidot:authorName>kikito</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>You are using strawman arguments here.</p> <p>First you talked about a 1500-line function. Then you say that you need a 1 manyear to decypher and write the tests. That does not match.</p> <p>If it's a huge library with lots of functions, you don't need to do everything in 1 go. You can refactor as you go: when you need to &quot;touch&quot; one function, write the tests for that individual function, and then refactor.</p> <blockquote> <p>But alas! It cuts straight through your well-defined functions and components! (Remember that this is inevitable: The domain itself is spaghetti such as regulatory directives or telco protocols.)</p> </blockquote> <p>Saying &quot;the domain is spaghetti&quot; does not mean anything. All domains change. All domains that are worth writing programs about are complex.</p> <p>Code can't be done like a building, or a bridge. Bridges have the Laws of Physics. Code lives in a changing environment. You can't build a bridge if every moment gravity changes, and the next one steel becomes jelly.</p> <p>That's why they pay us: to make code that not only works, but adapts to changes. That is the whole point. You must know how to make code that adapts. If you don't, search for help - read, go to workshops, or do something. It is your job to know how to do those things.</p> <p>The code you showed is not a product of &quot;the domain&quot;. It's a consequence of bad programming practices, and nothing else (with the possible exception of badly informed management).</p> <blockquote> <p>And he is right. Refactoring every two weeks is not a realistic option.</p> </blockquote> <p>Another strawman argument. I never said refactoring every two weeks. I say refactor *as much as you can*; not every 2 weeks, every day.</p> <p>And explain the problems of not refactoring to your manager, which is also part of your job.</p> <p>Your manager's immediate job is to increase the ROI, but in a larger scale he also should make informed tactical decisions. Your job is to provide him with all the information to make those decisions.</p> <p>Let me present you both scenarios.</p> <p>If you add tests and refactor, at the beginning (and for some time, depending on the size of the library) you will go more slowly. But sooner or later adding features will become easier, you will get less bugs. And you will be happier. If you end up leaving the project, a new programmer picking it up will have lots of help from the tests.</p> <p>If you just leave the big functions be, you will eventually get tired of maintaining that monstrosity. And then you will start looking for other jobs. And then you will leave your company, and your manager will be left with a new programmer, who won't have any idea of what the code does or why. The cycle will repeat.</p> <p>Adding new features will get increasingly more difficult, and bugs will appear with increasing frequency. At the end either the company will lose their clients or they will have to abandon the product and start from scratch.</p> <p>Choose.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/blog:36/comments/show#post-1998383</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/blog:36/comments/show#post-1998383</link>
				<description></description>
				<pubDate>Tue, 25 Mar 2014 15:08:52 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>OK, here's the story:</p> <p>You've inherited the code in question. The particular case foosoft=4 was written 20 years ago by a guy who died in the meantime.</p> <p>You find the problem and you see the code is in terrible shape and you are able to convince your management to spend say 1 manyear on decyphering the code and writing the tests. Then you convince them to allocate one more manyear to refactor the code in a clean way.</p> <p>Once done a deployed, you get a new change request from the customer. But alas! It cuts straight through your well-defined functions and components! (Remember that this is inevitable: The domain itself is spaghetti such as regulatory directives or telco protocols.)</p> <p>At this point you'll try to convince your manager to allocate more time on refactoring. The answer would be: &quot;You've got 2 manyears to do refactoring. You've finished two weeks ago. And now you asking me for more time to refactor? Shut up and do your work.&quot;</p> <p>And he is right. Refactoring every two weeks is not a realistic option. In such environment, simply keeping the code in a single function is the best bet: It's at least linear and relatively easy to understand and modify.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/blog:36/comments/show#post-1998357</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/blog:36/comments/show#post-1998357</link>
				<description></description>
				<pubDate>Tue, 25 Mar 2014 14:27:17 +0000</pubDate>
				<wikidot:authorName>kikito</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <blockquote> <p>It looks all right but then it turns out that foosoft=4 is already<br /> being used to identify yet another vendor who uses sequence<br /> numbering step of 2. The beautification have actually broken the product!<br /> The patch is hastily reverted.</p> </blockquote> <p>There are several things that I consider wrong on this approach.</p> <p>First, the text doesn't mention it explicitly, but it seems that the issue was detected when the new code was already in production. It should have been picked up in a staging environment, not in a production environment.</p> <p>Second, when you encounter a huge-ass function, the first thing you have to do is look for tests. If there are no tests, the first thing you must do is write the tests - from whatever documentation / knowledge there is. *Then* you can start refactoring.</p> <p>If the code had been passed around several times and it had no tests and no docs, chances are that you will get bitten by &quot;implicitness&quot; like the foosoft=4 case.</p> <p>But the responsible way of doing things not &quot;reverting the patch and leaving it like that&quot;. You add another test for the one-off case (foosoft=4), then redo the &quot;beautification&quot; (more on that later) and then you push those changes to the staging server for testing. And after they are verified, you can move them to production (even then, you can add them gradually, with feature flags). And if new &quot;implicit cases&quot; arise, you add tests and refactor until everything is discovered and nothing remains implicit.</p> <p>Finally, the article seems to infer that refactoring is &quot;about the looks&quot;. It mentions &quot;code looking nice&quot; and &quot;beautification&quot;. The point of refactoring is not beauty; it's utility. Code is refactored so that it is *better at communicates what it does to humans*.</p> <p>A proper refactoring of the function would have taken this into account.</p> <div class="code"> <pre> <code>int new_sequence_number(int old_sqn, int foosoft) { if(is_vendor_a(foosoft)) { return vendor_a_new_sequence_number(old_sqn, foosoft); } else if(is_ventor_b(foosoft)) { return vendor_b_new_sequence_number(old_sqn, foosoft); } else { return old_sqn + 1; } }</code> </pre></div> <br /> The important thing this function does is *not* calculating the new sequence; it's deciding whether what kind of sequence we're calculating. The particularities of how to calculate it are left to other functions. By using explicit names we make the code more *clear* (not necessarily more beautiful or elegant). There's no &quot;implicitness&quot; here. <p>If you &quot;leave the big functions untouched&quot; you are part of the problem, and a not particularly good programmer. Sure, if an impending deadline forces you to, take shortcuts, but reserve some time later on to &quot;pay the debt&quot; you incurred into.</p> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>