4.1.1 Identify the procedure appropriate to solving a problem.
4.1.2 Evaluate whether the order in which activities are undertaken will result in the required outcome.
4.1.3 Explain the role of sub-procedures in solving a problem.
Procedural thinking is a disciplined method of thinking in sequence, in order and logically. This is very similar to "Methodical thinking" where a person pays very careful attention to the detail and precisely follows the procedures.
Procedural thinking can be demonstrated using tools such as flow chart and/or in simple algorithms.
Following a recipe requires procedural thinking because you must follow the steps in order
Putting together Ikea furniture requires procedural thinking because you usually follow the steps in order
Procedural thinking is used when performing CPR to save someone's life - you follow a series of steps (call for help, check breathing, check airway, check circulation, decide if you perform CPR)
When you print something on a school printer, you follow a series of sequential steps (choose what to print, click print, choose a printer, go to the printer, and then scan your barcode).
If a lamp is broken, you might follow these steps in the flowchart below[2]:
"Procedural programming can be defined as a subtype of imperative programming as a programming paradigm based upon the concept of procedure calls, in which statements are structured into procedures (also known as subroutines or functions). Procedure calls are modular and are bound by scope. A procedural program is composed of one or more modules. Each module is composed of one or more subprograms. Modules may consist of procedures, functions, subroutines or methods, depending on the programming language. Procedural programs may possibly have multiple levels or scopes, with subprograms defined inside other subprograms. Each scope can contain names which cannot be seen in outer scopes."
"OOP is a programming paradigm based on the concept of "objects", which may contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods. A feature of objects is that an object's procedures can access and often modify the data fields of the object with which they are associated (objects have a notion of "this" or "self"). In OOP, computer programs are designed by making them out of objects that interact with one another. There is significant diversity of OOP languages, but the most popular ones are class-based, meaning that objects are instances of classes, which typically also determine their type."
Procedural Programming
Uses a list of instructions to tell the computer what to do step by step
Operations rely on procedures also known as routines or sub-routines
Contains series of computation steps to be carried out
Also referred to as imperative programming
Procedural programming languages are also known as Top-down languages (Most early programming languages e.g. Fortran, COBOL, C)
Intuitive in the sense that it is similar to how you expect the program to work
Object-Oriented Programming
An approach to problem solving where all computations are carried out using objects
An Object may contain data, in the form of fields, often knows as attributes, functions in the form of proCedures known as methods.
An Object is a component of a program that knows how to perform certain actions and how to interact with other elements of the program
Computer programs are designed by making them out of objects that interact with one another
sub-procedures – also known as procedures, functions, methods, routines, or subroutines –
take input
generate output
manipulate data
Example #1: Java method
/*
* Generates random number between min and max inclusive
* pre: max > min > 0
* post: random number <= max > min
*
*/
public int getRandomNum(int min, int max) {
Random r = new Random();
int num = r.nextInt(max) + min;
return num;
}
A large/difficult program could be divided into smaller/easier parts (sub-programs);
A sub-program could be used many times in this and other programs;
A sub-program could be written independently;
A sub-program could be tested independently;
Easier maintenance – only sub-program could be changed/modified as needed;
A function is a piece of code that is called by name. It can be passed data to operate on (i.e. the parameters) and can optionally return data (the return value).
All data that is passed to a function is explicitly passed.[4]
vs
A method is a piece of code that is called by a name that is associated with an object. In most respects it is identical to a function except for two key differences:
A method is implicitly passed the object on which it was called.
A method is able to operate on data that is contained within the class (remembering that an object is an instance of a class - the class is the definition, the object is an instance of that data).[4]
Creating methods/functions in Java
Procedural thinking. (n.d.). Retrieved August 17, 2017, from https://computersciencewiki.org/index.php/Procedural_thinking
(n.d.). Retrieved August 17, 2017, from http://www.yourdictionary.com/methodical
C++ Programming: Programming Language Paradigms, from https://en.wikibooks.org/wiki/C%2B%2B_Programming/Programming_Languages/Paradigms
What is the difference between function and method in Java?, from https://www.quora.com/