| Thread overview | ||||||||
|---|---|---|---|---|---|---|---|---|
|
May 21, 2004 Perl's if and unless | ||||
|---|---|---|---|---|
| ||||
I've never really liked Perl's general appearance except for its alternate if and unless constructs.
These have the structure:
<statement> if <condition>;
<statement> unless <condition>;
e.g.
print "INFO: this is a message\n" if $verbose && $debug_level >= DBG_INFO;
process_input() unless length $input == 0;
The alternate if construct is equivalent to the D:
if (<condition>)
{
<statement>;
}
The alternate unless construct is equivalent to the D:
if (! <condition>)
{
<statement>;
}
I really like the unless because it reads so well.
"do this unless this is true"
I would think this bit of syntactic sugar wouldn't be too hard to add to D since it's just a simple transformation.
I apologize if this has been requested and debated already.
Brian
| ||||
May 21, 2004 Re: Perl's if and unless | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Brian Hammond | <snip>
><statement> if <condition>;
><statement> unless <condition>;
</snip>
Always makes me think of a bomb squad technician in a comedy:
"Now cut the blue wire... <pause> but before you do that..."
| |||
May 21, 2004 Re: Perl's if and unless | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Juan C | Juan C wrote:
> <snip>
>
>><statement> if <condition>;
>><statement> unless <condition>;
>
> </snip>
>
> Always makes me think of a bomb squad technician in a comedy:
>
> "Now cut the blue wire... <pause> but before you do that..."
>
>
I have to say that this is one of the ugliest constructs I've ever faced. :)
--Steve
[glad to say that my perl hacking days are mostly behind me..]
| |||
May 22, 2004 Re: Perl's if and unless | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Brian Hammond | "Brian Hammond" <d at brianhammond dot comBrian_member@pathlink.com> wrote in message news:c8lmu2$vdm$1@digitaldaemon.com... > I really like the unless because it reads so well. > > "do this unless this is true" That just seems backwards to me <g>. I like things to execute forwards, not backwards. | |||
May 22, 2004 Re: Perl's if and unless | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter | >> I really like the unless because it reads so well.
>>
>> "do this unless this is true"
>
>That just seems backwards to me <g>. I like things to execute forwards, not backwards.
Well she's your baby so that's that :-)
Brian
| |||
May 22, 2004 Re: Perl's if and unless | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Brian Hammond | "Brian Hammond" <d at brianhammond dot comBrian_member@pathlink.com> wrote in message news:c8mh1p$264r$1@digitaldaemon.com... > >> I really like the unless because it reads so well. > >> > >> "do this unless this is true" > > > >That just seems backwards to me <g>. I like things to execute forwards, not > >backwards. > > Well she's your baby so that's that :-) Thank god for that. It seems a bit strange to me as well. I dont like using a do / while either. Phill | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply