Ruby没有元组,这不能算优点吧。元组是函数式编程的核心。Ruby一天到晚吹嘘函数式编程,没这个也没啥好吹的。
· There are no “new style” and “old style” classes. Just one kind.
· Ruby是单根的。Python新风格的类是单根的。但是Python旧风格的类没有根类。
· Python的类从元类生成。Python旧风格的类也是从元类生成的,可以自定义元类。
Ruby好像也有类似的东西。抱歉,很久没玩Ruby了。
· You never directly access attributes. With Ruby, it’s all method calls.
· Ruby中不能访问属性,它提供了自动生成的get/set方法。Python可以直接访问属性,需要自己写get/set方法,或者直接操作变量。__attr__方法中也可以拦截对属性的访问。
Ruby的函数调用中()可以省略,对代码可读性有很大伤害。
· There’s public, private, and protected to enforce access, instead of Python’s _voluntary_ underscore __convention__.
· Ruby强制定义了类的public,private,protected.
· Python都是public,但是可以__开始的变量会混淆名字。
我觉得这个有没有都无所谓。
· “mixin’s” are used instead of multiple inheritance.
· Ruby是单继承的,有特定的mixin机制。Python使用多继承实现混入。
· 混入指的是多继承没有数据只有方法的类。
· You can add or modify the methods of built-in classes. Both languages let you open up and modify classes at any point, but Python prevents modification of built-ins — Ruby does not.
· Python不能修改内建类的方法和属性,只能继承它们。
· Ruby可以修改。--------这有个鸟用?把基本类型弄坏了咋整?
· You’ve got true and false instead of True and False (and nil in stead of None).
· Python的关键字True,False和None真的诡异。 关键字混用大小写确实不太习惯。
· There are a number of shortcuts that, although give you more to remember, you quickly learn.
They tend to make Ruby fun and very productive.
· 这个是Ruby的一大缺点。Ruby有很多快捷键,默认值。很诡异。如上面那个Rails生成的类,太难看懂了。