1 / 12

The Evils of Copy and Paste

The Evils of Copy and Paste. Presented by Daniel Daugherty Daniel_cfug@danield.us. Why is Copy and Paste Evil?. Wait a second I use copy and paste all the time what is wrong with it?????? You mean I have to retype everything every time??. Why is Copy and Paste Evil?.

kana
Download Presentation

The Evils of Copy and Paste

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Evils of Copy and Paste • Presented by • Daniel Daugherty • Daniel_cfug@danield.us

  2. Why is Copy and Paste Evil? • Wait a second I use copy and paste all the time what is wrong with it?????? • You mean I have to retype everything every time??

  3. Why is Copy and Paste Evil? • Copy and Paste != Code Reuse • Copy and Paste is code duplication • But more is good right?

  4. What should I do instead? • Cut and Paste is your friend. • Cut the code and place where it can be referenced in two or more places (actual code reuse). • This may require some refactoring of the code into a more reusable segment of code.

  5. Advantages Of Cut and Paste • No duplication of code • No duplication of bug(s) within duplicated code. • Improved Readability • Improved Maintainability • Improved Testability

  6. variables include module custom tags import CFC Functions Web Services AJAX Code Reuse options in ColdFusion

  7. Does it matter how much I copy and paste? • Copying as little as one word could be a reason to extract that into a reusable segment. Even simple text labels. • Examples • Externalize a field label or column header • If length(x) and isdate(x) • If length(y) and isdate(y) becomes • If validDate(x) If validDate(y)

  8. Copy Paste Change? • But I just need to copy paste this 3 lines and make two small changes. • Small changes can be very error prone. Large changes tend to be tested better than small. • Possible options for reuse of this code. • CFModule/Custom Tag • CFC/Function

  9. What about other languages? • JavaScript, ActionScript - methods, variables, external files, prototypes. • CSS - named classes , multiple selectors for one set of attribute(s). Breaking style up into smaller re-useable blocks: Layout, Text, Color … • Java - classes, methods, variables, JSP tags, EJB, web services, …

  10. What about other applications? • Are both applications for same customer/company/client? • Use web services to make the logic available to both applications. • If both live on the same servers use mappings/custom tag paths to allow both apps to reference the same code.

  11. Code Example/Walkthrough

  12. Wrap Up • Try keeping track of how many times you copy and paste code for one day. You might be surprised at how often you do it. • Then think each time you do how can I move this to a reusable format. • Some copy paste is OK. • Questions?

More Related