Comparison of programming languages (object-oriented programming)
Encyclopedia
This Comparison of programming languages compares how object-oriented programming
languages such as C++
, Python
, Perl
, Java
and others manipulate data structures.
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...
languages such as C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
, Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
, Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...
, Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
and others manipulate data structures.
Object construction and destruction
construction | destruction | ||||
---|---|---|---|---|---|
ABAP Objects | data variable type ref to class . create object variable «exporting parameter = argument». |
||||
C++ C++ C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell... (STL Standard Template Library The Standard Template Library is a C++ software library which later evolved into the C++ Standard Library. It provides four components called algorithms, containers, functors, and iterators. More specifically, the C++ Standard Library is based on the STL published by SGI. Both include some... ) |
class variable«(parameters)»; or class *variable = new class«(parameters)»; |
delete pointer; | |||
C# | class variable = new class(parameters); | variable.Dispose; | |||
Java Java (programming language) Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities... |
variable.dispose; | ||||
D D (programming language) The D programming language is an object-oriented, imperative, multi-paradigm, system programming language created by Walter Bright of Digital Mars. It originated as a re-engineering of C++, but even though it is mainly influenced by that language, it is not a variant of C++... |
delete variable; | ||||
Objective-C Objective-C Objective-C is a reflective, object-oriented programming language that adds Smalltalk-style messaging to the C programming language.Today, it is used primarily on Apple's Mac OS X and iOS: two environments derived from the OpenStep standard, though not compliant with it... (Cocoa Cocoa (API) Cocoa is Apple's native object-oriented application programming interface for the Mac OS X operating system and—along with the Cocoa Touch extension for gesture recognition and animation—for applications for the iOS operating system, used on Apple devices such as the iPhone, the iPod Touch, and... ) |
class *variable = b>class alloc ] init]; or class *variable = Python]] |
variable = class(parameters) | del variable (Normally not needed) | ||
[[Visual Basic .NET]] | Dim variable As New class(parameters) | variable.Dispose | |||
[[Eiffel (programming language) | (type*) x | ||||
JavaScript | x.constructor | x instanceof class | colspan=3 | ||
Visual Basic .NET | x.GetType | TypeOf x Is type | CType(x, type) or TryCast(x, type) | ||
Eiffel | x.generating_type | attached {TYPE} x | attached {TYPE} x as down_x | ||
Python | type(x) | isinstance(x, type) | colspan=3 rowspan=3 | ||
PHP | get_class(x) | x instanceof class | |||
Perl | ref(x) | x->isa("class") | |||
Perl 6 | x.WHAT | x.isa(class) | type(x) or x.type |
||
Ruby | x.class or x.type |
x.instance_of?(type) or x.kind_of?(type) |
colspan=3 rowspan=2 | ||
Smalltalk | x class | x isKindOf: class | |||
Windows PowerShell | x.GetType | x -is [type] | [type]x or x -as [type] | ||
OCaml | colspan=2 | (x :> type) | colspan=2 | ||
F# | x.GetType | x :? type | (x :?> type) |
Namespace management
Import namespace | Import item | ||
---|---|---|---|
qualified | unqualified | ||
ABAP Objects | |||
C++ (STL) | using namespace ns; | using ns::item ; | |
C# | using ns; | ||
D | import ns; | import ns : item; | |
Java | import ns.*; | import ns.item | |
Objective-C | |||
Visual Basic .NET | Imports ns | ||
Eiffel | |||
Python | import ns | from ns import * | from ns import item |
PHP | use ns; | use ns/item; | |
Perl | use ns; | ||
Perl 6 | |||
Ruby | |||
Windows PowerShell | |||
OCaml | open ns | ||
F# |
Contracts
Precondition | Postcondition | Check | Invariant | Loop | |
---|---|---|---|---|---|
ABAP Objects | colspan=5 rowspan=2 | ||||
C++ (STL) | |||||
C# | Spec#: type foo( «parameters» ) requires expression { body } |
Spec#: type foo( «parameters» ) ensures expression { body } |
|||
Java | colspan=5 rowspan=3 | ||||
Objective-C | |||||
Visual Basic .NET | |||||
D | f in { expression } body{ instructions } | f out (result) { expression } body{ instructions } | invariant { expression } | ||
Eiffel | f require tag: expression do end |
f do ensure tag: expression end |
f do check tag: expression end end |
class X invariant tag: expression end |
from instructions invariant tag: expression until expr loop instructions variant tag: expression end |
Python | colspan=5 rowspan=3 | ||||
PHP | |||||
Perl | |||||
Perl 6 | PRE { condition } | POST { condition } | |||
Ruby | colspan=5 rowspan=4 | ||||
Windows PowerShell | |||||
OCaml | |||||
F# |