CSC/ECE 517 Fall 2011/ch1 1e sa

From Expertiza_Wiki
Jump to navigation Jump to search

"Block and Object-Oriented Programming Languages" by Andrew Davis and Srikanth Ramachandran

In computer science, computer programming languages exhibit variance in syntax and structure in order to effectively solve problems. Two of these variances can be seen between block structure and object-oriented structure. A programming language with block structure allows the programmer to group lines of code so that they may be accessed as a single entity. Meanwhile, object-oriented structure allows the programmer to associate data with its actions in a hierarchical manner. Object-oriented structure has many advantages which generally make it more effective and durable than block-structured languages, but object-oriented languages also benefit from ideas present in block structure programming.

Block structure

Definition

Block-structured programming languages are task-centric, high-level languages. Operations on data sets are emphasized rather than the data itself in an attempt to logically organize program operation. The design and implementation involves breaking down the problem into discrete blocks, or units, which can be nested to any depth or not at all. Each block generally consists of a set of delimiters such as braces, indentation, and the like that separate them from other blocks. Each of these blocks contains a set of (optional) declarations and logic to solve a particular problem. Declarations inside of nested blocks introduces the concept of variable scope, which frees the programmer from having to worry about name collisions and other variable maintenance tasks.<ref>Block (programming) at Wikipedia</ref>

History

Block-structured languages were first conceived in the 1950s with the advent of ALGOL, one of the first imperative programming languages. An evolution of block structuring was created as the “GOTO” logic of programs became more and more difficult to understand and maintain. In 1968, famed computer scientist Edsger Dijkstra wrote a letter and follow-up article on the ideas and motivation behind “structured programming,” where the program exhibits “separation of concerns,” single point of entry but multiple points of exit, and ideas of data structures. It was Dijkstra’s and others’ which helped propel this basic idea of block structure programming into the mainstream.<ref>Structured programming at Wikipedia</ref>

Programming languages

Block-structured programming languages dominate the general purpose, imperative programming language arena. Indeed most programming languages in modern use enjoy some of the benefits of block structure with grouping of code and scope of variables. Indeed, ignoring their object-oriented aspects, all of C, C++, C#, Java, PHP and Visual Basic – for example – contain elements of block structure.

Object-oriented structure

Definition

Description

Object-oriented structured languages are data-centric, high-level languages. Compared to block-structure languages, logical organization of data and the methods associated with them are emphasized. It is a way of grouping data with executable code (called “objects”) that works with that data which exhibits attributes in a hierarchical manner (called “classes”). Toward this end and depending on the language, classes can be interrelated and defined so that their relationships can produce code that is well-organized, easy to read, and reusable.<ref name="oopref">Object-oriented programming at Wikipedia</ref>

Principles

Encapsulation

Also referred to as “data hiding,” encapsulation shields the programmer from the implementation details of an object. These implementation details would include private variables, special libraries, and data structures that the programmer does not need to know in order to utilize the functionality offered by the object.<ref>Encapsulation (object-oriented programming) at Wikipedia</ref>

Inheritance

Inheritance introduces the idea of objects sharing functionality in data or methods that are common. Subclasses can inherit data structures, functions, and attributes of their superclasses in order to create an object hierarchy that is effective in organizing data and methods in a logical manner.<ref>Inheritance (computer science) at Wikipedia</ref>

Polymorphism

Polymorphism describes the idea of interfaces, where one data type can be defined that allows other dissimilar types to implement a common set of methods and fields. This allows a high level of abstraction that allows programmers to write easily maintainable code.<ref>Polymorphism in object-oriented programming at Wikipedia</ref>

History and transition

Early forms of OOP were created in the early 1960s with the creation of LISP and an early form of ALGOL, with Simula 67 signaling the actual beginning of the OOP “revolution.” The development of OOP languages progressed through other languages like Smalltalk and the archetypal C++ to arrive at the OOP languages we have today.<ref name="oopref"/>

Programming languages

A complete list of object oriented languages is outside the scope of this document, but some major examples are Boo, C++, C#, COBOL, F#, Fortran 2003, Java, MATLAB, Objective-C, PHP5, Python, Ruby, and Visual Basic.<ref>List of object-oriented programming languages at Wikipedia</ref>

Structure comparison

Advantages and disadvantages

Block Structured Languages

Advantages:
  • Simplicity.
  • Coding and turnover time is quite less.
  • Dynamic lifetime of variables provide efficient usage of memory with allocation and deletion happening at the entrance and exit of each block.
Disadvantages:
  • Commercial projects are very difficult to manage due to very large code base sizes.
  • There is very less code reuse.
  • When arrays are passed as parameters they are usually unbounded,hence it was easy to access an element out of bounds.

Object Oriented Languages

Advantages:
  • The software objects model the real world objects. Hence the program composition is well defined and structured.
  • Since each object's definition and internal working is decoupled from other objects in the system the design becomes inherently modular.
  • Adding new features becomes very easy because of the inheritance feature. The new class can contain the new feature in addition to all old features from the inherited class.
  • Debugging is easier since each objects internal working is independent of each other. This helps in isolating errors easily and fixing them.
  • Code re usability.
Disadvantages:
  • The complexity of O-O design becomes prohibitive when working on small projects.
  • Object-oriented programming paradigm is preferable for dynamic environments rather than simple non complex environments.
  • The time efficiency is much less compared to block structured languages.

Effectiveness and durability

Applicability between paradigms

See also

References

<references/>

Further reading

  • Freeman, Eric, Elisabeth Freeman, Kathy Sierra, and Bert Bates. Head First Design Patterns. Sebastopol, CA: O'Reilly, 2004. Print.
  • Liberty, Jesse. Sams Teach Yourself C++ in 24 Hours. Indianapolis, IN: Sams, 2002. Print.
  • Microsoft Visual C++ Language Reference. Redmond, WA: Microsoft, 1997. Print.
  • Weiss, Mark Allen. Data Structures & Algorithm Analysis in Java. Reading, MA: Addison-Wesley, 1999. Print.

External links

Object Oriented Programming at slideshare The Evolution of Object-Oriented Languages The History of OOP