Copy and Paste is not a design pattern.




  • After noticing one of my coworkers likes to copy and paste code (Some code I inherited from him contained a comment along the lines "Any changes made here need to be made in this other function"), I found a tool that reports duplicate lines, called Simian. Running it one one file:

    Found 608 duplicate lines in 58 blocks in 1 files
    Processed a total of 1139 significant (2578 raw) lines in 1 files
    

    So, half the file is comments, commented out code and white space, and half of the remaining code is duplicated. Over the whole code base:

    Found 14508 duplicate lines in 1164 blocks in 278 files
    Processed a total of 54116 significant (132672 raw) lines in 559 files
    

    Over a quarter of the code base is duplicated lines. But this is how we've always done things. Another interesting thing, Simian allows you to set the block size it uses to figure out if a section is duplicate. The above numbers are the default block size of 6

    Threshold: 5 lines
    Found 16968 duplicate lines in 1656 blocks in 311 files
    Processed a total of 54116 significant (132672 raw) lines in 559 files
    
    Threshold: 4 lines:
    Found 21688 duplicate lines in 2836 blocks in 374 files
    Processed a total of 54116 significant (132672 raw) lines in 559 files
    

    I'm going to cry now.



  • I feel your pain. I've been rooting out copypasta in our code base for several years. There are still some places that would make you cry, but it's a lot better now. Well, I think it's a lot better now. Maybe I should look into this tool to see how bad it is.



  • @boomzilla said:

    I feel your pain. I've been rooting out copypasta in our code base for several years. There are still some places that would make you cry, but it's a lot better now. Well, I think it's a lot better now. Maybe I should look into this tool to see how bad it is.
     

     

    Copy paste is style of coding and it become much simpler to follow convention over configuration. That is basic philosophy of all ruby development.

     



  • @Nagesh said:

    @boomzilla said:

    I feel your pain. I've been rooting out copypasta in our code base for several years. There are still some places that would make you cry, but it's a lot better now. Well, I think it's a lot better now. Maybe I should look into this tool to see how bad it is.
     

     

    Copy paste is style of coding and it become much simpler to follow convention over configuration. That is basic philosophy of all ruby development.

     

    Copy-pasted code allows for a more flexible upgrade path than shared libraries because regression tests on everything that relies on a library can be hugely expensive. And if a library is deemed "mature enough" and supposedly won't require frequent debug/upgrade activities, then the copy-pasted code that it would replace is good enough too so it should be left alone.



    Unless it's a very tiny system, I believe that design patterns, convention over configuration and copy-pasted code are a better gamble than shared components.



  • @bardofspoons42 said:

    Copy and Paste is not a design pattern

    It is a design pattern... a design pattern used by fucking retards.



  • @The_Assimilator said:

    @bardofspoons42 said:
    Copy and Paste is not a design pattern

    It is a design pattern... a design pattern used by fucking retards.

    I'm so incredibly impressed by the depth and wit in your post that I not only change my mind about copy-pasted code, I also want to launch a start-up and hire you as chief engineer. The company will be called "WE HIRE NO FUCKING RETARDS AND WE LOVE UPPERCASE" but only if the .com domain name is available.


  • Winner of the 2016 Presidential Election

    If you maintain one medium-to-large project that uses 25%+ copypasta code, for any length of time, the code itself will beat you with a cluestick. Good luck keeping anything consistent.

    Edit: this is why I think it's important every developer should deal with some WTF code firsthand, to witness the damage anti-patterns can cause.



  • @Ronald said:

    @The_Assimilator said:
    @bardofspoons42 said:
    Copy and Paste is not a design pattern

    It is a design pattern... a design pattern used by fucking retards.

    I'm so incredibly impressed by the depth and wit in your post that I not only change my mind about copy-pasted code, I also want to launch a start-up and hire you as chief engineer. The company will be called "WE HIRE NO FUCKING RETARDS AND WE LOVE UPPERCASE" but only if the .com domain name is available.

    Wait, are you actually advocating copy-and-paste? I thought you were just joking..


  • Winner of the 2016 Presidential Election

    @morbiuswilters said:

    @Ronald said:
    @The_Assimilator said:
    @bardofspoons42 said:
    Copy and Paste is not a design pattern

    It is a design pattern... a design pattern used by fucking retards.

    I'm so incredibly impressed by the depth and wit in your post that I not only change my mind about copy-pasted code, I also want to launch a start-up and hire you as chief engineer. The company will be called "WE HIRE NO FUCKING RETARDS AND WE LOVE UPPERCASE" but only if the .com domain name is available.

    Wait, are you actually advocating copy-and-paste? I thought you were just joking..


    I'm thinking bridget just made a new screen name.



  • @morbiuswilters said:

    @Ronald said:
    @The_Assimilator said:
    @bardofspoons42 said:
    Copy and Paste is not a design pattern

    It is a design pattern... a design pattern used by fucking retards.

    I'm so incredibly impressed by the depth and wit in your post that I not only change my mind about copy-pasted code, I also want to launch a start-up and hire you as chief engineer. The company will be called "WE HIRE NO FUCKING RETARDS AND WE LOVE UPPERCASE" but only if the .com domain name is available.

    Wait, are you actually advocating copy-and-paste? I thought you were just joking..

    No I just wanted to complain about the uppercase thing and I needed a good context.



  • @joe.edwards said:

    I love bridget jones diary

    Hey we should schedule a GT and watch all the bridget jones movies. If there is some time left we could watch a few Ernest too, the dude is gone so they won't make any new ones.



  • @Ronald said:

    Hey we should schedule a GT and watch all the bridget jones movies.
     

    Holy fucking shit, I'm only learning now there's [url="http://www.imdb.com/title/tt0317198/?ref_=fn_al_tt_2"]a sequel[/url]?

    PJ and chocolate ice cream time tonight!

     



  • @Lorne Kates said:

    @Ronald said:

    Hey we should schedule a GT and watch all the bridget jones movies.
     

    Holy fucking shit, I'm only learning now there's a sequel?

    PJ and chocolate ice cream time tonight!

     

    More on the way! (maybe)



  • I worked at a job like this, an ASP.NET shop using .NET 4.0 and writing it like 1.0.  I ran Simian just to see and it came up with similar results.  I also once tried to run FxCop, and it would CRASH due to so many warnings/issues it found.  This place also ignored compiler warnings for everything (because hey it compiles, so it must work... right?)

    Funnily enough I was fired for suggesting one too many times that maybe there's a better way of doing things than copy/paste and hacking away until the errors stop coming up, and the reason given was that my C# skills weren't that good.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.