develooper Front page | perl.perl6.language | Postings from May 2004

Re: C style conditional statements

Thread Previous | Thread Next
From:
Matthew Walton
Date:
May 12, 2004 01:47
Subject:
Re: C style conditional statements
Message ID:
40A1E488.4040504@alledora.co.uk
St├ęphane Payrard wrote:
> Le Wed, May 12, 2004 at 02:00:42AM +0200, le valeureux mongueur Pedro Larroy a dit:
> 
>>Hi
>>
>>Is there any chance that in perl6 there will be the possibility to write
>>if/else statements without {}s with the condition at the beginning?
>>
>>Like 
>>
>>if (condition)
>>	statement;
>>
>>In order not to break traditional C culture. Is there any technical
>>reason why it wasn't done in perl5? 
> 
> 
> In Perl5, variable declaration are an executable statement. Also the
> scope of a variable starts from its declaration and ends at the
> end of the immediately enclosing block. Things would get
> problematic if the branches of an if/else were not scoped.
> What would be the meaning of :
> 
> if (condition)
>    my $foo = 'bar';
> else
>    print $foo;

Not entirely sure, but according to the camel book, another reason for 
the braces being compulsory is that Perl makes a distinction between a 
block and a statement, whereas in C a block is actually (sometimes) a 
kind of statement - indeed a compound statement. Of course, it's 
possible that was just an excuse, but it does make a fair bit of sense. 
Especially since Perl's got things like anonymous subroutines and 
closures, which are sort of fancy blocks, and ultimately one has to 
realise that { and } don't mean the same thing in Perl at all. They just 
*look* like they do.

I am actually glad to see Perl 6 extending this trend, as it seems to be 
using { and } for Good Things. I wouldn't argue at all that it's 
important to keep familiarity for C programmers anymore (so sayeth the 
Haskell programmer), although it might perhaps be a little early to go 
for Python-like syntax. For some reason, lots of people don't like it 
when indentation is what's controlling their code structure...


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About