in reply to Re: No braces
in thread No braces

In perl, it's counter-intuitive to say something like:
do_something() if(COND);
Why is it counter-intuitive in Perl? It might be counter-intuitive for you, but that doesn't mean you can generalize that. It may be counter-intuitive for you to say I use my umbrella if it rains, but that doesn't make it counter-intuitive to say it in English. For the majority of the English speakers, it's not counter-intuitive to say "Effect if condition", and the counter intuitiveness of such a statement doesn't depend on the language.

Abigail

Replies are listed 'Best First'.
Re: Re: No braces
by saberworks (Curate) on Feb 11, 2004 at 20:26 UTC
    I didn't mean that "just in perl" it's counter-intuitive, I meant, the way perl forces you to do it is counter-intuitive. Of course what is intuitive differs depending on the person, I just find it much more natural to put the condition first. I would never say, "I use my umbrella if it rains." I would say, "If it rains, I'll use my umbrella." Of course as the reply stated below, I could wrap the whole thing in parens and use && but that (IMO of course) is still not as intuitive as saying if(COND) do_something(); I've been working with perl now for years and I still pause and scratch my head when I see that in code. I fear I'll never get used to it.

    Either way, I didn't mean to say that it was only counter-intuitive in perl.
      I meant, the way perl forces you to do it is counter-intuitive.
      But Perl doesn't require you to do it this way. Perl allows to put either the cause, or the effect to go first.

      Abigail

        Sort of. You can only say if(COND) { do_something; } - you can't leave off the braces and still use that construct. You'd have to do something more funky using &&, etc.