JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Languages on JVM » JRuby  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 【Ruby】Ten Things a Java Programmer Should Know About Ruby
T55555

Java, Ruby, Haskell

版主

發文: 1026
積分: 24
於 2005-01-29 00:25 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
唉 ... 可惜 javaworld.tw 沒有 Ruby 副版,
也不知道有沒有同好, 就先把它丟到灌水版啦.

"Ten Things a Java Programmer Should Know About Ruby"
一 thread 在 Ruby mailing list 燒的火熱.

早以超過 "Ten Things", 而且好像還沒完沒了 ...

( 一如 "Python Is Not Java" : 為您著想, 建議 Java 新手勿觀 )

http://jimweirich.tadalist.com/lists/public/14055

http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/128529?128488-128712


reply to postreply to post
作者 Re:【Ruby】Ten Things a Java Programmer Should Know About Ruby [Re:T55555]
Forth



版主

發文: 676
積分: 8
於 2005-01-29 01:57 user profilesend a private message to usersend email to Forthreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我有在用ruby和對我來說長得很像的groovy

還好公司沒人看我的程式,不然可能會說:
Java is not C
Ruby is not C
之類的吧......


reply to postreply to post
孟母擇鄰,良禽擇木,電腦擇友
作者 Re:【Ruby】Ten Things a Java Programmer Should Know About Ruby [Re:T55555]
Duncan

還隱隱作痛

版主

發文: 7816
積分: 39
於 2005-01-29 02:38 user profilesend a private message to usersend email to Duncanreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
T55555 wrote:
http://jimweirich.tadalist.com/lists/public/14055


這連結的第一點就遜掉了。
1
Ruby classes are Objects (therefore String.new, not new String())


這純粹是語言的定義者怎麼去定義語法,跟 classes 是不是 object 無關,Java class 也都是 object。

把建構物件的過程設計成以 operator 來做,有暗示著這個動作有執行環境的幫助,而不單單是執行某個 method/function,如果 Java 也用 SomeClass.new 的語法而這個 new 並不算是 method 的話則與 static method invocation 混淆,如果 SomeClass.new 算是特例,語意是執行 SomeClass 的 constructor(也許也統一把 class constructor name 通通規範成 new),那麼也會有模糊的地方,因為建構一個 object 不單單只是去執行某個 method 中的所有 statement 就可以做到的,而是隱含有配置空間在先,然後執行 constructor 做初始化。我個人覺得和一般的 method call 語法同型不見得有比較好。

個人意見。


reply to postreply to post

給我
辣味豆腐 其餘免談
作者 Re:【Ruby】Ten Things a Java Programmer Should Know About Ruby [Re:Duncan]
T55555

Java, Ruby, Haskell

版主

發文: 1026
積分: 24
於 2005-02-01 02:41 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Duncan wrote:
這連結的第一點就遜掉了。
1
Ruby classes are Objects (therefore String.new, not new String())


這純粹是語言的定義者怎麼去定義語法,跟 classes 是不是 object 無關,Java class 也都是 object。

那文件還沒處理, 所以與是不是 "第一點" 無關.
而且很多還再討論之中 ...


把建構物件的過程設計成以 operator 來做,有暗示著這個動作有執行環境的幫助,而不單單是執行某個 method/function,如果 Java 也用 SomeClass.new 的語法而這個 new 並不算是 method 的話則與 static method invocation 混淆,如果 SomeClass.new 算是特例,語意是執行 SomeClass 的 constructor(也許也統一把 class constructor name 通通規範成 new),那麼也會有模糊的地方,因為建構一個 object 不單單只是去執行某個 method 中的所有 statement 就可以做到的,而是隱含有配置空間在先,然後執行 constructor 做初始化。我個人覺得和一般的 method call 語法同型不見得有比較好。

個人意見。


我不是語言專家, 故無法置評.
以下我只想舉一些例子 about Ruby "new" can do but not Java "new".
( 例子是我個人想到的, 有沒有意義又另當別論;
我只想告訴您有這種 feature, 不想花時間去找 "有意義" 的例子)
"new" as a method, so like other Ruby's methods, you could "redefine" it!

I want run some code just "before" constructor!
Of couse java can do that too, but difficult.
Here is the Ruby example :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Parent
  def Parent::new
    puts 'In Parent.new'
    super
  end
end
 
class Child < Parent
  def Child::new
    puts 'Something need to do just before create instance...'
    super
  end
end
 
Child.new

==> output
1
2
Something need to do just before create instance...
In Parent.new

On Java, try to do that, impossible:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Parent {
  public Parent() {
    System.out.println("In Parent constructor");
  }
}
 
public class Chiild extends Parent {
  {
    System.out.println("I would like do something before constructor");
  }
  public Child() {
    System.out.println("I would like do something before constructor");
  }
  public static void main(String[] args) {
    new Child();
  }
}

==> output
1
2
3
In Parent constructor
I would like do something before constructor
I would like do something before constructor

The only way to do this on java is
add stuff you like to do before construct A
on above of *ALL* "new A();" code.
==> it's caller's responsable not like Ruby's build into class responsable.

Ruby even goes to extrem dynamic and flexible,
in fact, you could redefine new to return what ever you want.
1
2
3
4
5
class MyClass 
  def MyClass::new
     "Ooops"
  end
end

Call MyClass.new will return you a "Ooops" String instance!


T55555 edited on 2005-02-01 22:02
reply to postreply to post
作者 Re:【Ruby】Ten Things a Java Programmer Should Know About Ruby [Re:T55555]
alien

小弟劣作一幅



發文: 772
積分: 6
於 2005-02-01 11:29 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
constructor 一部份 (因為我不懂 Ruby, 只能從上面的資訊猜測) 看來與一般常見的 factory 沒太大分別?
要做到 "在 parent 的 constructor 前做些東西", 利用 factory method pattern, 那只是在 factory 的 child class 內, 在 invoke parent 的create method 前做些什麼吧?

當然, 直覺程度與 Ruby 那種是不可以相提並論了.


reply to postreply to post

public class Alien {
public boolean isNewbie() {
return true;
}
public String toString() {
return "請大家多多指教";
}
}
作者 Re:【Ruby】Ten Things a Java Programmer Should Know About Ruby [Re:T55555]
Duncan

還隱隱作痛

版主

發文: 7816
積分: 39
於 2005-02-01 12:04 user profilesend a private message to usersend email to Duncanreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
T55555 wrote:
Ruby even goes to extrem dynamic and flexible,
in fact, you could redefine new to return what ever you want.
1
2
3
4
5
class MyClass 
  def MyClass::new
     "Ooops"
  end
end

Call MyClass.new will return you a "Ooops" String instance!


從這一點看來,MyClass.new 不過(相當於)是一個 static method(假設 Java 程式員在設計 class 時約定俗成都會有一個 Object create() method),差別只在於 Ruby 的 new 是 builtin,Java 不是。我想沒有必要硬要說這個 new 與 constructor 有關,至於是不是每個 class 都需要這種(create) 東西,應該是很明顯的。

有越多的 feature 是不是就越有利?


reply to postreply to post

給我
辣味豆腐 其餘免談
作者 Re:【Ruby】Ten Things a Java Programmer Should Know About Ruby [Re:Forth]
ray_linn

什么都不懂的小白

版主

發文: 540
積分: 10
於 2005-02-01 12:36 user profilesend a private message to usersend email to ray_linnreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Forth wrote:
我有在用ruby和對我來說長得很像的groovy

還好公司沒人看我的程式,不然可能會說:
Java is not C
Ruby is not C
之類的吧......


原来这里也有人在玩Groovy, Smile


reply to postreply to post
飞翔的候鸟
作者 Re:【Ruby】Ten Things a Java Programmer Should Know About Ruby [Re:T55555]
Duncan

還隱隱作痛

版主

發文: 7816
積分: 39
於 2005-02-01 14:29 user profilesend a private message to usersend email to Duncanreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
T55555 wrote:
我不是語言專家, 故無法置評.
以下我只想舉一些例子 about Ruby "new" can do but not Java "new".
( 例子是我個人想到的, 有沒有意義又另當別論;
我只想告訴您有這種 feature, 不想花時間去找 "有意義" 的例子)
"new" as a method, so like other Ruby's methods, you could "redefine" it!

I want run some code just "before" constructor!
Of couse java can do that too, but difficult.
Here is the Ruby example :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Parent
  def Parent::new
    puts 'In Parent.new'
    super
  end
end
 
class Child < Parent
  def Child::new
    puts 'Something need to do just before create instance...'
    super
  end
end
 
Child.new

==> output
1
2
Something need to do just before create instance...
In Parent.new

On Java, try to do that, impossible:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Parent {
  public Parent() {
    System.out.println("In Parent constructor");
  }
}
 
public class Chiild extends Parent {
  {
    System.out.println("I would like do something before constructor");
  }
  public Child() {
    System.out.println("I would like do something before constructor");
  }
  public static void main(String[] args) {
    new A();
  }
}

==> output
1
2
3
In Parent constructor
I would like do something before constructor
I would like do something before constructor

The only way to do this on java is
add stuff you like to do before construct A
on above of *ALL* "new A();" code.
==> it's caller's responsable not like Ruby's build into class responsable.


對於這一點,我們都很清楚能不能在 invoke super constructor 前做點事與 Java class 是不是 object;與 Java 有沒有 Class.new 更是沒有直接的關連。

討論這件事之前一定要弄清楚 "能與不能" 和 "為與不為" 是兩回事,對你來說 in Java 是"不能",對我來說是"不為"。在 invoke super constructor 之前是不應該碰 object 的內容的,那麼所有你能在 invoke super constructor 之前作的事到底能帶來什麼 significant 益處?才是考慮的重點。

一旦你覺得非這麼做不可時(我目前倒是還沒遇到非得如此不可的情況),再來考慮 Java 能不能?能,你可以選擇為之。或許可以說 Java 不要這個 feature 而非沒有這個 feature。

** Parent class 使用你給的 source。

Child.class (0.39k)


Duncan edited on 2005-02-01 16:54
reply to postreply to post

給我
辣味豆腐 其餘免談
作者 Re:【Ruby】Ten Things a Java Programmer Should Know About Ruby [Re:T55555]
iampoya

Speculator

版主

發文: 169
積分: 8
於 2005-02-08 04:55 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
T55555 wrote:
唉 ... 可惜 javaworld.tw 沒有 Ruby 副版,
也不知道有沒有同好, 就先把它丟到灌水版啦.

As You Like It As You Wish Wink


reply to postreply to post
Japan Adult Video Album
作者 Re:【Ruby】Ten Things a Java Programmer Should Know About Ruby [Re:T55555]
contagious





發文: 12
積分: 2
於 2005-08-11 15:00 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Jim Weirich 在今年的 OSCON 有一個講題就是10 Things Every Java ProgrammerShould Know About Ruby

投影片在http://onestepback.org/articles/10things/index.html


reply to postreply to post
» JWorld@TW »  Languages on JVM » JRuby

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8