CS441 - Group Project #4
Comparison of
Object-oriented Languages to
- Functional Languages
- Logic-based Languages
Marcus Garrett
Jeff Heckathorn
Tom Heffron
Sedric Hibler
Ali Wajid
Due Date:
December 2, 2002
History
Comparison
Marcus Garrett
versus
Functional
Object-oriented
programming began in the form SIMULA, and later became the class
of programming language to which C and C++ belong. SIMULA I and
Simula 67 were the two first object-oriented languages. The Simula
family of
languages were developed at the Norwegian Computing Center, Oslo,
Norway by Ole-Johan Dahl and Kristen Nygaard. Simula 67 created
the concept of a class, so that it would have the capability for
concurrency of objects rather than of tasks. It introduced most of
the main concepts of object-oriented programming: classes,
inheritance and virtual procedures. These features - combined with
safe referencing and mechanisms for bringing into a program
collections of program structures described under a common class
heading - marked the semblance of object-oriented programming. Simula 67 still is being used today, but its main impact has been
in its introduction of one of the main categories of programming,
object-oriented programming.
Bjarne Stroustrup started his development of C++ (in the 1980s) by
bringing the key concepts of Simula into the C programming
language. Simula has also inspired much work in the area of
program component reuse and the construction of program libraries.
Object-oriented programming is today (in the late 1990s) becoming
the dominant style for implementing complex programs with large
numbers of interacting components.
Functional programming language came from the need for a language
that could handle artificial intelligence. John McCarthy first
developed the first functional language LISP in the late 1950s at
the Massachusetts Institute of Technology. LISP programming
systems are interpreters. The LISP language is rooted on the
representational power of "S-expressions" and use of functional
composition and recursion. LISP is a weakly typed language which is
ideal for on-the-fly code generation and interpreting. Its extreme
flexibility, power, and its ability to treat code as data, made it
the ideal of Artificial Intelligence research during 1970s and
1980s. Dozens of LISP implementations have been built over the
years, many of them were inspired by MacLISP. Eventually the
designers of the descendants of MacLISP convened and developed a
standard for LISP systems called 'Common LISP'.
The concepts of these languages do not mirror each other. The
reasons for creating these languages satisfied two rather different
communities. While logic languages were developed for the
scientific and mathematical community, object-based languages were
developed for the business sector. One characteristic they did
share was their use in the academic community. Both languages are
used extensively to teach programming at universities across the
world. Object-based languages such as C++ are used to teach the
basics of programming and functional languages such as LISP are
used to teach artificial intelligence.
versus
Logic-based
Logic programming is an approach to computer
science in which the first order predicate logic is used as a high
level programming language. The history of logic programming
started with symbolic logic, and then First Order Predicate Logic
emerged from symbolic logic to form the base for Logic
Programming. Prolog is the most viable and widely used logic-based
language. Prolog (short for PROgramming LOGic) was designed within the realm
of Artificial Intelligence (AI). It originally became popular with
AI researchers, who want to know more about "what" and "how" intelligent
behavior is achieved. The philosophy behind it deals with the
logical and declarative aspects. Prolog represents a fundamentally
new approach to computing and became a serious competitor to LISP.
Again, these two languages were born for different reasons.
Object-based languages were conceived to give the programmer more
flexibility than the programming languages in existence at the time.
Object-based languages filled the niche to create software for the
business community. Logic programming languages were created to
research artificial intelligence. It was developed process a set
of rules and a have control structure on those rules. This is a
vast departure from object-based languages where the control
structure is designed and methodical. Logic programming languages
use predicate calculus to prove theorems stored on in a database
structure and the driver makes decisions based on the theorems.
Overview Comparison
Marcus Garrett
versus Functional
Functional languages create programs
that model mathematical functions where as object-based languages
place an emphasis on designing programs through the use of
objects. All computation in a functional program is accomplished
by applying functions to arguments. Functional languages rely on
the relationship between components of a program, as well as
external libraries, subprograms, and functions. There is no
top-down sequence of commands in a functional language, but rather
a number of independent functions operate together to produce a
desired result. Functional languages and object-based languages
have similarities in their design. The difference is that
object-based languages place an emphasis on encapsulation and
abstraction. Object-based languages feature such concepts as:
encapsulation/information hiding, inheritance,
polymorphism/dynamic binding, all pre-defined types are objects,
all operations performed by sending messages to objects, and all
user-defined types are objects. Object-based languages have a lot
of features that offer the programmer the ability to do great
things, but all of which make it easy to write unreadable and
unusable programs. Because very little is needed to maintain in
Object-based language programs, they have low overhead and good
performance.
Functional references (for Sections
1 and 2):
1)
http://www.ifi.uio.no/~kristen/FORSKNINGSDOK_MAPPE/F_OO_start.html
2)
http://www.parallelism.cs.ncl.ac.uk/objectives/
3)
http://java.sun.com/docs/books/tutorial/java/concepts/
4)
http://www.cyberdyne-object-sys.com/oofaq2/
5)
http://www.cs.nott.ac.uk/~gmh//faq.html
6)
http://www.wikipedia.org/wiki/Functional_programming
versus Logic-based
Where logic-based languages were used to
create innovative computer systems such as artificial intelligence
research, object-based languages were used in the academic and
business realm. Logic-based languages were designed to be able to handle
complex functions, but where not limited to only mathematical
expressions. Prolog is the highest level logic-based language
widely used today. It is taught with an emphasis on thinking of
the logical relations between objects or entities relevant to a
given problem, rather than on procedural steps necessary to solve
it. . The system in which it is programmed decides the way to
solve the problem, including the sequences of instructions that
the computer must go through to solve it. The features of
object-based languages such as abstraction, encapsulation,
inheritance, and polymorphism provide for a good learning base.
These features also contribute to its popularity in the business
world. They provide for easy maintenance and portability
decreasing costs and increasing code reusability.
Logic-based references (for Sections 1
and 2):
1)
http://www.ifi.uio.no/~kristen/FORSKNINGSDOK_MAPPE/F_OO_start.html
2)
http://www.parallelism.cs.ncl.ac.uk/objectives/
3)
http://java.sun.com/docs/books/tutorial/java/concepts/
4)
http://www.cyberdyne-object-sys.com/oofaq2/
5)
http://cs.wwc.edu/~aabyan/221_2/PLBOOK/Logic.html
6)
http://www.biocheminfo.org/moirai/cs_magenta/prolog.html
7)
http://www.cs.waikato.ac.nz/~marku/languages.html
Handling of
Data Objects
Sedric
Hibler
According to
Aqua Phoenix ("Intro to
Object Oriented Programming"), object-oriented programming was not
invented for uncomplicated handling of graphical components, but
rather for uncomplicated handling of data objects. Useful programs do
not just dump data into text areas; instead, they organize data in
data structures, which are also objects in object oriented
languages. Object-based programming languages can store data as
integer, decimal, Boolean, character, arrays, pointers, and
strings. At the same time they allow for the creation of abstract
data types that can be encapsulated with functions to form an
object.
In object-oriented programming languages, data is stored and
retrieved via methods in the object. However, data is not simply
dumped into the object; the object makes sure that data is stored
in a correct fashion. In order to organize data, the object has
certain variables that may only be changed by the object itself.
Certain variables and methods are declared as private members,
which means that only the class itself is allowed to change the
value. Public and protected data types are also available.
Object-Based languages are typically strongly typed languages.
Inheritance allows an abstract data type to inherit all the data
and functionality of an existing type. Classes help to model
real-world objects and situations. They can be comprised of a
number of different data types.
versus Functional
Functional languages are type-less (in
general), compared to object oriented languages, which are not
type-less. The value of an object is determined during the
execution of the program. Some functional languages have added
some general data types, like integers and characters. Both
programming styles allow user defined types. Functional languages
use linked lists as their primary data structure. A major
difference between functional languages and object-oriented
languages is the support for abstract data types and inheritance
that is allowed in object-based languages.
versus Logic-based
Logic-based languages allow dynamic
binding (where data definitions can be changed during program
execution). One exception noted was that Prolog's 'constants'
values cannot change during program execution, which is where
their name comes from. We also find that logic languages can
create dynamic structures, as object based languages can. Logic-based
languages consist of terms, which include constants, variables,
and structures. These terms consist of integers and characters.
However, logic languages don't make use of many basic data types,
including arrays and classes, like the object-oriented languages.
References:
1)
http://www.aquaphoenix.com/research/oop/lecture17.html
2)
http://t.students.umkc.edu/tehqnf/CS441/cs441proj1.htm
3)
http://t.students.umkc.edu/tehqnf/CS441/cs441proj2.htm
4)
http://t.students.umkc.edu/tehqnf/CS441/cs441proj3.htm
5)
http://r.students.umkc.edu/rjjkr7/CS%20441/project_1.htm
6)
http://k.students.umkc.edu/kmtvd3/CS441/CS441_PROJECT1.doc
7)
http://c.students.umkc.edu/cbdn92/REVISEDproject1.doc
8)
http://a.students.umkc.edu/alpvwb/project1.htm
9) Sebesta,
Robert. Concepts of Programming Languages, Sixth Edition.
Reading, Massachusetts: Addison-Wesley, 2001.
Handling of
Sequence Control
Jeff Heckathorn
The
object-based family of programming languages has it’s sequence
control semantics in common with the sequence control semantics of
the block-structured, procedural family. The object-based family
as an imperative language type executes each line of code
sequentially from first to last with the flow control statements
altering the next line of program execution to meet the needs of
the programmer. The object-based languages allow for looping
controls such as the For loop and the While loop. They also allow
for if then branching statements for sequence or branch selection.
They also allow for multi-way branching statements. The
object-based languages heave language semantics for function calls
within a program and user defined program library calls, which are
also a form of sequence control.
versus
Functional
The functional
programming languages have their sequence control designed around
mathematical functions. These functions use recursion and
conditional expressions for control of flow. The example languages
of Scheme, and LISP have two basic sequence control elements. One
element controls two-way branching that includes If or For
selections. The second is a multiple selector COND function
allowing for multiple path function. The Functional language
semantics are different enough from the object-based to make
direct comparison difficult.
versus
Logic-based
The logic-based
programming languages such as Prolog and Mercury have their
program execution based on first order predicate calculus. The
program execution is much different than the object-based language
family. At face value both families, when the syntax is compared,
have no recognizable sequence control constructs in common. Prolog
as an example of the logic-based programming languages uses
predicate statements and most sequence control is used with
recursive predicate statements.
References:
1)
http://t.students.umkc.edu/tehqnf/CS441/cs441proj1.htm
2)
http://m.students.umkc.edu/mkb5e9/CS441/project1.htm
3)
http://y.students.umkc.edu/yl7e4/cs441/SIMULA.doc
4)
http://k.students.umkc.edu/kmtvd3/CS441/CS441_PROJECT1.doc
5)
Luger, George. “Artificial Intelligence Structures and Strategies
for Complex Problem Solving” 4th edition 2002.
Handling of
Subprograms & Storage Management
Ali Wajid
versus
Functional
Object-based
languages and functional languages both allow users to use
subprograms to avoid writing the same code again and again.
Object-based languages appear to have built-in functions that
programmer can make use of when writing programs - they have to
include the library in which those built-in functions are defined
and then the functions already defined in the library can be
easily use. Functional languages have primitive functions and
functional forms defined for programmers. Functional languages,
such as Scheme and LISP, allow complex functions to be constructed
by using set of these primitive functions and functional forms.
To create subprograms in Scheme, which is a functional language,
'lambda syntactic form' is used. Subprograms in functional languages
may include other subprograms. Functional programming languages
seem to have very simple and small subprograms. Subprograms in
functional languages are limited in size and scope, and
programmers have to be really careful when implementing these
subprograms. It is up to the programmer to combine these
subprograms efficiently to work together. The object-based
language group, however, is much more advanced when it comes to
functions. Functions in object-based language group can be defined
as public, private, and protected. Most object-based languages
allow functions to be overloaded. So, functions can have same name
but work on different data types depending on the arguments passed
to the functions and their return type. Object-based languages
also allow parameters to be passed as call-by-reference and
call-by-value. Parameters can be of any type that is already
defined either in the language of that group or by the programmer.
For example, parameters of type integer, char, string, etc. are
allowed to be passed to functions or subroutines.
Both language groups seem to have strong support for recursion
because sometimes problems can be solved easily using recursion
than using other method. Subprograms in object-based languages
always have a name, but subprograms in functional languages may or
may not have a name. In Object-based languages, results are stored
in memory, which is done using variables in the program. On the
other side, functional languages do not use variables in the
program, and that’s why the programmer does not have to worry
about the memory cells on which the program is executed.
Most object-based languages give flexibility to the programmer.
Some of the languages in this group, such as Simula, tends to
support automatic memory management by implementing a garbage
collector that automatically frees the memory that has been
allocated. C++ on the other hand, which also belongs to
object-based language group, does not support automatic garbage
collection, so the programmer has to de-allocate memory using the
keyword delete. Similarly, Functional languages also give just as
much freedom to programmers as object-based languages as far as
memory management is concerned. In functional languages, such as
Scheme, programmers do not have to explicitly de-allocate objects.
Storage management system automatically takes care of freeing the
space once it determines that the object is no longer being used
in the program.
versus
Logic-based
Object-based
languages and logic-based languages differ from each other when it
comes to subprograms. In logic-based languages, such as Prolog,
subprograms are used to describe logical relationships between
facts. According to our understanding, object-based languages
allow recursion in subprograms. So, subprograms in object-based
languages are allowed to call themselves. On the other hand,
logic-based languages have no support for recursion what so ever.
So, subprograms are not allowed to call themselves in logic-based
languages.
Object-based languages have two types of variables - namely global
and local. In Prolog, which belongs to logic-based language
family, variables are visible everywhere in the program. It does
not matter where we declare variables in Prolog, all variables
work as global variables. Our understanding is that all variables
can be seen and changed by the code in the main program or by the
subprograms.
Object-based and logic-based languages both allow dynamic
allocation of memory. Object-based languages and logic-based
languages both use garbage collection to handle storage management
automatically. Garbage collection gives the programmer more
flexibility and decreases the chances of memory leaks.
References:
1)
http://t.students.umkc.edu/tehqnf/CS441/cs441proj2.htm
2)
http://t.students.umkc.edu/tehqnf/CS441/cs441proj3.htm
3)
http://y.students.umkc.edu/yl7e4/cs441/SIMULA.doc
4)
http://k.students.umkc.edu/kmtvd3/CS441/CS441_PROJECT1.doc
5)
http://c.students.umkc.edu/cbdn92/REVISEDproject1.doc
6)
http://r.students.umkc.edu/rjjkr7/CS%20441/project_1.htm
7) Sebesta,
Robert. Concepts of Programming Languages, Fifth Edition.
Reading, Massachusetts: Addison-Wesley, 2000.
Handling of Abstraction and
Encapsulation
Tom Heffron
As described in
project 3, most object-based
languages take their roots from simple and block-structured
procedural languages. They build upon the capabilities of modules
and code blocks by adding inheritance, function overriding, and
polymorphism in order to fully abstract data elements and their
associated procedures. Encapsulation of those data types aid the
programmer in organizing very large-scale projects by allowing
separate compilation units and generic data types that are
initialized at run time.
versus Functional
Since functional languages
focus more on the functions used to solve a problem,
this family concentrates on the abstraction of its procedures
rather than the abstraction of the data. Functional languages are designed to mimic mathematical
functions, so they are less concerned with the underlying
architecture of the hardware. They do not worry about abstracting
the individual tasks in order to abstract memory cell and register
movement. Most functional languages give a programmer the ability
to abstract some complex functions by defining a ‘feeder function’
that will redirect the data types passed to the function into
other detailed functions to perform the work - but this is more of
an organizational aid.
Encapsulation is a bit of a non-issue in functional programming.
There is a logical organizational break between functions and each
is relatively self-contained. A programmer need only ensure that
any call to an ‘external’ function can be accessed by the program.
versus Logic-based
It is difficult to directly compare
data abstraction in object-oriented languages to logic-based
languages. Encapsulation in the logic-based family is simply a way
to expand its ‘world of knowledge’. This means that new
declarations and statements can be seen by a calling program in
order to solve a new problem. A programmer must be concerned that
any call to ‘external knowledge’ must be preceded with the name of
that module in which it resides – and the predicates will then
have direct access to the data in that module. Therefore, the
programmer must have direct access to the declarations of that
module – and data hiding becomes difficult.
Some logic-based programs were not
designed for large-scale projects and do not include support for
shareable, reusable code. Others, such as Mercury, do implement
reusable code in modules - allowing data declarations and
predicates to either be totally hidden or completely seen by the
calling program.
References:
1)
http://c.students.umkc.edu/cbdn92/REVISEDproject1.doc
2)
http://t.students.umkc.edu/tehqnf/CS441/cs441proj1.htm
3)
http://t.students.umkc.edu/tehqnf/CS441/cs441proj3.htm
4)
http://r.students.umkc.edu/rjjkr7/CS 441/project_1.htm
5)
http://y.students.umkc.edu/yl7e4/cs441/SIMULA.doc
6)
http://k.students.umkc.edu/kmtvd3/CS441/CS441_PROJECT1.doc
7) Louden, Kenneth C. Programming Languages Principles and
Practice. Boston: PWS Publishing Company, 1993.
8) Sebesta,
Robert. Concepts of Programming Languages, Fourth Edition.
Reading, Massachusetts: Addison-Wesley, 1999.