4 ms·
To be fair, Ruby inherited "unless" from Perl. And Perl literally has the opposite design principle, TIMTOWTDI or "there is more than one way to do it". I'm n
by sshine 4y ago
To be fair, Ruby inherited "unless" from Perl.
And Perl literally has the opposite design principle, TIMTOWTDI or "there is more than one way to do it".
I'm not arguing here -- I prefer the "one obvious way" principle.
But you can design a beautiful programming language without regard for the long-term learnings of software engineering.
I always liked Perl's "unless", and I always made sure to not abuse it with double negatives or other contorted conditions that are, in themselves, reasonable. I also promised myself I wouldn't write very big programs in Perl.
- aspyct 4y agoRuby is basically Perl++
- lloeki 4y ago> Everyone has an individual background. Someone may come from Python, someone else may come from Perl, and they may be surprised by different aspects of the language. Then they come up to me and say, 'I was surprised by this feature of the language, so Ruby violates the principle of least surprise.' Wait. Wait. The principle of least surprise is not for you only. The principle of least surprise means principle of least my surprise. And it means the principle of least surprise after you learn Ruby very well. For example, I was a C++ programmer before I started designing Ruby. I programmed in C++ exclusively for two or three years. And after two years of C++ programming, it still surprises me. - Matz, c.a 2003
- TurboHaskal 4y agoI came to Ruby from Perl, and I love `unless`. One of the first things I do in any Lisp is build my own unless macro unless the dialect already has it :)
- nolls 4y ago
- gpvos 4y agoI only know `unless` from Perl, and it can make your code clearer if used sparingly. For example it allows you to express preconditions positively: die "You may only use port numbers 1024 and higher" unless $port >= 1024;
- TomSwirly 4y agodie "Port numbers below 1024 are forbidden" if $port < 1024; is hardly unreadable spaghetti code.
- gpvos 4y agoOkay. Now compare: die "You may only use port numbers 1024 and higher" unless $port >= 1024 || is_root(current_uid()); die "Port numbers 1024 are forbidden" if $port < 1024 && !is_root(current_uid());
- hashhar 4y agoMy head hurts! Does unless apply to both branches or just one. The if example is easier for sure.
- deleted 4y ago[deleted]