Chi-Tech
devman_A2_OOP_vs_Functional.h
Go to the documentation of this file.
1
/**\page DevManOOPvsFunc OOP vs Functional Programming
2
*
3
4
## Object Oriented Programming or Functional Programming
5
6
### <CENTER>Chi-Tech uses a healthy balance between OOP and FP</CENTER>
7
8
The fundamental language with which a human provides instructions to a
9
computer has always been **assembly language**. This language,
10
which was pioneered halfway through the 20th century, is specific to
11
a computer architecture and became the lowest level of programming that
12
rose above simply supplying bytes of binary code to the computer.
13
14
Assembly language comprises combinations of keywords and/or numbers to
15
form instructions, with each instruction telling the processor what
16
action to take, whether it is to move data from one memory location
17
to another or to perform an arithmetic operation on some data. By
18
stringing together numerous instructions the complexity of a human
19
thought-process could be made repeatable by a computer, however, the
20
process of generating assembly language programs quickly became tedious.
21
It did not take long before mankind comprehended the need for "packaging"
22
multiple instructions into **macros**, which could be reused and
23
hence the modern programming language was born where macros are
24
standardized and collected into higher level languages
25
(i.e., FORTRAN, C, etc).
26
27
In the 1950s scientific programming revolved around **block programming**,
28
a programming paradigm where
29
thought-processes are arranged as blocks that creates-,
30
transforms- or uses data. This era of programming also included
31
the use of the famous "GOTO" statement which led to the concept
32
of what we today call "spaghetti-code", a style of programming
33
only seen in older programs. The biggest concern with this style
34
is the amount of effort required by a person, other than the creator
35
of the programmer, to understand the overall program structure and flow.
36
The difficulties are mainly associated with the limitations of the
37
human mind to maintain scope and in many cases programmers would find
38
themselves having trouble comprehending programs that they wrote a
39
few weeks or months ago. These problems were greatly reduced with
40
the advent of **structured programming** where the flow of the
41
program is controlled by means of control blocks like if/then/else
42
statements within which blocks of code, called "functions", could
43
be executed. This aligned well with the industrial era where procedures
44
could be regarded as stand-alone parts and the overall flow of the program
45
could be visualized by a process diagram. The general term used
46
today is **functional programming** (FP) and is very effective
47
for certain algorithms.
48
49
50
The general motivation for functional programming stemmed from a
51
development point of view. In the true sense of talking to the
52
computer, the FP paradigm still resulted in sets of instructions
53
to the computer, however, it was found that reusing, changing or
54
understanding code using block programming proved to be a tremendously
55
difficult task, especially when "GOTO" statements constantly interrupted
56
the linear flow of a program. Functional programming overcame this
57
difficulty by defining stand-alone procedures that had predefined inputs
58
and outputs along with a concept called **local scope**, which is
59
a tremendous improvement that allowed much flexibility with variable
60
names and allowed the programmer to remove the dependence on global data.
61
This paradigm is still very much valid today and greatly improved the
62
process of code development.
63
64
65
Another programming paradigm, called **object oriented programming**
66
(OOP), was created in the 1960s to allow programmers to structure
67
their code as objects that interact with each other. It ushered-in
68
an era where the complexity of a computer programming could be limitless
69
and the ease of comprehension of computer programs could be increased
70
by relating code concepts to real world objects. This paradigm grew
71
very popular and successful. It allowed for an alternative to the
72
control blocks used in procedural programming and allowed programs to
73
reduce or even eliminate cache-misses (a performance aspect). It's
74
success however, was not long-lived, as the difficulties associated
75
with this paradigm became apparent. One such difficulty was that a
76
program's evolution became dependent on the underlying architecture/layout
77
of objects. If the architecture was flawed from the start the program's
78
development would eventually grind to a halt, where additions or
79
modifications became near impossible.
80
81
OOP allows for the implementation of advanced concepts some of them
82
plagued with tremendously risk. Concepts such as inheritance
83
and encapsulation offered many rewards whilst simultaneously introducing
84
problems.
85
86
<b>Inheritance</b> allows one to define a parent class of objects,
87
with associated procedures called methods, that provide basic
88
functionality that can be used or specialized by child classes.
89
A typical example is a parent class "solver" specialized
90
into "diffusion-solver" or "transport-solver". The concept is
91
useful in many circumstances and is generally very successful if
92
not for the risk of creating categorical hierarchies that ultimately
93
become unmanageable. Inheritance ultimately allows programmers
94
to "program" their code into a corner, from which there is no escape
95
other than to refactor large portions of
96
architecture (if not the whole architecture). In scientific programs,
97
where we need to solve a multitude of different kinds of problems,
98
inheritance can create such a large hierarchical depth that the
99
program becomes very dependent on the programmer's knowledge of
100
the underlying architecture and less on the actual knowledge of
101
problem-solving techniques. Therefore, when the program grows beyond
102
a certain level of complexity, it can be more efficient to write
103
specialized code from scratch than to devote the time to learn and
104
comprehend the hierarchy. Inheritance is not dispensable however,
105
and has a very unique place in modern programming. The ultimate
106
solution is to keep scientific program to a very shallow level of
107
inheritance in order to minimize the hierarchical depth of the
108
architecture.
109
110
<b>Encapsulation</b> allows certain data items of an object to
111
be **private** and therefore protected from incorrect
112
manipulation. It has provided great utility and will be a key
113
feature for many applications but unfortunately the concept also
114
fuels the over-engineering of data structures. This is because
115
objects that are over-encapsulated, cannot easily be modified by
116
procedures living in a FP paradigm, reducing the compatibility of
117
FP with OOP. Architectures that require perfect protection through
118
encapsulation often exhibit an overwhelming focus on the actual
119
"encapsulation" and less focus on the actual working code. There is
120
a healthy trade-off between creating accessor/mutator
121
functions (i.e., getters/setters) and how likely it is that unprotected
122
access will cause undetected problems. In most cases scientific
123
programmers should be more reliant on unit-tests as compared to
124
encapsulation.
125
\n
126
\n
127
The modern focus of scientific programs should be a healthy balance
128
between OOP and FP and therefore Chi-Tech follows such a paradigm.
129
130
131
* */
doc
PAGES
ProgrammersManual
ReferenceContent
devman_A2_OOP_vs_Functional.h
Generated by
1.9.3