Computational Thinking
Computational thinking
Computational thinking helps with this. It allows us to take a complex problem, understand what the problem is and develop possible solutions. These solutions can then be presented in a way that a computer, a human, or both can understand.
Two important elements of computational thinking are:
decomposition
abstraction
Logical reasoning
Logical reasoning is not programming. Put simply, programming tells a computer what to do and how to do it. Logical reasoning enables programmers to work out exactly what to tell the computer to do.
Decomposition and abstraction
Decomposition involves analysing a complex problem or system and breaking it down into smaller parts that are more manageable and easy to understand. The smaller parts can then be examined and solved, or designed individually, as they are simpler to work with.
Abstraction
Abstraction is the process of filtering out - essentially ignoring - the characteristics of problems that are not needed in order to concentrate on those that are needed. It is also the filtering out of specific details. From this, an idea of what is to be solved can be created.
Using subprograms to produce structured code
Subprograms are small programs that are written within a larger, main program. The purpose of a subprogram is to perform a specific task. This task may need to be done more than once at various points in the main program.
There are two types of subprogram:
procedures
functions
Benefits of using subprograms
Subprograms are usually small in size, which means they are easier to write, test and debug than programs. They are also easy for someone else to understand.
Subprograms can be saved separately as modules and used again in other programs. This saves time because the programmer can use code that has already been written, tested and debugged.
A subprogram may be used repeatedly at various points in the main program. However, the code only has to be written once, resulting in shorter programs.
Procedures
A procedure is a subprogram that performs a specific task. When the task is complete, the subprogram ends and the main program continues from where it left off. For example, a procedure may be written to reset all the values of an array to zero, or add some values together.
A parameter allows a value to be passed in to the procedure. The name of each parameter can be used inside the procedure to access the value the procedure was called with.
A procedure is run by calling it. To call it, programmers use the procedure name and include any parameter values that the procedure needs
Functions
A function works in the same way as a procedure, except that it processes data and returns a result back to the main program.
A function is run by calling it from the main program. To call it, programmers use the function's identifier, the parameter value to be passed into the function, and a variable for the function to return and assign a value into.
Built-in functions
Many programming languages include built-in, ready-made functions, such as:
int - converts strings or floats into integers
str - converts a number into a string
asc - finds the ASCII number of a character
Additionally, some languages allow functions to be added in from external files called libraries. Libraries contain pre-written, tested functions that extend the functionality of a language.