Hacker News new | past | comments | ask | show | jobs | submit login

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.




I 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 :)


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


    die "Port numbers below 1024 are forbidden"
        if $port < 1024;
is hardly unreadable spaghetti code.


Okay. 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());


My head hurts! Does unless apply to both branches or just one. The if example is easier for sure.


> 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


Ruby is basically Perl++


ruby is OOPerl


Ruby is Perl 6




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: