CSC/ECE 517 Fall 2010/ch1 1e vs

From Expertiza_Wiki
Jump to navigation Jump to search

CSC/ECE 517 Fall 2010/ch1 1e vs


Introduction

This article compares and contrast block-structured languages and Object Oriented languages and also focuses on the advantages of Object-Oriented languages over the Block-structured languages. It also emphasizes on the usage of block structures in Object-Oriented programming.

What is a Block-Structured Language?

A block is a section of code which is grouped together and consists of one or more declarations and statements.

A block structured programming languages is a class of high level programming languages that allows the creation of blocks and includes the nested blocks as components where nesting could be extended to any depth. Block structured languages have a syntax such that the structures are enclosed within the bracketed keywords like if....fi in ALGOL language.

An example of a block in ALGOL looks as shown below:

begin

integer N;
Read Int(N);
begin
real array Data[1:N]
real sum,avg;
sum:=0;
for i:=1 step 1 until N do
begin real val;
Read Real (val);
Data[i]:=if val<0 then -val else val
end;
for i:=1 step 1 until N do
sum:=sum+Data[i];
avg:=sum/N;
Print Real(avg);
end

end

What is an Object-Oriented Programming?

Object-Oriented programming is a programming paradigm using "objects"- the data structures which consists of data fields and methods together with their interactions to design the applications and computer programs. The programming techniques include features like data abstraction, encapsulation, messaging, polymorphism and inheritance. It is a type of programming language where the programmers define not only the data type of a structure but also the type of functions that can be applied to the data structure.

An example of the code from JAVA language is as follows:

Class HelloWorld
{
public static void main(String args[])
{
System.out.println("Hello world!"):
System.out.println("Arguments you have entered is:");
(if args.length>0)
{
for(int i=0;i<args.length;i++)
{
System.out.print(args[i]+" ");
}
System.out.println();
}
else
System.out.println("<<No Arguments>>");
}
}