Stepping stones - early coding, and writing re-usable code quickly
Archive - Originally posted on "The Horse's Mouth" - 2011-09-24 15:08:19 - Graham Ellis
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!