CSC/ECE 517 Fall 2011/ch1 1g jn: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 66: Line 66:
     this.toString = function() {
     this.toString = function() {
         return 'Name: ' + name + ', Age: ' + age;
         return 'Name: ' + name + ', Age: ' + age;
     };
     };
}
}

Revision as of 23:41, 7 September 2011

Comparing Object-Oriented and Scripting Languages

Scripting Languages

Overview:-Object Oriented and Scripting Languages

Object-Oriented Languages
1.OOP languages focus on abstract relationships and hierarchy of related functionality.
2.Any problem is handled as a collection of real-world objects that provide services to solve that problem.
3.It bounds data closely to the functions that operate on it and protects it from accidental modification from outside functions.
4.Encapsulation and polymorphism emphasizes on re-usability by keeping the implementation flexible without having the need to change a great deal of code.
5.Object-orientation is a sturdy compromise between performance and organization. Programmer needs to know how to effectively represent real-life scenarios into objects to fill the needs of market.
Scripting Languages
1.High-level software development language,primarily used for the purpose of adding dynamic and interactive components to web pages.
2.They are not stand-alone programming languages with support of large system development. However, they can be integrated with existing technologies to provide required functionality.
3.Portable and Platform independent because they can be created and edited easily on any text editors.
4.Easy to learn and require minimum programming knowledge or experience.
5.It must be efficient when calling system resources such as file operations, inter-process communications, and process control.

Is scripting essentially synonymous with dynamic typing?

Advantages that object orientation brings to a scripting languages

Advantages of object orientation on scripting languages can be explained on the basis of core O-O concepts:-

Code Reusablity

To allow developers to pay more attention on program functionality, code reuse is a very effective technique that saves time and effort by significantly reducing the redundant code. Administrators and script developers can share functionality by breaking their programs into reusable units like modules functions etc. and using them as other program’s components. For example:-

  • Python supports program reusability by implementing modules and packages in standard Python Library.
  • Windows PowerShell offer Modules that enable production-ready scripting solutions. These redistributable components have added benefit of allowing users to repackage and abstract multiple components to create custom solutions.
  • CPAN (Comprehensive Perl Archive Network) is an online repository of Perl modules which are collection of files of Perl code that can be reused from program to program.

Inheritance

One major advantage of Object Inheritance, apart from its usefulness in defining and abstracting functionality, is it permits the implementation of additional functionality in similar objects without the need to re-implement all of the shared functionality. Object oriented languages implement class-based inheritance and thus have deep hierarchies. Whereas most of the scripting languages use prototypical inheritance where classes and objects have shallow hierarchies and are more expressive. Since scripting languages are loosely-typed languages, object references don’t need casting. For example :-

  • JavaScript and PowerShell support inheritance through prototyping as well as properties and method.
  • In JavaScript,Class objects are soft and thus new members can be added by simple assignment. All object types have a prototype property that can be both extended and inherited. Prototyping also has its disadvantages like object creation can much slower than it can be in a more conventional class/object dichotomy scheme.
  • Inheritance in Python has close resemblance with classical inheritance as it allows multiple base classes, a derived class can override any methods of its base class or classes, and a method can call the method of a base class with the same name.
  • @ISA variable defined for each package in PERL governs inheritance.If a call to a method on an object or class returns null in that object’s package, Perl looks to @ISA for other packages to go looking through in search of the missing method.

The main reason behind inheritance exhibiting a different behavior in scripting languages is, it needs to be as dynamic as the environment it is in.

Encapsulation

Encapsulation is a useful technique in programming which allows you to separate an abstraction's implementation from its interface, thus allowing enhancements without affecting the interface.

  • JavaScript implements encapsulation using Closures which can be used to group interrelated and dependent code. For example, A Closure allows the buffer array to be associated with the function that is dependent upon it and simultaneously keep the property name to which the buffer array as assigned out of the global namespace and free of the risk of name conflicts.
  • Python supports encapsulation with naming conventions; however they are not strictly implemented. For Example, it differentiates between identifiers starting with a single versus double underscore (akin to protected versus private).

function Person(name, age) {

   this.toString = function() {
       return 'Name: ' + name + ', Age: ' + age;
   };

}

Advantages that scripting capability bring to an object-oriented languages

Advantages of scripting languages that are not object oriented