Information Technology Reference
In-Depth Information
as you have expressed an algorithm as mathematical pseudo code, the step to a real
programming language is quite small. The implementation of an algorithm in a par-
ticular language will of course depend on the syntax and built-in functionality of that
language. Even for the simple algorithms from Sect. 6.1 , the realizations of the algo-
rithms in different languages (see Sects. 6.3 and 6.4 ) vary considerably. Deciding
upon the most convenient programming tool is greatly subject to personal taste and
experience. Nevertheless, modern computational scientists need to master several
programming languages and have the ability to quickly jump into a new language.
The reason is obvious: Different tools have different strengths and weaknesses and
hence are suitable for different type of problems.
We shall discuss four basic issues that influence the choice of programming
language for scientific computing tasks:
-
Static typing versus dynamic typing
-
Computational efficiency
-
Built-in numerical high-performance utilities
-
Support for user-defined objects
The languages we bring into the discussion are Fortran 77, C, C CC , Java, Maple,
Matlab, and Python. All of these languages are widely used in scientific computing.
There are different versions of Fortran, e.g., Fortran 95 and Fortran 2000, which
have some of the features of C CC , Java, and Python. Fortran 77, on the other hand,
is a small and compact language with fewer features than C. We will normally spec-
ify the type of Fortran language, and use the term Fortran (without a number) when
we speak of the Fortran family of languages in general.
6.2.1
Static Typing Versus Dynamic Typing
Computer languages such as Fortran, C, C CC , and Java are said to be strongly
typed ,or statically typed . This means that the programmer must explicitly
write the type of each variable. If you want to assign the value 3 to a variable called
a , you must first specify the type of a . In this case a can be an integer or a real (single
precision or double precision) variable, since both types can hold the number 3. Say
you specify a to be an integer. Later on in the program you cannot store a string in a ,
because a can only hold an integer; a is related to a memory segment consisting of
four bytes, which are sufficient to store an integer, but too large or (more likely) too
small to store a string. Even if we could store a four-character string in four bytes,
the program would interpret these four bytes as an integer, not as four characters.
Maple, Matlab, and Python are examples of programming languages where one
does not need to specify the type of variables. If we want to store the number 3
in a variable a , we usually write a=3 (or a:=3 in Maple) to perform the assign-
ment. We may well store a string in a afterward, and then a real number, if desired.
The variable a will know its content, i.e., it will know whether it contains an inte-
ger, a real number, or a string and adjust its behavior accordingly. For example, if
Search WWH ::




Custom Search