появилось не много времени, решил дочитать книгу про С++, которую читал где-то год назад
что в этих языках отличается в ООП?
там сишные програмисты слелали много чего в perl
http://lurkmore.ru/Perl
http://www.perlmonks.org/?node_id=579920
tie OOP perl
Perl, C++
Модератор: Модераторы разделов
-
- Сообщения: 526
- ОС: FreeBSD 8.0 CURRENT
-
- Сообщения: 67
Re: Perl, C++
Добро всегда побеждает зло. Мы победили, значит мы - добро.
-
- Сообщения: 526
- ОС: FreeBSD 8.0 CURRENT
Re: Perl, C++
ну вот говорят что С++ нельзя заменить другим языком в прикладных разработках, что именно в нем лучше? или это нельзя объяснить?
в книгах бывает пишут что на оборот...
это как поговорка:
Лучше установить FreeBSD, чем потратить 30 лет на Linux'ы и выяснить какой из них хуже.

в книгах бывает пишут что на оборот...
это как поговорка:
Лучше установить FreeBSD, чем потратить 30 лет на Linux'ы и выяснить какой из них хуже.

-
- Сообщения: 8735
- Статус: GPG ID: 4DFBD1D6 дом горит, козёл не видит...
- ОС: Slackware-current
Re: Perl, C++
можно. Просто шурупы проще отвёрткой закручивать, а в некоторых случаях шурупавёртом. но уж ни как не молотком. Хотя молотком тоже можно. И на PHP можно прикладное ПО писать... Вот только...
Поглядел тесты... Ну что я могу сказать? Конечно реализация MD5 из Java лучше, чем та-же MD5, но откомпилированая непонятно из чего, непонятно чем, и непонятно с какими опциями, при этом, запущенная не под совсем тем. Потому спор изначально глупый, что сильнее, слон или танк?
-
- Сообщения: 526
- ОС: FreeBSD 8.0 CURRENT
Re: Perl, C++
я не спорил...
-
- Сообщения: 8735
- Статус: GPG ID: 4DFBD1D6 дом горит, козёл не видит...
- ОС: Slackware-current
Re: Perl, C++
ага... но в сабже VS
Кстати, шуруповёртом закручено наверное 80-99% шурупов, его используют профессионально и в промышленных масштабах... Однако... Инструмент это дорогой, не надёжный, очень не универсальный, и так далее, и тому подобное... Подходящей отвёрткой я любой шуруп закручу, а вот шуруповёртом...
-
- Сообщения: 526
- ОС: FreeBSD 8.0 CURRENT
Re: Perl, C++
вот нашел, не много, адекватное пояснение
(не для спора)
2000г
(не для спора)
2000г
Код: Выделить всё
PERL AND C++
For better or worse, to much of the programming world, C++ is object-oriented program-
ming. Devised by Bjarne Stroustrup at the Bell Research Laboratories in the early 80s as an
object-oriented successor to the C programming language, C++ has undergone perhaps the
most public and collaborative evolution of any programming language, culminating in the
recent ANSI C++ standard.
Like Perl, C++ is a hybrid language with object-oriented features layered over an original
imperative language. Syntactically and semantically, its non-object-oriented components are
almost completely backwards compatible with the C programming language, while its object-
oriented features draw most heavily on Simula.
B.2.1 Objects
C++ objects are structured regions of memory that store one or more typed data members. In
other words, every object is a record of various fields. In Perl, too, objects may be recordlike
structures (i.e., hashes), but they may also be arrays, scalar variables, subroutine references, or
any other Perl datatype.
C++ objects may be stored directly in statically typed variables or dynamically created and
accessed via typed pointers or references. Perl objects may similarly be variables or unnamed
values and are always accessed via references4 stored in dynamically typed variables. Unlike
C++, in Perl there is no need for a manual deallocation mechanism like delete, since all ob-
jects in Perl are automatically garbage-collected.
C++ also permits the definition of static data members that are (conceptually) shared by
all objects of a given class. Perl has no equivalent construct, but it is easy to set up such shared
attributes using lexical variables of appropriately restricted scope (chapter 3).
C++ objects are created either by static declaration or by dynamic allocation using the new
operator. Perl objects are almost always created dynamically, in a method that is often called
new.
B.2.2 Classes
A class in C++ is a specification of the data and function members (i.e., methods) possessed by
a particular kind of object. Classes in Perl also define the methods of a type of object, but do
not normally directly specify the attributes possessed by such objects.5 Attribute specification
is typically arranged by the constructor method (e.g., new).
In C++, a class specifies a local namespace in which data and function members exist, but
C++ also has a separate higher-level namespace mechanism with which two or more classes
can be grouped. Perl’s package construct does double-duty as both a namespace and a class
specification mechanism, so there is no such ability to construct hierarchical namespaces.
Perl provides better resources for run-time type information than does C++. Whereas a
C++ program is restricted to the data provided by the standard typeid function, and limited
to using dynamic casts to verify class compatibility, Perl allows almost every aspect of a class’s
structure and capabilities to be interrogated at run-time: class name via the ref function, hi-
erarchical relationships via the UNIVERSAL::isa subroutine, and method compatibility via
the UNIVERSAL::can subroutine.
Perl does not directly support generic classes such as those provided by C++ templates.
In practice, this presents few problems because the combination of Perl’s closure mechanism,
interface polymorphism (see below), and dynamic-typing makes generic types largely unnec-
essary (chapter 12).
B.2.3 Methods
C++ and Perl are both hybrid languages that allow code to be executed in stand-alone subrou-
tines as well as methods.
In C++, a class’s function members are declared as part of the class specification and may
be defined at the same point or anywhere else, provided the appropriate class qualifier (i.e.,
ClassName::functionName) is used. Perl is even more liberal in this respect: a class method
may be declared and defined anywhere, provided it is suitably qualified (using the same qual-
ification syntax as C++).
Every C++ member function has a specific signature determined by its name and the
number and types of arguments it takes. C++ methods may be overloaded, may have default
argument values, and may also pass arbitrary arguments (using the “...” specifier). Perl methods
have no static checking of parameter types, and Perl unifies the many variable argument list
mechanisms of C++ by passing arguments as an actual variable-length list. There is no signa-
ture-based method selection (like C++ overloading), but the effect can be achieved using mul-
timethod techniques (chapter 13).
C++ member functions are called on an object or object reference using the “dot” oper-
ator (varOrRef.method(args)). Methods may also be invoked through a pointer using the
“arrow” operator (ptr->method(args)). In Perl, methods are always invoked through a ref-
erence to an object, using the arrow operator ($ref->method(args)). Unlike C++, in Perl,
if the method takes no arguments, the trailing parentheses indicating a subroutine call may be
omitted.
C++ allows pointers or references to member functions to be used to call those functions
on specific objects using the ptr->*funcptr() syntax. Perl allows references to methods to
be used in the same way, using the $ref->$methodRef() notation. Unlike C++, Perl also al-
lows methods to be called by name, by storing a suitable character string—rather than a ref-
erence—in the $methodRef variable.
In both languages, a method may act like a procedure or a function, depending on wheth-
er it chooses to return a value. Both languages provide a return statement to specify such re-
turn values. However, unlike C++, where a member function that does not return a value must
have a return type of void, Perl methods do not require, nor allow, any form of return-type
specification.
C++ provides the special constant this within each member function, which is a pointer
to the object on which the method was called. In Perl, a reference to the invoking object is in-
stead passed as the first argument to the call. It is typically extracted from the argument list
and stored in a variable called $self.
Both C++ and Perl allow class methods to be defined within a class. In C++, such member
functions are defined with the static qualifier and are called using the syntax ClassName:
:method(args). In Perl, such methods are defined in the same way as all other methods, and
differ only in that they expect the class name—rather than an object reference—as their first
argument. They are called using the syntax ClassName->method(args).
Both languages also support the definition of class-specific versions of the standard set of
operators (i.e., operator overloading), and, as in C++, overloaded operators in Perl may either
be regular subroutines or specific object methods (chapter 10).
B.2.4 Constructors and destructors
C++ classes typically provide a special member function—with the same name as the class
itself—that may be used to initialize objects when they are created. Perl has no comparable
built-in initialization mechanism. Instead, a regular class method, typically called new, is used
to both create and initialize objects.
C++ also provides for destructor functions, which are automatically called on an object
just before it goes out of scope or is otherwise deallocated. Perl also allows for destructor meth-
ods to be defined using the special method name DESTROY.
B.2.5 Encapsulation
Every data and function member of a C++ class has some associated accessibility—public,
protected, or private—which determines the scopes from which it can be directly
accessed. Perl has no equivalent concept and does not enforce any form of encapsulation on
attributes or methods of objects. There are, however, several programming techniques which
permit both attributes and methods to be appropriately restricted in accessibility (chapter 11).
B.2.6 Inheritance
Both C++ and Perl support optional multiple inheritance of superclasses, but in quite differ-
ent ways. In C++, the classes from which a given class inherits are determined at compile-time
by the class definition. The classes that a given Perl package inherits are determined at run-
time by the contents of that package’s @ISA array.
A subclass in C++ does not have access to the private data and function members of its
superclasses.6 Because the attributes and methods of a Perl class are entirely unencapsulated,
there is no equivalent restriction in Perl. Likewise, Perl does not support access variations along
the lines of C++’s protected or private inheritance.
Perl does not have a mechanism corresponding to virtual inheritance in C++, nor does it
need one, since object attributes are determined dynamically by constructors, rather than stat-
ically by class definitions. In practice, the most common forms of class implementation all pro-
vide implicit virtual inheritance of attributes.7
Unlike C++, Perl classes all implicitly inherit from a single common class called
UNIVERSAL.
B.2.7 Polymorphism
In C++, methods are implicitly nonpolymorphic unless they are specifically marked as being
virtual. All Perl methods are implicitly polymorphic and there is no way to mark them as
nonpolymorphic. Unlike C++, in Perl, any method may be redefined in any derived class.
C++ polymorphism is controlled by class hierarchies because virtual functions are called
through typed pointers or references. In Perl, all variables are dynamically typed and, therefore,
may store a reference to any class of object at any time. Thus, Perl provides the more general
form of polymorphism—interface polymorphism—in which any object (regardless of its class
hierarchy membership) may respond to any method call for which it has a suitably named
method.
C++ allows base class member functions to be accessed from derived class member func-
tions, even if the derived class redefines the function in question. This access is achieved by ful-
ly qualifying the nested function call with the name of the desired ancestral class. Perl has the
same mechanism. However, Perl also provides a special pseudo-class called SUPER that may
be used to delegate a method dispatch to an unspecified ancestral class—namely whichever one
actually provides the inherited method (chapter 6).
Perl has no method abstraction construct corresponding to C++’s pure virtual member
function declaration. Instead, in keeping with Perl’s dynamically typed nature and run-time
checking philosophy, if an abstract method is required, a normal method is specified and made
to immediately throw an exception.
B.2.8 Comparative syntax
Table B.2 shows a translation into Perl of the fundamental object-oriented features of C++.
Selected comparative syntax for C++ and object-oriented Perl
Table B.2
C++
Construct Perl
Comment // Comment to EOL # comment from ‘#’ to eol
/* Delimited comment*/
Assignment variable = value; $variable = value;
Temporary variable className variable = init; my $variable = init;
Class definition class className package className;
{ specification }; specification
Class derivation class subclassName package subclassName;
: superclassName(s) @ISA = qw( superclassName(s) );
{ specification }; specification
Attribute specification class className bless
{ { memberName=>type->new() },
type memberName; className;
};
Class attribute class className package className;
specification { {
static type memberName; my $var = type->new(init);
}; sub fieldName
type className::memberName { $var = $_[1] if @_>; $var}
}
=init;
Object instantiation ptr = new className(args); $ref = className->new(args);
Table B.2
C++ Perl
Construct
Method definition class className package className;
{
returnType methodName(args) sub methodName
{ {
statements my @args = @_;
return returnValue; statements;
} return returnValue;
} }
Polymorphic method virtual returnType sub methodName
definition methodName (args) {
{ my @args = @_;
statements statements;
return returnValue; return returnValue;
} }
Abstract method virtual returnType methodName() sub methodName
definition = 0; { die "Abstract method” }
Constructor definition className(args) sub new
{ {
statements my {$classname, @args) = @_;
} my $self =
bless {}, $classname;
statements;
return $self;
}
Destructor definition ~className() sub DESTROY
{ {
statements statements
} }
Method invocation objref.methodName(args); $objref->methodName(args);
objptr->methodName(args);
Indirect method retType (class::*methptr)(args) $methref = \&class::methodName;
invocation = class::methodName;
objref.*methptr(args): $ref->$methref(args);
objptr->*methptr(args);
Class method classNam::methodName(); className->MethodName();
invocation
Access to message this my ($self) = @_
target
Access to superclass this->superclass::methodName(); $self->SUPER::methodName();
method
Class type classDescriptor = $className
identification typeid(object); = ref($object);
Exception handlers try { statements } unless (eval { statements; 1 })
catch { handler } { handler }
Raising an exception throw exceptionType(args); die "exceptionText:"
-
- Сообщения: 526
- ОС: FreeBSD 8.0 CURRENT