免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 11404 | 回复: 2
打印 上一主题 下一主题

学了perl之后,我发现C++真的好简单呀!!!!  关闭 [复制链接]

论坛徽章:
0
1 [报告]
发表于 2006-10-30 13:17 |显示全部楼层
C++ 我只看過,未學過,Perl 會一點皮毛,但看來 Perl 不是 OO,怎麼會Perl
就學 C++ 很容易呢?請舉例。

论坛徽章:
0
2 [报告]
发表于 2006-10-30 16:01 |显示全部楼层
原帖由 flw 于 2006-10-30 15:23 发表

C++ 拥有的 OO 特性,Perl5 全都有。
Perl5 完全支持 OOP 的。


http://www.cyut.edu.tw/~ckhung/b/pr/scripting.php

论坛徽章:
0
3 [报告]
发表于 2006-10-30 21:48 |显示全部楼层
http://www.garshol.priv.no/download/text/perl.html
其中一段

Not really object-oriented

Although object-orientation is not as fantastic as many would like us to think, Perl does support it. However, it does so only half-heartedly, since objects were added rather late in the life of the language.

The result of this is that normal files, sockets, hashes and lists are not objects, which means that the interfaces to them are not as convenient as they could have been. Newer versions of Perl come with object-oriented modules with wrappers for these kinds of objects, which means that Perl has a protocol for such objects and you can write your own implementations of these protocols. However, it also means that you need to distinguish between ordinary file handles and file objects, which is a bit inconvenient.

Another thing is the fact that when creating objects you need to explicitly manage the internals of your objects. In Perl, object creation is manual. A class is declared as a package, and the functions in the package then become the methods of the class. To create an object, you make a hash table and then bless it (using the built-in function 'bless') to make it an object. The 'perlobj' man page, which explains the Perl object features, recommends this form of object initializer:

package MyClass;
sub new {
    my $class = shift;
    my $self = {};
    bless $self, $class
    $self->initialize();  # do initialization here
    return $self;
}

There are other ways of doing object initialization, some of which cause problems for inheritance. Personally, I find it amazing that this sort of thing should be necessary at all. The above is equivalent to this Python code:

class MyClass:
    pass

The result is that one can easily get object construction wrong (such as by not catering for inheritance), defining classes is awkward and it's hard to tell from code when a class is defined (for both human readers and software documentation tools).

我個人比較相信那些言論,雖然我對PERL 理解不多,只知道它最初是作為 shell,sed,awk和Unix 眾多命令的
替代品和SuperSet, 它一開始便不是作為 OO語言開發的, Ruby 卻是作為OO語言開發的 scripting language
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP