What is not "Least Surprise" in Ruby [closed]
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 :
- 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. - socket search dns name for any accept, do
BasicSocket.do_not_reverse_lookup = true
for do not be surprise by long delay split(regexp)
don't split empty field in the end of string, dosplit(regexp,-1)
for splitting all stringstring.trim
is unknown, usesting.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.
精彩评论