开发者

What is not "Least Surprise" in Ruby [closed]

开发者 https://www.devze.com 2022-12-14 17:34 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 12 years ago.

Matz said :

开发者_StackOverflowI designed Ruby to minimize my surprise. I wanted to minimize my frustration during programming, so I want to minimize my effort in programming.

But sometime we get (bad) surprise in ruby practice.

As beginner in ruby, I found some example :

  1. Exception Thread do not produce any immediate traces by default, we must do Thread.abort_on_exception = true or don't forget to join all thread.
  2. socket search dns name for any accept, do BasicSocket.do_not_reverse_lookup = true for do not be surprise by long delay
  3. split(regexp) don't split empty field in the end of string, do split(regexp,-1) for splitting all string
  4. string.trim is unknown, use sting.strip in place (for old tcl dev...)

Have you other case for improve my ruby practice ?

thank you.


The design of Ruby the language is different from the design of Ruby libraries (which mostly seem to be what you use as examples). Matz designed the language around the principle of least surprise, but not every library (even modules in the Ruby standard library) were designed that way. (Keep in mind that Matz didn't write every Ruby library, or even the entire Ruby standard library, himself.)


A gentle note, I think you are over-extending the idea of least surprise. To me you are extending Matz's idea of least surprise from his idea of least surprise to include your idea of least surprise. Remember that what surprises you may not surprise another and may in fact surprise them if it worked the way that you think it should. All that said, it's good to voice your opinions about how you think it should work because we can all learn from it but to say that "we get (bad) surprise" is extending your idea of surprise onto others.

As for me, all of these examples have the feel that you want these to work better for your preference (or app) than the general case.

0

精彩评论

暂无评论...
验证码 换一张
取 消