Home Accessibility Courses Diary The Mouth Facebook Resources Site Map About Us Contact
Coding efficiency - do not repeat yourself!

"If you find yourself repeating something ... there's probably a better way"

"If you find yourself thinking "surely someone's done this before" ... they probably have, and their code is probably available to you"

The things I find myself saying very frequently in courses ... for delegates who are new to programming get so involved in writing code that's going to work that they don't stop and think if they're doing to much work; they concentrate so much on the immediate task in hand, nose to grindstone, that they don't always look at the wider picture.

1. If you repeat the same code several times in succession, you probably should be using a loop.

2. If you repeat the same code several times in your program, you probably should be splitting that code out into a function.

3. If you find yourself writing the same code in several programs, you probably should be using an included file.

4. If you find yourself writing complex code to do a common, simple task there's probably a built in function to help you.

5. If you find yourself writing code that - surely - someone has done before, look at the resource libraries for the language you're using - PEAR, PECL, CPAN, Gems ... or at SourceForge.

Remember that if you duplicate code, you're duplicating the need for any fixes as you test and debug the code, and you're duplicating the maintainance tasks ongoing for the whole life of the code - and that will be a huge waste of time and effort.

From yesterday's PHP course: [control - no functions or includes] and [With functions and an include] ; [here] is the include file.
(written 2010-11-02)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
H105 - PHP - Functions
  [2929] Passing a variable number of parameters in to a function / method - (2010-08-20)
  [2737] Improving your function calls (APIs) - General and PHP - (2010-04-24)
  [2682] Adding extensions to PHP Open Source applications - callbacks - (2010-03-17)
  [2630] Static variables and ampersands in PHP - (2010-02-10)
  [2488] A variable number of arguments in a PHP function - (2009-11-02)
  [1784] Global - Tcl, PHP, Python - (2008-09-03)
  [1380] Static variables in PHP - (2007-10-05)
  [1357] Clean my plate, but keep my wine bottle. (PHP; Static) - (2007-09-18)
  [1267] is there a lookup function in php? - (2007-07-15)
  [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)
  [1021] PHP - static declaration - (2007-01-04)
  [936] Global, Superglobal, Session variables - scope and persistance in PHP - (2006-11-21)
  [866] A lazy programmer is a good programmer - (2006-09-15)
  [775] Do not duplicate your code - (2006-06-23)
  [421] Don't repeat code - use loops or functions - (2005-08-21)
  [409] Functions and commands with dangerous names - (2005-08-11)
  [340] Code and code maintainance efficiency - (2005-06-08)
  [339] Passing information into and out of PHP functions - (2005-06-07)
  [308] Call by name v call by value - (2005-05-11)
  [223] There is a function in PHP to do that - (2005-02-21)
  [96] Variable Scope - (2004-10-22)

Q101 - Object Orientation and General technical topics - Programming Principles
  [4206] Writing the perfect program in Tcl? - (2013-11-13)
  [4153] Rooms available tonight - how to code an algorithm from first principles - (2013-08-19)
  [4118] We not only teach PHP and Python - we teach good PHP and Python Practice! - (2013-06-18)
  [4090] Test Driven Development in Python - Customer Comes First - (2013-05-16)
  [4061] Seamless, integrated IT - we have a long way to go! - (2013-04-11)
  [4003] Web and console - same principle, same code - Ruby example - (2013-02-14)
  [3954] Lesson 1 in programing - write clean, reuseable and maintainable tidy code - (2012-12-16)
  [3928] Storing your intermediate data - what format should you you choose? - (2012-11-20)
  [3878] From Structured to Object Oriented Programming. - (2012-10-02)
  [3673] Object oriented or structured - a comparison in Python. Also writing clean regular expressions - (2012-03-26)
  [3551] Some terms used in programming (Biased towards Python) - (2011-12-12)
  [3548] Dark mornings, dog update, and Python and Lua courses before Christmas - (2011-12-10)
  [3542] What order are operations performed in, in a Perl expression? - (2011-12-07)
  [3456] Stepping stones - early coding, and writing re-usable code quickly - (2011-09-24)
  [2964] An introduction to file handling in programs - buffering, standard in and out, and file handles - (2010-09-21)
  [2915] Looking up a value by key - associative arrays / Hashes / Dictionaries - (2010-08-11)
  [2878] Program for reliability and efficiency - do not duplicate, but rather share and re-use - (2010-07-19)
  [2769] Easy - but for whom? - (2010-05-18)
  [2586] And and Or illustrated by locks - (2010-01-17)
  [2550] Do not copy and paste code - there are much better ways - (2009-12-26)
  [2510] The music of the stock market - (2009-11-22)
  [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)


Back to
Learning to Program ... in PHP. Course examples.
Previous and next
or
Horse's mouth home
Forward to
Server logs - drawing a graph of gathered data
Some other Articles
Liquorice allsorts and Dolly Mixtures
PHP data sources - other web servers, large data flows, and the client (browser)
VAT rise in January - it is really up 14% not just 2.5%
Server logs - drawing a graph of gathered data
Coding efficiency - do not repeat yourself!
Learning to Program ... in PHP. Course examples.
Testing the new pavement ready for Christmas
Autumn walk from Bowerhill
Retaining web site visitors - reducing the one page wonders
Courses for late 2010 and early 2011
4280 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, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86 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., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3026_Cod ... self-.html • PAGE BUILT: Sun Mar 30 15:20:58 2014 • BUILD SYSTEM: WomanWithCat