Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Do not copy and paste code - there are much better ways

If you find yourself using copy and paste to duplicate a piece of code, take a step back and think again. You're doubling your maintenance work, with two separate sets of code to look after and keep in step from that day forwards.

Are you going to give me the "but I have to change one copy a bit" excuse? Please don't ... in identifying which bits need changing, you have identified the parameters for a named block of code ... which will be known as a sub / subroutine / function / macro / method / procedure / command depending on which language you're writing in.

There's an example in [this bit of code] which I wrote yesterday in Perl, looking for Christmas topics within place names (Well - as someone else said ... "the programs on the TV weren't worth watching") ...

And if you want to try the code out, there's a web based derivative [here]. Enjoy!

(written 2009-12-26 09:47:34)

 
Associated topics are indexed under
Q101 - Object Orientation and General technical topics - Programming Principles
  [2586] And and Or illustrated by locks - (2010-01-17)
  [2415] Variable names like i and j - why? - (2009-09-22)
  [2327] Planning! - (2009-08-08)
  [2310] Learning to write high quality code in Lua - (2009-07-30)
  [2228] Where do I start when writing a program? - (2009-06-11)
  [2022] Pre and post increment - the ++ operator - (2009-02-03)
  [2001] I have not programmed before, and need to learn - (2009-01-19)

P105 - Perl - Repeating Blocks of Code
  [1607] Learning to program in Perl - (2008-04-11)

P209 - Subroutines in Perl
  [2069] Efficient calls to subs in Perl - avoid duplication, gain speed - (2009-03-07)
  [1921] Romeo and Julie - (2008-12-04)
  [1860] Seven new intermediate Perl examples - (2008-10-30)
  [1850] Daisy the Cow and a Pint of Ginger Beer - (2008-10-21)
  [1826] Perl - Subs, Chop v Chomp, => v , - (2008-10-08)
  [1784] Global - Tcl, PHP, Python - (2008-09-03)
  [1782] Calling procs in Tcl and how it compares to Perl - (2008-09-02)
  [1202] Returning multiple values from a function (Perl, PHP, Python) - (2007-05-24)
  [1163] A better alternative to cutting and pasting code - (2007-04-26)
  [969] Perl - $_ and @_ - (2006-12-07)
  [775] Do not duplicate your code - (2006-06-23)
  [588] Changing @INC - where Perl loads its modules - (2006-02-02)
  [531] Packages in packages in Perl - (2005-12-16)
  [357] Where do Perl modules load from - (2005-06-24)
  [308] Call by name v call by value - (2005-05-11)
  [96] Variable Scope - (2004-10-22)


Back to
Christmas Day ...
Previous and next
or
Horse's mouth home
Forward to
Perl and the Common Gateway Interface - out of fashion but still very useful?
Some other Articles
Adding retrospective ALT attributes to IMG
On a short walk from home
Web site traffic - real users, or just noise?
Perl and the Common Gateway Interface - out of fashion but still very useful?
Do not copy and paste code - there are much better ways
Christmas Day ...
Ten years ago, we moved to Melksham Spa
The great thing about snow ....
How well do you know Melksham - a quiz for Christmas
Scraping content for your own page via PHP
2675 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2010: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 344596 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho