<!-- [if gte mso 9]><xml><w:WordDocument><w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel><w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery><w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery><w:DocumentKind>DocumentNotSpecified</w:DocumentKind><w:DrawingGridVerticalSpacing>7.8</w:DrawingGridVerticalSpacing><w:View>Normal</w:View><w:Compatibility></w:Compatibility><w:Zoom>0</w:Zoom></w:WordDocument></xml><![endif]-->
Ruby优于
Python
之处(面向
hackers
)
Posted:June7,2011by
JinpuHu
in
Architecture
Tags:
Python
,
ruby
,
Language
0
粗略的看,ruby
和
python
非常的相似,都拥有不错的社区,大量的类库,都是动态语言。但如果要在之间做一个取舍?你会怎么看呢?
我说说我的看法:
哲学不一样
Python强调的是代码风格的统一,一件事情只有一种做法,从而似乎更加利于团队合作;而
Ruby
走了另一个极端,由于语言设计的非常优美,做一件事情可以有更多的选择,所谓条条大路通罗马。如果你问一个
hacker
,他一定会告诉你,他不喜欢被限制。至于团队协作的问题,那就看你的团队都是什么人组成的,如果都是一帮
hacker
,那自然会有一些协议,大家在这个协议的基础上工作,不同的模块间按照协议
“
通讯
”
便
ok
了。但如果你的团队比较
“
保守
”
,那就选择
Python
吧。如果我
build
一个新的团队,我就一定选择
hacker
。可以推荐大家去看一下黑客与画家。
:)
对象系统更彻底
比如一个数组对象的长度,在Python
里只能
len(array)
,或者
array.__len__()
。而在
Ruby
里,一切皆对象,你可以
array.size
或者
array.length
。细节决定成败。
元编程支持更猛
你可以在任何时候,动态的修改任何Ruby
的
class
,这得利于
Ruby
实现
OO
时构建的
eigenclass
(
Ruby
对象系统实在值得好好研究,可以参见我
以前的一篇博客
)。而这在Python
里做起来是很困难的,甚至是不可能的。
Python
对于导入的
class
或者模块,只能以过程式的方式,进行
XXX.new_method
赋值,而
Ruby
可以和
import
前的写法一致,是声明式的。虽然
Openclass
容易引入不可控的
bug
,但他也可以
hacker
更多的空间,更多对已有代码的控制,用得恰当可以使代码更加简短,更加可读。比如:
10.years.ago
,这让
hacker
写起来很愉快!
这更加适合做DSL
。
匿名blocks
发飙
Python可以用
lamba
来实现,但可恶的是代码必须是
oneline
的,这典型没有考虑
block
的威力。而
Ruby
的每个方法都可以接受一个匿名
block
。那匿名
block
有什么威力?
JavascriptNinja
一定明白。对于非
JavascriptNinja
,简言之,可以直接使用
block
传递给一个方法,方法可以利用
block
产生域的变量,如果还无法想到好处,最直接的就是去学好
Javascript
。
任何表达式,方法,函数都有一个返回值
如果你熟悉FunctionalProgramming
,你就知道,任何元素都应该有一个返回值(比如
if
表达式也会以最后的结果作为返回值),结果往往由一系列的函数调用决定,一个函数的输入往往是另一个函数的输出。这点
Python
是做不到的。
更快和更注重实效的积累
rails3.1就快出来了,里面拥抱了
jQuery
,拥抱了
sasscoffeesrcript
,还内置支持了
httpstream
。这些在
django
等
Python
的
webframework
里没有得到及时的反应。而且
rails
生态系统里,
rails
的进化是社区推动的,一个新特性必然是更加合理的解决了目前
web
开发的问题,而非理论或个人英雄主义。取之于民,用之于民。
以上是我对这两门语言的一些简短的想法,将来有新的想法再加入。不想引来Pythoners
的口水,如果你觉得我的观点有问题,不用赞同便是。
原文:http://jinpu.wordpress.com/2011/06/07/what-are-the-advantages-of-ruby-over-python/
分享到:
相关推荐
No Starch Press,2014出版, Black Hat Python, Python Programming for Hackers and Pentesters
Python hacker. Those are two words you really could use to describe me. At Immunity, I am lucky enough to work with people who actually, really, know how to code Python. I am not one of those people. ...
Justin Seitz-Black Hat Python_ Python Programming for Hackers and Pentesters-No Starch Press (2014).MOBI
Python is the high-level language of choice for hackers and software security analysts because it makes it easy to write powerful and effective security tools. A follow-up to the perennial best-seller...
In Black Hat Python, the latest from Justin Seitz (author of the best-selling Gray Hat Python), you’ll explore the darker side of Python’s capabilities – writing network sniffers, manipulating ...
原版书,高清无水印,有源码,学习运用python写脚本。
Python Programming for Hackers and Reverse Engineers
Black.Hat.Python.Python.Programming.for.Hackers.pdf python hacker programming
Python 黑客研讨会 环境 Python 混帐 数据库 虚拟环境 系统参数 系统,操作系统库 地图、lambda、列表合成、字典合成、生成器示例:词表阅读器 子流程示例:nmap 处理程序 xml库示例:xml 解析 参数解析 结构 插座 ...
原名: Gray Hat Python:Python Programming for Hackers and Reverse Engineers 作者:Justin Seitz 资源格式: PDF 版本: 扫描版 出版社: 电子工业出版社 发行时间: 2011年03月01日 内容介绍: 《Python灰帽子:...
比较好的一本关于Python的书,英文文字版。
Python Programming for Hackers and Pentesters by Justin Seitz
网络安全渗透测试漏洞
网络安全渗透测试漏洞
Python Hacking Essential, This book is not for professional hackers. Instead, this book is made for beginners who have programming experience and are interested in hacking. Here, hacking techniques ...
Hackers delight 2nd edition黑客必备