develooper Front page | perl.perl6.language | Postings from April 2008

'returns' vs 'of'

Thread Next
From:
John M. Dlugosz
Date:
April 12, 2008 22:28
Subject:
'returns' vs 'of'
I don't like the assignments of 'returns' and 'of'.  I think it is easily confused.  I've written

foo (Int $x)
returns Int

in examples and nobody noticed.  As formal documentation, that scans right as the outer perceived return value type.  But no, it's supposed to be

foo (Int $x)
of Int

instead.  The returns keyword affects the implementation of the function, not the external contract.  

Yet, if returns is missing it uses the of value by default, but if the of is missing it does not give static type checking to the caller, rather than using the same as the returns.

Will other programmers make the same mistake?  I think it's going to be a problem.  It's like thinking you used strict but did not, and the compiler wasn't telling you things it should have.

--John

Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About