DHH观点:为什么我偏爱Ruby?
生活随笔
收集整理的這篇文章主要介紹了
DHH观点:为什么我偏爱Ruby?
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
DHH觀點:為什么我偏愛Ruby?
David Heinemeier Hansson(DHH)在RailsConf 2006的Keynote Address中討論Rails具有各種conventions時,提到這樣的觀點,即任何一種paradigm都不是萬能的,任何paradigm都會有例外情況,例外情況就須要例外處理;Rails在提倡其conventions的同時,仍然允許我們避開conventions,采用更原始的辦法來處理同樣的事情。Rails正是這種既具有明顯conventions又允許例外情況的優秀語言。對此,DHH說如是:
..And that's why I personally love Ruby. Ruby has strong opinions of how you should do things, but it allows you to do basically everything if you really, really want to. A private method, it is only private until you call, well, .send(), simple for the method name. You can circumvent these things because sometimes it's DAMN useful to be able to circumvent these things, and you know the trade-offs -- you know that this special piece of code is being written in special way because it needs special consideration, it's not like the rest, and I should consider carefully the tradeoff I'm making.
……這也是我個人偏愛Ruby的原因:對于“你應該如何做事情”,Ruby持有強烈的觀點,但在你真的非常非常想繞開conventions做事情的時候,Ruby也允許你做幾乎所有事情。比如,private方法是私有的,但若你使用.send()進行調用,這種私有性就失效了。在Ruby中你可以繞開規則,因為有時候繞開規則真的非常受用,而且你在Ruby中繞開規則時,你會非常清楚其涉及到的利弊權衡與折中——你知道,對這一段特別的代碼需要作特殊考慮,它是以特殊的方式寫就的,它與慣常用法不同,你應該仔細考慮你所做的利弊權衡與折中。
# 有時候繞開規則真的非常受用
class Klass
? private
?? ?def hello(*args)
?? ??? ?puts "Hello " + args.join(' ')
?? ?end
end
k = Klass.new
# 使用 .send() 方法繞開private訪問控制規則
k.send :hello, "gentle", "readers"
# 按慣常方式會受到訪問控制規則的制約:
k.hello("gentle", "readers")
# Klass.rb:10: private method `hello' called for #<Klass:0x2b4b2dc> (NoMethodError)
David Heinemeier Hansson(DHH)在RailsConf 2006的Keynote Address中討論Rails具有各種conventions時,提到這樣的觀點,即任何一種paradigm都不是萬能的,任何paradigm都會有例外情況,例外情況就須要例外處理;Rails在提倡其conventions的同時,仍然允許我們避開conventions,采用更原始的辦法來處理同樣的事情。Rails正是這種既具有明顯conventions又允許例外情況的優秀語言。對此,DHH說如是:
..And that's why I personally love Ruby. Ruby has strong opinions of how you should do things, but it allows you to do basically everything if you really, really want to. A private method, it is only private until you call, well, .send(), simple for the method name. You can circumvent these things because sometimes it's DAMN useful to be able to circumvent these things, and you know the trade-offs -- you know that this special piece of code is being written in special way because it needs special consideration, it's not like the rest, and I should consider carefully the tradeoff I'm making.
……這也是我個人偏愛Ruby的原因:對于“你應該如何做事情”,Ruby持有強烈的觀點,但在你真的非常非常想繞開conventions做事情的時候,Ruby也允許你做幾乎所有事情。比如,private方法是私有的,但若你使用.send()進行調用,這種私有性就失效了。在Ruby中你可以繞開規則,因為有時候繞開規則真的非常受用,而且你在Ruby中繞開規則時,你會非常清楚其涉及到的利弊權衡與折中——你知道,對這一段特別的代碼需要作特殊考慮,它是以特殊的方式寫就的,它與慣常用法不同,你應該仔細考慮你所做的利弊權衡與折中。
# 有時候繞開規則真的非常受用
class Klass
? private
?? ?def hello(*args)
?? ??? ?puts "Hello " + args.join(' ')
?? ?end
end
k = Klass.new
# 使用 .send() 方法繞開private訪問控制規則
k.send :hello, "gentle", "readers"
# 按慣常方式會受到訪問控制規則的制約:
k.hello("gentle", "readers")
# Klass.rb:10: private method `hello' called for #<Klass:0x2b4b2dc> (NoMethodError)
轉載于:https://www.cnblogs.com/kingofark/archive/2006/12/13/591118.html
總結
以上是生活随笔為你收集整理的DHH观点:为什么我偏爱Ruby?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Web服务初探:用Demo学Web服务系
- 下一篇: 想到就去做