<story><title>The Wrong Abstraction (2016)</title><url>https://www.sandimetz.com/blog/2016/1/20/the-wrong-abstraction</url></story><parent_chain><item><author>captainmuon</author><text>So much this. I&amp;#x27;ve encountered many codebases (in science and in tech) where the coder did not even use basic abstractions. In one case there was a lot of&lt;p&gt;&lt;pre&gt;&lt;code&gt;    plot(&amp;#x27;graph1&amp;#x27;)
    plot(&amp;#x27;graph2&amp;#x27;)
    ....
    plot(&amp;#x27;graph100&amp;#x27;)
&lt;/code&gt;&lt;/pre&gt;
because somebody didn&amp;#x27;t know how to create strings at runtime in C++. Another codebase did complex vector calculations in components, I was able to reduce a 500 lines function to 50 lines (including comments, and with bugs fixed).&lt;p&gt;I can sympathize with this a bit, I started programming with BASIC - you could not return structs, you could not use indirect variables (no pointers&amp;#x2F;references)... but at least you had the FOR loop :-P&lt;p&gt;People get often called out for over abstracting (rightly so), but I&amp;#x27;ve rarely seen somebody critisized for copypasta or for overly stupid code. Probably because we&amp;#x27;re too accidentially afraid to imply somebody can&amp;#x27;t code.</text></item><item><author>Pxtl</author><text>Every Line Of Business codebase I&amp;#x27;ve worked on has been the worst &amp;quot;there I fixed it&amp;quot; copypasta spaghetti, and has never made it to the point where &amp;quot;maybe we shouldn&amp;#x27;t add a parameter to this existing, cleanly abstracted method to handle this new similar-but-distinct use-case&amp;quot; was anywhere near my radar for abstraction.&lt;p&gt;I would &lt;i&gt;love&lt;/i&gt; to have developers where my problem was &amp;quot;maybe you piggybacked on existing code &lt;i&gt;too much&lt;/i&gt;, in this case you should&amp;#x27;ve split out your own function&amp;quot;.</text></item></parent_chain><comment><author>toastal</author><text>This comes up very often and is probably a big part of the distaste many people have for jQuery. You see so much copypasta $(selector) that queries the entire DOM over and over again instead of storing the intial query in a selector, querying children based on a ParentNode, etc.. This duplication is wasteful at best, and can hurt performance at worst.&lt;p&gt;But as others noted, this is usually the sign that the creator is either green, or puts little focus in furthering their programming because they normally do other things--not malice or carelessness.</text></comment>
<story><title>The Wrong Abstraction (2016)</title><url>https://www.sandimetz.com/blog/2016/1/20/the-wrong-abstraction</url></story><parent_chain><item><author>captainmuon</author><text>So much this. I&amp;#x27;ve encountered many codebases (in science and in tech) where the coder did not even use basic abstractions. In one case there was a lot of&lt;p&gt;&lt;pre&gt;&lt;code&gt;    plot(&amp;#x27;graph1&amp;#x27;)
    plot(&amp;#x27;graph2&amp;#x27;)
    ....
    plot(&amp;#x27;graph100&amp;#x27;)
&lt;/code&gt;&lt;/pre&gt;
because somebody didn&amp;#x27;t know how to create strings at runtime in C++. Another codebase did complex vector calculations in components, I was able to reduce a 500 lines function to 50 lines (including comments, and with bugs fixed).&lt;p&gt;I can sympathize with this a bit, I started programming with BASIC - you could not return structs, you could not use indirect variables (no pointers&amp;#x2F;references)... but at least you had the FOR loop :-P&lt;p&gt;People get often called out for over abstracting (rightly so), but I&amp;#x27;ve rarely seen somebody critisized for copypasta or for overly stupid code. Probably because we&amp;#x27;re too accidentially afraid to imply somebody can&amp;#x27;t code.</text></item><item><author>Pxtl</author><text>Every Line Of Business codebase I&amp;#x27;ve worked on has been the worst &amp;quot;there I fixed it&amp;quot; copypasta spaghetti, and has never made it to the point where &amp;quot;maybe we shouldn&amp;#x27;t add a parameter to this existing, cleanly abstracted method to handle this new similar-but-distinct use-case&amp;quot; was anywhere near my radar for abstraction.&lt;p&gt;I would &lt;i&gt;love&lt;/i&gt; to have developers where my problem was &amp;quot;maybe you piggybacked on existing code &lt;i&gt;too much&lt;/i&gt;, in this case you should&amp;#x27;ve split out your own function&amp;quot;.</text></item></parent_chain><comment><author>platz</author><text>&amp;gt; I&amp;#x27;ve rarely seen somebody critisized for copypasta or for overly stupid code.&lt;p&gt;Do you think that is in the realm of what the article is concerned with?</text></comment>