BBS水木清华站∶精华区

发信人: kafa (staring at the sun), 信区: Linux 
标  题: Ruby与其他语言的比较 
发信站: BBS 水木清华站 (Tue Nov 21 21:28:43 2000) WWW-POST 
 
呵呵,凑个热闹。 
这是www.ruby-lang.org自己网站上的比较。 
--------------------------- 
 Contrast Ruby and Other Languages Ruby Search          
 
----------------------------------------------------------------------- 
 
Let's compare other languages with Ruby. We take up Perl, Python, Tcl, Java,  
Eiffel and C++. This is based on our own judgment and biased view, however,  
it does not intend to spread fibs.  
 
Please tell me about mistakes, correction or supplementation for this page.  
 
Perl 
Ruby owes a lot of ideas Perl. Now, let's compare Perl with Ruby:  
 
 
Ruby was a genuine easy-to-use object-oriented language from the beginning;  
whereas Perl's OOP features were added to non-OO Perl, so that these features  
are (unlike the rest of Perl) very clumsy and hard to use correctly and  
effectively. For many people and purposes, Ruby is a better OO Perl than  
Perl.  
 
 
Ruby uses less punctuation ($,@,%, etc.) Ruby uses ($,@) prefixes to denote  
variable scope, not data type.  
 
 
Ruby scripts tend to be less cryptic.  
 
 
The default variable scope rules for Ruby (default: local) are much better  
suited for medium-to-large scale programming tasks; no "my, my, my"  
proliferation is needed for safe Ruby programming.  
 
 
Ruby is easier to learn than Perl, easier to maintain than Perl, yet Ruby  
compares well to Perl in terms of overall convenience and power.  
 
 
Ruby copies many good capabilities of Perl, ranging from $_ short cuts to  
extended regular expressions.  
 
 
Perl is statically typed language except for references. The only types in  
Perl are scalar, array, hash and type glob. :-)  
 
Python 
Python and Ruby deal with similar problem areas. Now, let's compare Python  
with Ruby:  
 
 
Ruby uses conservative statement structure, using `end'.  
You don't have to say `self.' to access attribute of the object.  
All data (including Integer, String, List, etc.) in Ruby are class instances.  
 
Ruby has a better (or real) closure feature.  
Object attributes are not accessible by default in Ruby.  
Ruby's functions (methods) are not first class objects.  
                                   ~~~~~~~~~~~请教什么意思? 
Ruby converts small integers and long integers automatically.  
Ruby does not have tuples.  
呵呵,我到现在也搞不清楚python为什么要搞个不能修改的tuple类型? 
Statements in Ruby have values; you can say  
 
 
def max(a,b) 
  if a>b then a else b end 
end 
 
 
Ruby has assignment syntax sugar such as +=, -=, etc.  
Ruby has more natural operator overloading; e.g. you can define  
 
 
def +(x) 
 self.to_i + x 
end 
 
 
Ruby has real garbage collector, not ref-counting. So that:  
(这个很爽,能够省不少事,其他的到没觉得怎么样。象把integer也作为类不知道会有什 
么好处?如果不能有特别的过人之处,想超越那些发展很久的“老语言”而流行起来不太 
可能吧?) 
Not subject to memory leaks like ref-counting is.  
No INCREF, DECREF are required for extensions.  
Extensions for Ruby written in C/C++ can easily define Ruby classes.  
Ruby has a loop abstraction using block; e.g.  
 
 
10.times do 
  ... 
end 
 
You can define your own arbitrary iterator.  
 
Ruby's block for method can be used more than iterator; e.g.  
 
 
mutex.synchronize do 
  .. critical process .. 
end 
 
 
Ruby provides method combination using `super'.  
Ruby is often faster than Python.  
 
Tcl 
Tcl is well-known as a scripting and glue language, but much simpler than  
Perl. Now, let's compare Tcl with Ruby:  
 
 
Ruby is a genuine object-oriented language.  
Ruby is often far faster than Tcl.  
Ruby can handle various data types.  
Ruby has various GUI toolkits, of cource including Tk.  
 
Java 
Java is the language in the news one way or another. Now, let's compare Java  
with Ruby:  
 
 
Ruby is an intepreted language.  
All data (including Integer, String, etc.) in Ruby are class instances.  
Ruby's module can be used to share implementation among classes.  
Ruby's variable and expressions are not statically typed.  
 
Eiffel 
An veteran would know the OOPL Eiffel. Now, let's compare Eiffel with Ruby:  
 
Too much difference in target (Why do I list it here ;-)  
 
C++ 
C++ is famous OOPL in many places. Now, let's compare C++ with Ruby:  
Ruby is too good to compare ;-)  
---------------------------------------------------------------------- 
---------------------------------------------------------------------- 
Written by webmaster@ruby-lang.org 
--------------------------- 
我觉得,理想的脚本语言本身应该具有简单清晰的语法,少用特殊标点符号;应该具有真 
正的oo特性,这是现代语言的标志;本身只提供基本的逻辑流程功能,通过提供简单方便 
的extension&embedding特性来利用其他语言写的“产品级的库”,这一点非常关键。 
最后,当然要在设计时就考虑国际化啦,呵呵。 
 
-- 
※ 来源:·BBS 水木清华站 smth.org·[FROM: 166.111.160.183]  

BBS水木清华站∶精华区