CSC/ECE 517 Fall 2011/ch1 1e dm: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 24: Line 24:
*Visibility: It provides restricted visibility for local identifiers [6].
*Visibility: It provides restricted visibility for local identifiers [6].
*Storage: Provides efficient use of storage and hence can save an order of magnitude in memory.
*Storage: Provides efficient use of storage and hence can save an order of magnitude in memory.
*Block structured programming provides the protection of data that is exclusive to one set of modules within a program from compromise by other modules.
*Can save an order of magnitude in run time.
*Can save an order of magnitude in run time.
*Being block-structured allows Fortran to be used for array operations.
*Being block-structured allows Fortran to be used for array operations.

Revision as of 19:13, 6 September 2011

CSC/ECE 517 Fall 2011/ch1 1e dm


Introduction

This wiki article describes the block structured and object oriented languages by highlighting their advantages and limitations along with providing a comparison between them. It also discusses the application of block structured concept in the object oriented programming.

Block Structured Languages

Block structured languages are a class of high-level languages in which a program is made up of blocks. A block is a section of code which can be grouped together. Blocks consist of one or more declarations and statements. A block structured programming language uses and permits the creation of blocks and may also include nested blocks as components. The major function of using blocks is to enable the groups of statements within the block to be treated as if they were a single statement.

Block structured programming is related to structured programming, which is a technique for organizing and coding computer programs in which a hierarchy of modules is used, each having a single entry and a single exit point, and in which control is passed downward through the structure without unconditional branches to higher levels of the structure. A structured program is decomposed into a hierarchy of processes. A process in this context is a body of code, typically a function or subroutine, that takes some input and manipulates it to produce an output. A process may be composed of other, more specialized processes, i.e., it may be a function that calls other functions. Structured Programming uses three types of control flow: sequential, test, and iteration.

Examples of block structured programming languages are ALGOL, FORTAN, Pascal, C, Python, Lisp, Ada, PL/SQL.

Characteristics

  • Takes on the top-to-bottom approach. A top-down approach is the breaking down of a system into compositional sub-systems, where each sub-system is then defined in further detail. This could be in the form of greater detail, additional subsystem levels, or until the entire system is reduced to base elements.
  • Based around data structures and subroutines.
  • Uses single entry and exit block.
  • The names of variables and other objects such as procedures which are declared in outer blocks are visible inside other inner blocks, unless they are shadowed by an object of the same name.
  • Splits the tasks into modular forms.

Advantages

  • Straightforward coding: Writing of classes and complex functions is not necessary to write a simple piece of code, which executes a specific set of commands.
  • Structuring: Splitting of tasks into blocks/modules makes the program simpler and easier to read with less lines and codes.
  • Easy Debugging: The blocks of large functions are easier to debug and refactor.
  • Visibility: It provides restricted visibility for local identifiers [6].
  • Storage: Provides efficient use of storage and hence can save an order of magnitude in memory.
  • Block structured programming provides the protection of data that is exclusive to one set of modules within a program from compromise by other modules.
  • Can save an order of magnitude in run time.
  • Being block-structured allows Fortran to be used for array operations.
  • Overhead involved in coarse-fine interactions can be amortized over larger array calculations.

Limitations

  • Communication patterns between levels can be complex.
  • Algorithm complexity can be substantial.
  • No data abstraction or information hiding supported.
  • The modular design employed does not provide wide usage of modules or blocks for all types of problem solving.
  • Redundancy: Repetition of code since it does not have modular sections since the code is written and executed sequentially, which leads to redundancy of code.
  • Readability: Harder to understand and harder to modify when the code becomes considerable large.
  • Separate Compilation:
  • Implementation:
  • Interference:

Object Oriented Languages

Object oriented programming is an approach to programming in which each data item with the operations used on it is designated as an object; the routines used to operate on the data item are called methods; and objects are grouped in a hierarchy of classes, with each class inheriting characteristics from the class above it.

The four fundamentals of object oriented programming languages are Polymorphism, Inheritance, Encapsulation and Abstraction.

Examples of object oriented programming languages are C++, Java, Smalltalk, Ruby.

Concepts

Objects: Object is the basic unit of object oriented programming. Data and function that operate on data can be bundles as a unit which is called as object.

Classes: Classes are the data types on which objects are created. This concept is similar to that of structures in C. Memory is allocated to the class only when an object is created.

Inheritance: Inheritance is the way to reuse and compartmentalize the code by creating collections of objects that can be based on previously created objects with slightly different or different properties and behaviour. A superclass, base class, or parent class is a class from which other classes are derived. The classes that are derived from a superclass are known as child classes, derived classes, or subclasses.

Data Abstraction: Data abstraction makes it possible to represent the needed information in program without presenting the details. It is also possible to create user defined data types and thus increase the power of programming language.

Data Encapsulation: Data Encapsulation is the process of combining data and functions into a single unit called class. Using this method, one cannot access the data directly, and is accessible only through functions present in a class. It thus gives rise to the concept of data hiding. It thus means that the internal representation of an object is generally hidden from view outside of the object's definition.

Polymorphism: Polymorphism is the ability to use an operator or function in different ways in other words giving different meaning or functions to the operators or functions. It thus uses a single function or an operator which functions in many different ways depending upon the specific usage. The purpose of polymorphism is to implement a style of programming called message-passing, in which objects of various types define a common interface of operations for users. The primary usage of polymorphism is the ability of objects belonging to different types to respond to method, field, or property calls of the same name, each one according to an appropriate type-specific behaviour. Polymorphism is not the same as method overloading or method overriding[5].

Overloading: Overloading is a specific branch of polymorphism, where the existing operator or function is made to have different implementations depending on their arguments. The purpose of overloading is to allow developers to define/redefine the operators as required.

Thus the object oriented programming features helps the program ad there by users of the application to achieve increased performance, it saves time of developing the application, give optimized code for the application, helps in gaining secured applications and there by helps in easier maintenance.

Advantages

  • Simplicity: Object oriented programming models real world objects, thus reducing the complexity of the code. It also helps in giving a clear picture of the program structure.
  • Modularity: Object oriented programming uses each object to form a separate entity whose internal workings are decoupled from other parts of the system. Hence it helps to reduce large problems to smaller, more manageable problems.
  • Modifiability: Object oriented programming helps in making minor changes to the view or the business logic without affecting any other part of the program.
  • Extensibility: Object oriented programming helps in adding new features or modify the existing features without affecting the entire program since the objects and classes are isolated from each other.
  • Maintainability: Object oriented programming uses objects which can be easily located and destroyed when the object is no longer in use.
  • Re-usability: Object oriented programming uses a modular approach where objects and classes can be reused in different programs. Thus less code needs to be written and reduces code redundancy.
  • Framework: Object oriented programming provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces.

Limitations

  • Complexity: The writing of classes and functions becomes complex when one has to write a straightforward piece of code.
  • Dynamic: Object oriented approach is well suited in case of a dynamic environment and not for a simple environment.
  • Over generalization: One tends to overgeneralise the amount of development time and often less provision is provided for design processes which may result in incorrect designs.
  • Artificial class relations

Compare and Contrast

Block Structure in Object Oriented Programming

Conclusion

See Also

References

  1. Advantages of block structured languages
  2. Advantages of object oriented languages
  3. Advantages of object oriented languages
  4. [1]
  5. ^Sierra, Kathy; Bert Bates (2005). Head First Java, 2nd Ed.. O'Reilly Media, Inc.. ISBN 0596009208.
  6. David R. Hanson, "Is Block Structure Necessary?", 1980.
  7. Pascal Programming Language

External Links

  1. Video for Structured Programming