📄 00000001.htm
字号:
<HTML><HEAD> <TITLE>BBS水木清华站∶精华区</TITLE></HEAD><BODY><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER>发信人: kafa (staring at the sun), 信区: Linux <BR>标 题: Ruby vs. Python <BR>发信站: BBS 水木清华站 (Sun Nov 19 13:55:06 2000) <BR> <BR>From Python Mailing list <BR>------------------------ <BR>June Kim wrote: <BR>><I> Has anyone used Ruby here? or are there some documents at least </I><BR>unbiased -- <BR>><I> yet, Python-centric view would be okay if not too fictional. </I><BR> <BR>Ruby is Smalltalk with Perlish syntax. <BR>Python is ... (this is c.l.p., you fill in the blank) <BR> <BR>Python and Ruby are both object oriented languages that provide a <BR>smooth transition from procedural to OO programming styles. Smalltalk, <BR>by contrast, is object only - you can't do anything until you understand <BR>objects, inheritance and the sizable Smalltalk class hierarchy. By <BR>providing procedural training wheels, Python and Ruby "fix" one of <BR>the features that may have kept Smalltalk out of the mainstream. <BR>The two languages differ by approaching this solution from <BR>opposite directions. <BR> <BR>Python is a hybrid language. It has functions for procedural <BR>programming and objects for OO programming. Python bridges <BR>the two worlds by allowing functions and methods to interconvert <BR>using the explicit "self" parameter of every method def. When a <BR>function is inserted into an object, the first argument automagically <BR>becomes a reference to the receiver. <BR> <BR>Ruby is a pure OO language that can masquerade as a procedural one. <BR>It has no functions, only method calls. In a Ruby method the receiver, <BR>also called self, is a hidden argument like "this" in C++. A "def" <BR>statement outside of a class definition, which is a function in <BR>Python, is actually a method call in Ruby. These ersatz functions <BR>become private methods of class Object, the root of the Ruby class <BR>hierarchy. Procedural programming is neatly solved from the other <BR>direction - everything is an object. If the user doesn't grok objects <BR>yet, they can just pretend that "def" is a function definition and <BR>still get useful work done. <BR> <BR>Ruby's OO purity provides a number features that Python lacks or is <BR>still workng toward: a unified type / class hierarchy, metaclasses, <BR>the ability to subclass *everything*, and uniform method invocation <BR>(none of this len() is a function but items() is a method rubbish). <BR>Ruby, like Smalltalk, only supports single inheritance, but it does <BR>have a very powerful mixin concept: a class definition may <BR>include a module, which inserts that module's methods, constants, <BR>etc. into the class. <BR> <BR>Ruby, again like Smalltalk, provides closures and code blocks and uses <BR>them to the same good effect. The Ruby collection classes and <BR>iterators are outstanding, much more powerful and elegant than the ad <BR>hoc solutions that Python is sprouting (lambdas and list comprehensions). <BR> <BR>Ruby's syntax and design philosophy are heavily influenced by Perl. It <BR>has a lot of syntactic variability. Statement modifiers (if, unless, <BR>while, until, etc.) may appear at the end of any statement. Some key <BR>words are optional (the "then" in an "if" statement for example). <BR>Parentheses may sometimes be elided in method calls. The <BR>receiver of a method may usually be elided. Many, many things are <BR>lifted directly from Perl. Built in regular expressions, $_ and <BR>friends, here documents, the single-quoted / double-quoted string <BR>distinction, $ and @ prefixes to distinguish different kinds of names <BR>and so forth. <BR> <BR>If you like Perl, you will like Ruby and be right at home with its <BR>syntax. If you like Smalltalk, you will like Ruby and be right at home <BR>with its semantics. If you like Python, you may or may not be put off <BR>by the huge difference in design philosophy between Python and <BR>Ruby/Perl. <BR> <BR>Ruby is much more complex than Python but its features, for <BR>the most part, hang together well. Ruby is well designed and full <BR>of neat ideas that might be mined for P3K. I'm not sure how many <BR>Python programmers will be attracted to it though - it hasn't won me <BR>over (yet). But it is worthy of serious study and could be a real threat <BR>to Perl. <BR> <BR>John Dell'Aquila <BR> <BR>------------------------ <BR>-- <BR>风来疏竹,风去而竹不留声 <BR>雁渡寒潭,雁去而潭不留影 <BR> <BR> <BR> <BR>※ 来源:·BBS 水木清华站 smth.org·[FROM: 166.111.64.211] <BR><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -