<s>
Imperative	B-Application
programming	I-Application
–	O
focuses	O
on	O
how	O
to	O
execute	O
,	O
defines	O
control	O
flow	O
as	O
statements	O
that	O
change	O
a	O
program	O
state	B-Application
.	O
</s>
<s>
Declarative	B-Language
programming	I-Language
–	O
focuses	O
on	O
what	O
to	O
execute	O
,	O
defines	O
program	O
logic	O
,	O
but	O
not	O
detailed	O
control	O
flow	O
.	O
</s>
<s>
Procedural	B-Application
programming	I-Application
–	O
specifies	O
the	O
steps	O
a	O
program	O
must	O
take	O
to	O
reach	O
a	O
desired	O
state	B-Application
.	O
</s>
<s>
Functional	B-Language
programming	I-Language
–	O
treats	O
programs	O
as	O
evaluating	O
mathematical	O
functions	O
and	O
avoids	O
state	B-Application
and	O
mutable	B-Application
data	O
.	O
</s>
<s>
Object-oriented	B-Language
programming	I-Language
(	O
OOP	O
)	O
–	O
organizes	O
programs	O
as	O
objects	O
:	O
data	B-General_Concept
structures	I-General_Concept
consisting	O
of	O
attributes	B-General_Concept
and	O
methods	B-Language
together	O
with	O
their	O
interactions	O
.	O
</s>
<s>
Event-driven	B-Application
programming	I-Application
–	O
program	O
control	O
flow	O
is	O
determined	O
by	O
events	O
,	O
such	O
as	O
sensor	O
inputs	O
or	O
user	O
actions	O
(	O
mouse	B-Device
clicks	O
,	O
key	O
presses	O
)	O
or	O
messages	B-Architecture
from	O
other	O
programs	O
or	O
threads	B-Operating_System
.	O
</s>
<s>
Automata-based	B-Application
programming	I-Application
–	O
a	O
program	O
,	O
or	O
part	O
,	O
is	O
treated	O
as	O
a	O
model	O
of	O
a	O
finite	B-Architecture
state	I-Architecture
machine	I-Architecture
or	O
any	O
other	O
formal	O
automaton	O
.	O
</s>
<s>
Reactive	B-Architecture
programming	I-Architecture
is	O
a	O
declarative	B-Language
programming	I-Language
paradigm	O
concerned	O
with	O
data	B-Application
streams	I-Application
and	O
the	O
propagation	O
of	O
change	O
.	O
</s>
<s>
The	O
subroutines	O
that	O
implement	O
OOP	O
methods	B-Language
may	O
be	O
ultimately	O
coded	O
in	O
an	O
imperative	B-Application
,	O
functional	B-Language
,	O
or	O
procedural	B-Application
style	O
that	O
may	O
,	O
or	O
may	O
not	O
,	O
directly	O
alter	O
state	B-Application
on	O
behalf	O
of	O
the	O
invoking	O
program	O
.	O
</s>
<s>
Despite	O
multiple	O
(	O
types	O
of	O
)	O
programming	O
paradigms	O
existing	O
in	O
parallel	O
(	O
with	O
sometimes	O
apparently	O
conflicting	O
definitions	O
)	O
,	O
many	O
of	O
the	O
underlying	O
fundamental	O
components	O
remain	O
more	O
or	O
less	O
the	O
same	O
(	O
constants	O
,	O
variables	O
,	O
datafields	B-Application
,	O
subroutine	O
calls	O
etc	O
.	O
)	O
</s>
<s>
and	O
must	O
inevitably	O
be	O
incorporated	O
into	O
each	O
separate	O
paradigm	O
with	O
equally	O
similar	O
attributes	B-General_Concept
or	O
functions	O
.	O
</s>
<s>
One	O
example	O
of	O
syntactic	O
sugar	O
may	O
arguably	O
be	O
the	O
classes	O
used	O
in	O
object-oriented	B-Language
programming	I-Language
languages	I-Language
.	O
</s>
<s>
The	O
imperative	B-Application
language	I-Application
C	B-Language
can	O
support	O
object-oriented	B-Language
programming	I-Language
via	O
its	O
facilities	O
of	O
function	B-Language
pointers	I-Language
,	O
type	O
casting	O
,	O
and	O
structures	O
.	O
</s>
<s>
However	O
,	O
languages	O
such	O
as	O
C++	B-Language
aim	O
to	O
make	O
object-oriented	B-Language
programming	I-Language
more	O
convenient	O
by	O
introducing	O
syntax	O
specific	O
to	O
this	O
coding	O
style	O
.	O
</s>
<s>
Moreover	O
,	O
the	O
specialized	O
syntax	O
works	O
to	O
emphasize	O
the	O
object-oriented	B-Language
approach	O
.	O
</s>
<s>
Similarly	O
,	O
functions	O
and	O
looping	O
syntax	O
in	O
C	B-Language
(	O
and	O
other	O
procedural	B-Application
and	O
structured	B-Language
programming	I-Language
languages	O
)	O
could	O
be	O
considered	O
syntactic	O
sugar	O
.	O
</s>
<s>
Assembly	B-Language
language	I-Language
can	O
support	O
procedural	B-Application
or	O
structured	B-Language
programming	I-Language
via	O
its	O
facilities	O
for	O
modifying	O
register	O
values	O
and	O
branching	O
execution	O
depending	O
on	O
program	O
state	B-Application
.	O
</s>
<s>
However	O
,	O
languages	O
such	O
as	O
C	B-Language
introduced	O
syntax	O
specific	O
to	O
these	O
coding	O
styles	O
to	O
make	O
procedural	B-Application
and	O
structured	B-Language
programming	I-Language
more	O
convenient	O
.	O
</s>
<s>
Features	O
of	O
the	O
language	O
C#	B-Application
(	O
C	B-Application
Sharp	I-Application
)	O
,	O
such	O
as	O
properties	O
and	O
interfaces	O
,	O
similarly	O
enable	O
no	O
new	O
functions	O
,	O
but	O
are	O
designed	O
to	O
make	O
good	O
programming	O
practices	O
more	O
prominent	O
and	O
natural	O
.	O
</s>
<s>
In	O
total	O
instruction	B-General_Concept
path	I-General_Concept
length	I-General_Concept
only	O
,	O
a	O
program	O
coded	O
in	O
an	O
imperative	B-Application
style	O
,	O
using	O
no	O
subroutines	O
,	O
would	O
have	O
the	O
lowest	O
count	O
.	O
</s>
<s>
However	O
,	O
the	O
binary	O
size	O
of	O
such	O
a	O
program	O
may	O
be	O
larger	O
than	O
the	O
same	O
program	O
coded	O
using	O
subroutines	O
(	O
as	O
in	O
functional	B-Language
and	O
procedural	B-Application
programming	I-Application
)	O
and	O
would	O
reference	O
more	O
non-local	B-General_Concept
physical	O
instructions	O
that	O
may	O
increase	O
cache	O
misses	O
and	O
instruction	O
fetch	O
overhead	O
in	O
modern	O
processors	B-General_Concept
.	O
</s>
<s>
The	O
paradigms	O
that	O
use	O
subroutines	O
extensively	O
(	O
including	O
functional	B-Language
,	O
procedural	B-Application
,	O
and	O
object-oriented	B-Language
)	O
and	O
do	O
not	O
also	O
use	O
significant	O
inline	O
expansion	O
(	O
inlining	O
,	O
via	O
compiler	B-Application
optimizations	I-Application
)	O
will	O
,	O
consequently	O
,	O
use	O
a	O
larger	O
fraction	O
of	O
total	O
resources	O
on	O
the	O
subroutine	O
linkages	O
.	O
</s>
<s>
Object-oriented	B-Language
programs	O
that	O
do	O
not	O
deliberately	O
alter	O
program	O
state	B-Application
directly	O
,	O
instead	O
using	O
mutator	O
methods	B-Language
(	O
or	O
setters	O
)	O
to	O
encapsulate	O
these	O
state	B-Application
changes	O
,	O
will	O
,	O
as	O
a	O
direct	O
consequence	O
,	O
have	O
more	O
overhead	O
.	O
</s>
<s>
This	O
is	O
because	O
message	B-Architecture
passing	I-Architecture
is	O
essentially	O
a	O
subroutine	O
call	O
,	O
but	O
with	O
three	O
added	O
overheads	O
:	O
dynamic	B-General_Concept
memory	I-General_Concept
allocation	I-General_Concept
,	O
parameter	O
copying	O
,	O
and	O
dynamic	O
dispatch	O
.	O
</s>
<s>
Obtaining	O
memory	O
from	O
the	O
heap	O
and	O
copying	O
parameters	O
for	O
message	B-Architecture
passing	I-Architecture
may	O
involve	O
significant	O
resources	O
that	O
far	O
exceed	O
those	O
needed	O
for	O
the	O
state	B-Application
change	O
.	O
</s>
<s>
Accessors	O
(	O
or	O
getters	O
)	O
that	O
merely	O
return	O
the	O
values	O
of	O
private	O
member	O
variables	O
also	O
depend	O
on	O
similar	O
message	B-Architecture
passing	I-Architecture
subroutines	O
,	O
instead	O
of	O
using	O
a	O
more	O
direct	O
assignment	O
(	O
or	O
comparison	O
)	O
,	O
adding	O
to	O
total	O
path	O
length	O
.	O
</s>
<s>
For	O
programs	O
executing	O
in	O
a	O
managed	O
code	O
environment	O
,	O
such	O
as	O
the	O
.NET	B-Application
Framework	I-Application
,	O
many	O
issues	O
affect	O
performance	O
that	O
are	O
significantly	O
affected	O
by	O
the	O
programming	O
language	O
paradigm	O
and	O
various	O
language	O
features	O
used	O
.	O
</s>
<s>
A	O
pseudocode	B-Language
comparison	O
of	O
imperative	B-Application
,	O
procedural	B-Application
,	O
and	O
object	B-Language
oriented	I-Language
approaches	O
used	O
to	O
calculate	O
the	O
area	O
of	O
a	O
circle	O
( πr²	O
)	O
,	O
assuming	O
no	O
subroutine	O
inlining	O
,	O
no	O
macro	O
preprocessors	B-General_Concept
,	O
register	O
arithmetic	O
,	O
and	O
weighting	O
each	O
instruction	O
'	O
step	O
 '	O
as	O
only	O
1	O
instruction	O
–	O
as	O
a	O
crude	O
measure	O
of	O
instruction	B-General_Concept
path	I-General_Concept
length	I-General_Concept
–	O
is	O
presented	O
below	O
.	O
</s>
<s>
The	O
instruction	O
step	O
that	O
is	O
conceptually	O
performing	O
the	O
state	B-Application
change	O
is	O
highlighted	O
in	O
bold	O
typeface	O
in	O
each	O
case	O
.	O
</s>
<s>
The	O
arithmetic	O
operations	O
used	O
to	O
compute	O
the	O
area	O
of	O
the	O
circle	O
are	O
the	O
same	O
in	O
all	O
three	O
paradigms	O
,	O
with	O
the	O
difference	O
being	O
that	O
the	O
procedural	B-Application
and	O
object-oriented	B-Language
paradigms	O
wrap	O
those	O
operations	O
in	O
a	O
subroutine	O
call	O
that	O
makes	O
the	O
computation	O
general	O
and	O
reusable	O
.	O
</s>
<s>
The	O
same	O
effect	O
could	O
be	O
achieved	O
in	O
a	O
purely	O
imperative	B-Application
program	I-Application
using	O
a	O
macro	O
preprocessor	B-General_Concept
at	O
only	O
the	O
cost	O
of	O
increased	O
program	O
size	O
(	O
only	O
at	O
each	O
macro	O
invocation	O
site	O
)	O
without	O
a	O
corresponding	O
pro	O
rata	O
runtime	O
cost	O
(	O
proportional	O
to	O
n	O
invocations	O
–	O
that	O
may	O
be	O
situated	O
within	O
an	O
inner	O
loop	O
for	O
instance	O
)	O
.	O
</s>
<s>
Conversely	O
,	O
subroutine	O
inlining	O
by	O
a	O
compiler	O
could	O
reduce	O
procedural	B-Application
programs	O
to	O
something	O
similar	O
in	O
size	O
to	O
the	O
purely	O
imperative	B-Application
code	O
.	O
</s>
<s>
However	O
,	O
for	O
object-oriented	B-Language
programs	O
,	O
even	O
with	O
inlining	O
,	O
messages	B-Architecture
still	O
must	O
be	O
built	O
(	O
from	O
copies	O
of	O
the	O
arguments	O
)	O
for	O
processing	O
by	O
the	O
object-oriented	B-Language
methods	B-Language
.	O
</s>
<s>
The	O
overhead	O
of	O
calls	O
,	O
virtual	O
or	O
otherwise	O
,	O
is	O
not	O
dominated	O
by	O
the	O
control	O
flow	O
alteration	O
–	O
but	O
by	O
the	O
surrounding	O
calling	O
convention	O
costs	O
,	O
like	O
prologue	B-Language
and	I-Language
epilogue	I-Language
code	O
,	O
stack	O
setup	O
and	O
argument	O
passing	O
(	O
see	O
here	O
for	O
more	O
realistic	O
instruction	B-General_Concept
path	I-General_Concept
length	I-General_Concept
,	O
stack	O
and	O
other	O
costs	O
associated	O
with	O
calls	O
on	O
an	O
x86	B-Operating_System
platform	O
)	O
.	O
</s>
<s>
See	O
also	O
here	O
for	O
a	O
slide	O
presentation	O
by	O
Eric	O
S	O
.	O
Roberts	O
(	O
"	O
The	O
Allocation	O
of	O
Memory	O
to	O
Variables	O
"	O
,	O
chapter	O
7	O
)	O
–	O
illustrating	O
the	O
use	O
of	O
stack	B-General_Concept
and	I-General_Concept
heap	I-General_Concept
memory	O
use	O
when	O
summing	O
three	O
rational	O
numbers	O
in	O
the	O
Java	B-Language
object-oriented	B-Language
language	I-Language
.	O
</s>
<s>
call	O
area(r,result )	O
;	O
</s>
<s>
result	O
=	O
circle.area(r )	O
;	O
</s>
<s>
The	O
advantages	O
of	O
procedural	B-Application
abstraction	B-Application
and	O
object-oriented-style	O
polymorphism	B-Application
are	O
poorly	O
illustrated	O
by	O
a	O
small	O
example	O
like	O
the	O
one	O
above	O
.	O
</s>
<s>
This	O
example	O
is	O
designed	O
mainly	O
to	O
illustrate	O
some	O
intrinsic	O
performance	O
differences	O
,	O
not	O
abstraction	B-Application
or	O
code	O
re-use	O
.	O
</s>
<s>
The	O
extent	O
to	O
which	O
different	O
paradigms	O
use	O
subroutines	O
(	O
and	O
their	O
consequent	O
memory	O
requirements	O
)	O
influences	O
the	O
overall	O
performance	O
of	O
the	O
complete	O
algorithm	O
,	O
although	O
as	O
Guy	O
Steele	O
pointed	O
out	O
in	O
a	O
1977	O
paper	O
,	O
a	O
well-designed	O
programming	O
language	O
implementation	O
can	O
have	O
very	O
low	O
overheads	O
for	O
procedural	B-Application
abstraction	B-Application
(	O
but	O
laments	O
,	O
in	O
most	O
implementations	O
,	O
that	O
they	O
seldom	O
achieve	O
this	O
in	O
practice	O
-	O
being	O
"	O
rather	O
thoughtless	O
or	O
careless	O
in	O
this	O
regard	O
"	O
)	O
.	O
</s>
<s>
For	O
procedural	B-Application
programming	I-Application
,	O
the	O
granularity	O
of	O
the	O
code	O
is	O
largely	O
determined	O
by	O
the	O
number	O
of	O
discrete	O
procedures	O
or	O
modules	B-Architecture
.	O
</s>
<s>
For	O
object-oriented	B-Language
programming	I-Language
,	O
the	O
number	O
of	O
method	B-Language
calls	I-Language
invoked	O
is	O
also	O
partly	O
determined	O
by	O
the	O
granularity	O
of	O
the	O
data	B-General_Concept
structures	I-General_Concept
and	O
may	O
thus	O
include	O
many	O
read-only	O
accesses	O
to	O
low	O
level	O
objects	O
that	O
are	O
encapsulated	O
,	O
and	O
thus	O
accessible	O
in	O
no	O
other	O
,	O
more	O
direct	O
,	O
way	O
.	O
</s>
<s>
Since	O
increased	O
granularity	O
is	O
a	O
prerequisite	O
for	O
greater	O
code	O
reuse	O
,	O
the	O
tendency	O
is	O
toward	O
fine-grained	O
data	B-General_Concept
structures	I-General_Concept
,	O
and	O
a	O
corresponding	O
increase	O
in	O
the	O
number	O
of	O
discrete	O
objects	O
(	O
and	O
their	O
methods	B-Language
)	O
and	O
,	O
consequently	O
,	O
subroutine	O
calls	O
.	O
</s>
<s>
Performance	O
problems	O
caused	O
by	O
excessive	O
granularity	O
may	O
not	O
become	O
apparent	O
until	O
scalability	B-Architecture
becomes	O
an	O
issue	O
.	O
</s>
<s>
Uniquely	O
,	O
the	O
object-oriented	B-Language
paradigm	O
involves	O
dynamic	B-General_Concept
memory	I-General_Concept
allocation	I-General_Concept
from	O
heap	O
storage	O
for	O
both	O
object	O
creation	O
and	O
message	B-Architecture
passing	I-Architecture
.	O
</s>
<s>
A	O
1994	O
benchmark	O
-	O
"	O
Memory	B-General_Concept
Allocation	I-General_Concept
Costs	O
in	O
Large	O
C	B-Language
and	O
C++	B-Language
Programs	I-Language
"	O
conducted	O
by	O
Digital	O
Equipment	O
Corporation	O
on	O
a	O
variety	O
of	O
software	O
,	O
using	O
an	O
instruction-level	O
profiling	O
tool	O
,	O
measured	O
how	O
many	O
instructions	O
were	O
required	O
per	O
dynamic	B-General_Concept
storage	I-General_Concept
allocation	O
.	O
</s>
<s>
See	O
also	O
"	O
Heap:Pleasures	O
and	O
pains	O
"	O
by	O
Murali	O
R	B-Language
.	O
Krishnan	O
that	O
states	O
"	O
Heap	O
implementations	O
tend	O
to	O
stay	O
general	O
for	O
all	O
platforms	O
,	O
and	O
hence	O
have	O
heavy	O
overhead	O
"	O
.	O
</s>
<s>
The	O
1996	O
IBM	O
paper	O
"	O
Scalability	B-Architecture
of	O
Dynamic	B-General_Concept
Storage	I-General_Concept
Allocation	B-General_Concept
Algorithms	I-General_Concept
"	O
by	O
Arun	O
Iyengar	O
of	O
IBM	O
demonstrates	O
various	O
dynamic	B-General_Concept
storage	I-General_Concept
algorithms	O
and	O
their	O
respective	O
instruction	O
counts	O
.	O
</s>
<s>
The	O
above	O
pseudocode	B-Language
example	O
does	O
not	O
include	O
a	O
realistic	O
estimate	O
of	O
this	O
memory	B-General_Concept
allocation	I-General_Concept
pathlength	O
or	O
the	O
memory	O
prefix	O
overheads	O
involved	O
and	O
the	O
subsequent	O
associated	O
garbage	O
collection	O
overheads	O
.	O
</s>
<s>
Suggesting	O
strongly	O
that	O
heap	O
allocation	O
is	O
a	O
nontrivial	O
task	O
,	O
one	O
open-source	B-Application
software	I-Application
microallocator	O
,	O
by	O
game	O
developer	O
John	O
W	O
.	O
Ratcliff	O
,	O
consists	O
of	O
nearly	O
1,000	O
lines	O
of	O
code	O
.	O
</s>
<s>
In	O
their	O
Abstract	O
"	O
Optimization	O
of	O
Object-Oriented	B-Language
Programs	O
Using	O
Static	O
Class	O
Hierarchy	O
Analysis	O
"	O
,	O
Jeffrey	O
Dean	O
,	O
David	O
Grove	O
,	O
and	O
Craig	O
Chambers	O
of	O
the	O
Department	O
of	O
Computer	O
Science	O
and	O
Engineering	O
,	O
at	O
the	O
University	O
of	O
Washington	O
,	O
claim	O
that	O
"	O
Heavy	O
use	O
of	O
inheritance	B-Language
and	O
dynamically-bound	O
messages	B-Architecture
is	O
likely	O
to	O
make	O
code	O
more	O
extensible	O
and	O
reusable	O
,	O
but	O
it	O
also	O
imposes	O
a	O
significant	O
performance	O
overhead	O
,	O
relative	O
to	O
an	O
equivalent	O
but	O
non-extensible	O
program	O
written	O
in	O
a	O
non-object-oriented	O
manner	O
.	O
</s>
<s>
In	O
some	O
domains	O
,	O
such	O
as	O
structured	B-Language
graphics	O
packages	O
,	O
the	O
performance	O
cost	O
of	O
the	O
extra	O
flexibility	O
provided	O
by	O
using	O
a	O
heavily	O
object-oriented	B-Language
style	O
is	O
acceptable	O
.	O
</s>
<s>
However	O
,	O
in	O
other	O
domains	O
,	O
such	O
as	O
basic	O
data	B-General_Concept
structure	I-General_Concept
libraries	O
,	O
numerical	O
computing	O
packages	O
,	O
rendering	O
libraries	O
,	O
and	O
trace-driven	O
simulation	O
frameworks	O
,	O
the	O
cost	O
of	O
message	B-Architecture
passing	I-Architecture
can	O
be	O
too	O
great	O
,	O
forcing	O
the	O
programmer	O
to	O
avoid	O
object-oriented	B-Language
programming	I-Language
in	O
the	O
“	O
hot	O
spots	O
”	O
of	O
their	O
application.	O
"	O
</s>
<s>
Serialization	B-Application
imposes	O
large	O
overheads	O
when	O
passing	O
objects	O
from	O
one	O
system	O
to	O
another	O
,	O
especially	O
when	O
the	O
transfer	O
is	O
in	O
human-readable	O
formats	O
such	O
as	O
Extensible	B-Protocol
Markup	I-Protocol
Language	I-Protocol
(	O
XML	B-Protocol
)	O
and	O
JavaScript	B-General_Concept
Object	I-General_Concept
Notation	I-General_Concept
(	O
JSON	B-General_Concept
)	O
.	O
</s>
<s>
This	O
contrasts	O
with	O
compact	O
binary	O
formats	O
for	O
non-object-oriented	O
data	O
.	O
</s>
<s>
Both	O
encoding	O
and	O
decoding	O
of	O
the	O
object	O
's	O
data	O
value	O
and	O
its	O
attributes	B-General_Concept
are	O
involved	O
in	O
the	O
serializing	B-Application
process	O
,	O
which	O
also	O
includes	O
awareness	O
of	O
complex	O
issues	O
such	O
as	O
inheriting	O
,	O
encapsulating	O
,	O
and	O
data	B-Application
hiding	I-Application
.	O
</s>
<s>
Carnegie-Mellon	O
University	O
Professor	O
Robert	O
Harper	O
in	O
March	O
2011	O
wrote	O
:	O
"	O
This	O
semester	O
Dan	O
Licata	O
and	O
I	O
are	O
co-teaching	O
a	O
new	O
course	O
on	O
functional	B-Language
programming	I-Language
for	O
first-year	O
prospective	O
CS	B-Language
majors	O
...	O
Object-oriented	B-Language
programming	I-Language
is	O
eliminated	O
entirely	O
from	O
the	O
introductory	O
curriculum	O
,	O
because	O
it	O
is	O
both	O
anti-modular	O
and	O
anti-parallel	O
by	O
its	O
very	O
nature	O
,	O
and	O
hence	O
unsuitable	O
for	O
a	O
modern	O
CS	B-Language
curriculum	O
.	O
</s>
<s>
A	O
proposed	O
new	O
course	O
on	O
object-oriented	B-Language
design	O
methodology	O
will	O
be	O
offered	O
at	O
the	O
sophomore	O
level	O
for	O
those	O
students	O
who	O
wish	O
to	O
study	O
this	O
topic.	O
"	O
</s>
