Actions: The Second Ingredient of a Program
In this chapter the second ingredient of a program namely “actions” that programmers use to manipulate data for solving real-world problems are introduced. Actions are transformed into machine instructions, which are then decoded and executed by the CPU.
- PDF / 709,802 Bytes
- 49 Pages / 439.37 x 666.142 pts Page_size
- 80 Downloads / 209 Views
Actions: The Second Ingredient of a Program
In the previous chapter, we have introduced data an essential but static component of programming. It is static in the sense that data has no ability to act: Data cannot change itself, create new data, or even display itself. It is the actions of a high-level language that will provide all these. Actions are what will be performed in terms of CPU instructions at the machine code level.
3.1 Purpose and Scope of Actions A program, as stated previously, is a solution to a world problem. World problems form a broad spectrum including: mathematical computations involved in mortgage calculations, weather forecasting, processing sensory data of a person’s cardiac activity or remote sensing of a fired hostile missile. Providing a (computerized) solution requires many actions to be taken in a program. Providing a (computerized) solution requires many actions to be taken in a program. These actions can be classified into two categories: • Creating and/or modifying data: This is actually what computation is all about. Given some data, based on rules that govern the specific computational domain, these types of actions infer new data. That is what we do when we multiply two numbers, solve a quadratic equation, calculate the fuel for a spacecraft to travel from Earth to the Moon, or find the net profit a bank has made over all its fiscal transactions. This type of computation is one, or a combination of two or more, of the following: • Evaluating a mathematical expression. • Looking up or modifying some structured data (e.g., a container, a tree, a graph, etc.), • Storing the results of computations. • Making a decision about how to proceed with the computation, • Altering the flow of the computation. G. Üçoluk, S. Kalkan, Introduction to Programming Concepts with Case Studies in Python, DOI 10.1007/978-3-7091-1343-1_3, © Springer-Verlag Wien 2012
71
72
3 Actions: The 2nd Ingredient of a Program
High-level programming languages provide the facilities to undertake these actions: • The evaluation of an expression is similar to what we are used to doing in our math classes, but there are some restrictions. For example, there is no concept of unknowns or variables as in mathematical terms, and writing down an equation never has the implicit meaning of ‘solving the equation for an unknown’. The information that appears in an expression is either a constant or a value stored in the memory (i.e., a ‘variable’ in programming terms). Therefore, all calculations are merely arithmetical. • High-level languages have built-in facilities for constructing and navigating structured data. In the previous chapter, some basic structures, such as containers, were introduced. A decent high-level language will provide programming handles (like pointers, functions for dynamic memory allocation) even if it does not offer direct syntax for actions on certain kinds of structured data. • Storing any result obtained in computations into the memory is provided in all high-level languages through variables.
Data Loading...