找回密码
 注册
搜索
热搜: java php web
查看: 514|回复: 1

[讨论]对Ruby语言的一些看法

[复制链接]
发表于 2009-1-26 07:19:56 | 显示全部楼层 |阅读模式
[讨论]对Ruby语言的一些看法
1,随意,更象人类的语言
java:
if(a == b) {
System.out. ….//already forgotton?
}


ruby:
puts “it’s right!” if a == b

2,纯粹的OOP
java:
MyClass my = new MyClass(”param”); //’;’ required
int i = Math.abs(-5);

ruby:
my = MyClass.new(”param”) #no ‘;’ required
i = -5.abs #see, even -5 is an object

3,灵活
java:
public String hello(String sir){
return “hello, ” + sir + “!”;
}

ruby:
def hello(sir)
“hello, #{sir}!” #the last line’s value will be the returned value.
end

4,人性、人性!
任务:打印n个*出来
java:
for(int i=0;i

ruby:
n.times { print “*”}

5,容错
java:
int[] i = {1,2,3};
i[5] = 99; //boom!!! ArrayIndexOutxxxException!!!

ruby:
i = [1,2,3]
i[5] = 99 # i is now [1,2,3,nil,nil,99]
好好学习,天天向上
发表于 2009-1-26 08:04:26 | 显示全部楼层
每个人看法不同而已。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|软晨网(RuanChen.com)

GMT+8, 2024-9-20 17:30

Powered by Discuz! X3.5

Copyright © 2001-2023 Tencent Cloud.

快速回复 返回顶部 返回列表