VCE IT Lecture Notes by Mark Kelly, McKinnon Secondary College
Processing features of programming languages |
|
(2011) SD U3O2 KK09- processing features of programming languages, including instructions, procedures, methods, functions and control structures |
InstructionsInstructions are commands that a particular programming language can interpret and carry out. Each language has its own instruction set; most languages have common instructions that they all can carry out even if their names vary (e.g. Most instructions need further information (parameters) to do their work (e.g.
|
ProceduresProcedures are usually self-contained segments of code that carry out a specific job. Modern programs are often made up of a collection of procedures that are called when needed. Procedures are sometimes also known as subprograms or subroutines. Programs built from procedures are sometimes called modular because pre-written modules can easily be inserted as needed into a new program, saving time and effort. Calling procedures keeps programs smaller because code is not repeated whenever it has to be carried out. Program flow jumps to the desired procedure, the code is carried out, and then program flow returns to the point at which it was called and the program continues. Many programmers keep a personal library of favourite procedures that they use all the time.
|
MethodsIn an object-oriented language, a method usually refers to the pre-determined operations that an object can carry out. Each class of object has its own particular methods. Just like a Dog object has the methods of bark, run, bite, sleep, and sniff, a textbox has methods like show, hide, enable. In Visual Basic, methods are invoked like Other methods can be devised in procedures by the programmer. Below, when button1 is clicked, it triggers the custom
Tip: don't confuse an object's methods (the things it can do) with its properties (its settings). e.g. TEXTBOX.KEYDOWN is an action it can respond to, but TEXTBOX.WIDTH is a property that can be set. |
FunctionsA function is a procedure that returns a value to the code that calls it. It is a way to create a custom calculation. The programming language has inherent (built-in) functions for you to use, e.g. square root(number), sine(angle), uppercase(text), but you can create your own functions as needed. Nearly all functions need to be provided with data to process. These data are called parameters. e.g. it's not much use asking for a square root without saying what number you want the square root of. This number is the function's parameter. Some functions need more than one parameter to calculate their value, e.g.
If, somewhere else in the program this (pseudo)code appeared: it would read every line in the text file and store the title (e.g. "Mrs"), first name and surname into variables. It would then call the Buildname function and pass it the 3 parameters. The Buildname function takes the values supplied (e.g. "Mary", "Smith" "Miss") and stores them in its own local variables Notice how the names of the parameter variables don't have to match the names of the parameters listed in the function definition. The values are passed as pieces of text. (See below about byval and byref) Advanced tip: Values can be passed to a function either by value (byval) or by reference (byref). If parameters are passed by value, copies of the values of the variables are sent to the function. Whatever the function does to those data, the original values of the variable are not changed. However if the parameters are passed by reference, any changes made by the function to the parameter also changes the variable that was sent as the parameter. e.g. if Buildname changed the value of |
Control structuresto be continued |
Back to the IT Lecture Notes index
Back to the last page you visited
Created $$
Last changed: September 14, 2010 3:07 PM
VCE IT Lecture notes copyright © Mark Kelly 2001-