Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ruby

Matz said :

I 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.

like image 972
raubarede Avatar asked Dec 21 '09 11:12

raubarede


2 Answers

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.)

like image 165
mipadi Avatar answered Nov 09 '22 08:11

mipadi


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.

like image 20
aDev Avatar answered Nov 09 '22 09:11

aDev