Page 193 - DCAP104_EXPOSURE_TO_COMPUTER_DISCPLINES
P. 193

Exposure to Computer Disciplines



                   Notes            • input: Get data from the keyboard, a file, or some other device.
                                    • output: Display data on the screen or send data to a file or other device.

                                    • arithmetic: Perform basic arithmetical operations like addition and multiplication.
                                    • conditional execution: Check for certain conditions and execute the appropriate sequence
                                      of statements.
                                    • repetition: Perform some action repeatedly, usually with some variation.

                                 Many computer languages provide a mechanism to call functions provided by libraries such as in
                                 .dlls. Provided the functions in a library follow the appropriate run time conventions (e.g., method
                                 of passing arguments), then these functions may be written in any other language.
                                 9.1.8 Paradigms

                                 Computer programs can be categorized by the programming language paradigm used to produce
                                 them. Two of the main paradigms are imperative and declarative.
                                 Programs written using an imperative language specify an algorithm using declarations,
                                 expressions, and statements. A declaration couples a variable name to a datatype. For
                                 example: var x: integer; . An expression yields a value. For example: 2 + 2 yields 4. Finally, a
                                 statement might assign an expression to a variable or use the value of a variable to alter the
                                 program’s control flow. For example: x := 2 + 2; if x = 4 then do_something( ); One criticism
                                 of imperative languages is the side effect of an assignment statement on a class of variables
                                 called non-local variables.

                                 Programs written using a declarative language specify the properties that have to be met by the
                                 output. They do not specify details expressed in terms of the control flow of the executing machine
                                 but of the mathematical relations between the declared objects and their properties. Two broad
                                 categories of declarative languages are functional languages and logical languages. The principle
                                 behind functional languages (like Haskell) is to not allow side effects, which makes it easier to
                                 reason about programs like mathematical functions. The principle behind logical languages (like
                                 Prolog) is to define the problem to be solved, the goal and leave the detailed solution to the Prolog
                                 system itself. The goal is defined by providing a list of subgoals. Then each subgoal is defined by
                                 further providing a list of its subgoals, etc. If a path of subgoals fails to find a solution, then that
                                 subgoal is backtracked and another path is systematically attempted.
                                 The form in which a program is created may be textual or visual. In a visual language program,
                                 elements are graphically manipulated rather than textually specified.
                                 9.1.9 Compiling or Interpreting

                                 A computer program in the form of a human-readable, computer programming language is called
                                 source code. Source code may be converted into an executable image by a compiler or executed
                                 immediately with the aid of an interpreter.

                                 Either compiled or interpreted programs might be executed in a batch process without human
                                 interaction, but interpreted programs allow a user to type commands in an interactive session.
                                 In this case, the programs are the separate commands, whose execution occurs sequentially, and
                                 thus together. When a language is used to give commands to a software application (such as a
                                 shell) it is called a scripting language.






        186                               LOVELY PROFESSIONAL UNIVERSITY
   188   189   190   191   192   193   194   195   196   197   198