First coding ... and people start at the top and work through to the bottom. Example:
[here].
Then they find bits of code repeating, and they separate the repeating stuff out into functions. Example :
[here].
In order to re-use the repeated stuff in other programs, they then save it to another file which can be loaded in lots of programs. Example:
[here] with the included file
[here].
Finally, as the application grows there may be good reasons to group all the named code blocks associated with a particular type of data into a class. Example of a calling program
[here], and the class file
[here].
It can be quite difficult for newcomers to programming to appreciate steps 2, 3 and 4 ... but if you can learn about them early on, you can save yourself a huge amount of recoding later. Learning by your mistakes is sometimes good, but it's usually inefficient!
(written 2011-09-24)
Associated topics are indexed under
Q101 - Object Orientation and General technical topics - Programming Principles [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)
[3026] Coding efficiency - do not repeat yourself! - (2010-11-02)
[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)
[2737] Improving your function calls (APIs) - General and PHP - (2010-04-24)
[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)
Some other Articles
Flying Colours!Catching the fishes first?On this day ... one PHP script with three usesAway to train - but still around by video for Melksham meetingsStepping stones - early coding, and writing re-usable code quicklyMySQL, MySQLi, PDO or something else - how best to talk to databases from PHPYour PHP website - how to factor and refactor to reduce growing painsReading and using emails including enclosures on your web server.Which or ATOC - who reads train fares right?Why would you want to use a Perl hash?