Learning to program - what are algorithms and design patterns?
Archive - Originally posted on "The Horse's Mouth" - 2014-11-22 15:16:57 - Graham Ellis
There are common themes for how programming statements are put together to give complete section of code to perform combined tasks. And typically these are putting together building blocks in a similar way to we would do things if we were working something out by hand.
Looking for the maximum value in a column of numbers, for example, we would start off by guessing that the first number was the maximum, and then we would check against each of the following numbers to see if it was greater, updating our guess if it was. Come the end of the reading down the column, the final value is no longer just a guess, it really is the maximum.
Such standard application of coding is known as the application of algorithms or design patterns - that latter term especially applicable to what we'll describe to you later on the course as Object Oriented Programming
All the languages that we teach have at least some algorithms and / or design patterns built into the language, as standard pieces of code in the library that we've referred to earlier in this module. In some languages, such as Lua and Tcl the standard libraries are quite small, and on the course we'll be showing you how to code certain algorithms yourself. In others such as PHP, we have a standing joke around the class that says "there's a function to do that" ... and indeed a huge array of common functions are available to you which you can call up in a single line to run a particular algorithm against some of your variables, passing back a result into another variable. Java, Python, Perl and Ruby - and some of the other languages - have a large number of algorithms available to you, included in the language distribution (as so present on your computer's disc / file system) but only loaded in to memory at run time, typically on your request through a program statement asking for them to be loaded. And resources are available in virtually every language on teh web to provide shared algorithms which, whilst to commonly enough needed to included in the distribuiton, are never the less worth sharing.