Make your own free website on Tripod.com

Project 4

Group Members:

VALLURI Vamsidhar, WONG Mei Fun , YEE Meng Yi and ZHANG Jingyuan

 

Compare and Contrast

1. Object-Based and Functional
2.
Object-Based and Logic

 

Object Based and Functional

Reference:
Java J. Steve Mohr, Carrie Neer, Madhukiran Moturu, Prashant Narayanan
Scheme Vamsidhar Valluri, Meng Yi Yee, Jingyuan Zhang, and Mei Fun Wong

History

The first object-based programming language was Simula 67; however, object-based language was not completely developed until Smalltalk, developed in the late 1960s. Some examples of the object-based language family are Java, Ada, C++, and Eiffel.

In recent years, one of the most widely used languages in the object-based family is Java. The development of Java was first started in December 1990 and was introduced on May 23, 1995.

The first functional programming language is Lisp, but some believe that it no longer represent the latest design concepts for functional languages. Functional programming language Scheme was introduced in 1975 by Guy L. Steele Jr. as the first dialect of Lisp. Initially, it was used for research and teaching, supporting only a handful of predefined syntactic forms and procedures. Now, Scheme is a general-purpose language. Some other members of the functional programming language family are Lisp, Common Lips, ML, and Haskell.

 

Overview of Language

Object-based language must provide support for three key language features: abstract data types, inheritance, and a particular kind of dynamic binding. All computing in a pure object-based language is done by sending a message to an object to invoke one of its methods. It is used to model and solve real world problems. Java for example, can be run on different kinds of computers. It is popular because of its platform independence. It has become the language and the platform, and the architecture for computing on the network.

The purpose of the design of a functional programming language is to imitate mathematical functions as much as possible. As a result, functional programming languages approach problem solving differently from methods of imperative languages. They provide a set of primitive functions, a set of functional forms to construct complex functions, a function application operation, and some structures for representing data. They are often implemented with interpreters and occasionally with compilers.

 

Handling of Data Objects

Classes are used in Object-based language. They provide data abstraction and can store many functions and variables within. Java includes primitive data types such as numbers, characters, and Boolean values; and it also includes reference data types such as objects and arrays. Classes are also used in Java. They allow the user to create sophisticated user-defined variables, and they allow for inheritance.

In functional language, lexical scoping and first class handling are used to handle data objects. Objects are dynamically allocated in a heap and retained until no longer needed. In Scheme, objects are considered first-class data values since they are heap allocated and retained indefinitely. They may be passed freely to procedures, returned as values from procedures and combined to form new objects.

 

Handling of Sequence Control

Both Object based and functional languages support conditional statements such as if-statements, loops, recursion, and iterations. Both support mathematical operators such as +, -, *, /. In object based language such as Java or C++, data stored in side the object changes only through the interface methods provided by the object. In the functional programming language Scheme, the order of the procedure and argument expressions are evaluated unspecified. It may be left to right, right to left or some arbitrary order. However, evaluation is guaranteed to be sequential.

 

Handling of Subprograms and Storage Management

Object-based languages support functions and procedures, and they can be very sophisticated. These subprograms can be defined in many different types such as int, float, double, long int, void. They can be overloaded and the parameters may be pass-by-value or pass-by-reference. Class is one of the main features of object-based language. It is allowed to store other data types and many functions inside it. In object-based language, storage may be dynamically allocated by pointers, or statically allocated. Garbage collection functions may be used to delete unwanted storage.

Like object-based languages, functional languages also use garbage collection to save memory space. Objects are dynamically allocated. In Scheme, objects are dynamically allocated in a heap where they are kept until no longer needed, then automatically deallocated. In both groups of language families, large functions can be created by using smaller and simper functions. Both groups allow recursive and simple call-return functions.

 

Handling of Abstraction and Encapsulation

Object-based languages can support very sophisticated and high level abstractions. Class can be commonly used for abstractions. It can be defined as an abstraction for a collections of data and operations. Encapsulation allows the data to remain absolutely within the object. The use of class allows for inheritance. Unlike other object-based language such as C++, every line of code written Java must be embedded in an object. Abstractions can also be accomplished through creating subprograms within a program or other subprograms.

Functional languages are also heavily abstracted. Like object-based languages, it can form abstractions by creating subprograms inside other subprograms or programs. A large portion of the executable code of any functional programs is stored in external functions and libraries. Many functions are currently available as encapsulations of standard functional language libraries. Scheme for example, has built-in procedures to process data.

^ Back to Top 

 

Object Based and Logic

Reference:
Java compiled by John Mohr, Madhukiran Moturu, Prashanth Narayanan and Carrie Neer
Prolog compiled by Linda Shipp, Jie Song, Rong Hai Shi and Jamie Stephens

 

 

History

 

The development of Java was started on December 1990 containing 3 members in a group. Years after years, the group became bigger which have 14 members in 1992. Java was introduced on May 23, 1995. Originally, Java was called Oak. The name of Oak was changed by Sun Microsystem because of marketing purpose.

Prolog which belongs to Logic based family was developed by Alain Colmerauer, Phillippe Roussel and Robert Kowalski during the very early 1970s. These languages are used in artificial intelligence. Prolog supplies to computer, relevant information and inferencing process for computing desirable results.

 

 

Overview of Language

 

Java is a software that can run on all different kinds of computers and electronic devices. Java allows computers and electronic devices to communicate with each other easily. Java has become the language, and the platform, and the architecture for computing on the network. Java is profitable for corporation by cutting the costs associated with developing software for multiple platforms. Also, Java is secure for use over the Internet. Java is accepted as a powerful fourth generation programming language.

 

Prolog is significantly different from conventional procedural programming and requires a readjustment in the way one thinks about programming. Prolog statements are facts, rules or goals.  Logical relationships are asserted, and Prolog is used to determin e whether or not certain statements are true, and if true, what variable bindings make them true.  This mode of programming essentially tells the computer what is true and what needs to be done rather than how to do it.  This allows the programmer to focus their energies on problem solving specifications rather than the details of written low-level control code.

 

 

 

Handling of Data Object

 

Objects in Java are expressed in two kind of data type (primitive type and reference type) where as objects in Prolog is expressed in terms. Primitive type in Java represents simple values that have built-in functionality in the languages, for instance, literal, constants and numeric expression. Reference type includes objects and arrays. They are called reference type because they are passed "by reference". On the other hand, term is basic structure in Prolog. There are four basic terms in Prolog: variables, compound term, atoms and form of term. Term is expressed in form name (argument…). In addition, Java widely uses objects and arrays and Prolog widely uses list as its data structure.

Another point of difference is that Java does not use pointer arithmetic. This means that primitive type can never be cast a reference type and vice versa. In fact, the referencing and dereferencing of objects and arrays is handled automatically by Java.

Also, Prolog doesn't use the abstract data types in programming. It only uses the term. Prolog uses the term to express everything including program and data.

 

Handling of Sequence Control

Java's execution is governed by statements and expressions that appear in a code block. A code block is a syntactically just a number of statements surrounded by braces. Prolog, on the other hand, has execution governed by control mechanism built into the interpreter. The programmer has command over broad details such as in which computations are developed, but finer details such as management of the binding history can be left to the interpreter to sort out.

Another difference between Java and Prolog is that Java has explicit and conditional statements such as If statement, While statement and For loop statement. Prolog does not have explicit and conditional statements that Java has. Statements in Prolog correspond to the head and headless Horn Clauses of predicate calculus. These statements are facts, rules and goals. The programming of these statements tells the computer what is true and what needs to be done rather than how to do it.

Furthermore logic base programming language like Prolog supports ‘backtracking’. Its objective is to obtain a particular goal, which automatically do the backtracking to find the solutions. This method is different from object based languages because prolog users logic statement and structures

 

Handling of Subprograms and Storage Management

In object based, subprograms comprise of functions, procedures and modules, which make the program modular and easy to understand. Functions are rather easy to debug and may or may not return a value. There exist both global variables and local variables. Modules in object base programming languages provide means of packaging global data, derived types and associated operations, interface blocks, and name list groups.

In logic-based languages procedures are often recursive and include some built in predicates. They may be difficult to debug. Recursive functions are a useful tool but require a lot of storage space.

Logic based language Prolog has no dynamic allocation for storage management, where most block-structured languages have both static and dynamic allocation

In addition, Prolog does not support the same storage ability for arrays in Java. Instead, an indexing system is implemented that is similar to arrays. This type of storage, however, does not promise quick retrieval as Prolog does not follow the same sequential storage.

 

Handling of Abstraction and Encapsulation

Abstraction and encapsulation is represented in classes in Java. Classes in Java can be defined into several types by using modifiers to define the accessibility of the object in the program.

Logic-based languages, in this case, Prolog has no real abstraction because complex data structures is actually based on simple data structures of atomic prepositions while lists provide a type of abstraction and encapsulation for data.

^ Back to Top 

 

Additional References

Sebesta, Robert W. Concepts of Programming Languages. Berkeley: Addision-Wesley

Longman, Inc., 1999.