The Evils of Copy and Paste - PowerPoint PPT Presentation

About This Presentation
Title:

The Evils of Copy and Paste

Description:

Why is Copy and Paste Evil? Wait a second I use copy and ... You mean I have to retype everything every time?? Why is Copy and Paste Evil? Copy and Paste ! ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 13
Provided by: Office20041299
Category:

less

Transcript and Presenter's Notes

Title: The Evils of Copy and Paste


1
The Evils of Copy and Paste
  • Presented by
  • Daniel Daugherty
  • Daniel_cfug_at_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
Code Reuse options in ColdFusion
  • variables
  • include
  • module
  • custom tags
  • import
  • CFC
  • Functions
  • Web Services
  • AJAX

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/cl
    ient?
  • 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?
Write a Comment
User Comments (0)
About PowerShow.com