[swift-evolution] [proposal] default returns
    Charles Srstka 
    cocoadev at charlessoft.com
       
    Tue May 10 19:45:07 CDT 2016
    
    
  
> On May 10, 2016, at 7:11 PM, Eduardo Mourey Lopez Ne via swift-evolution <swift-evolution at swift.org> wrote:
> 
> current:
> func myComplexOperation() -> Int {	
> 	//Some long complex code that might return some value
>       //Default return at the very end
>       return 0
> }
> 
> proposal:
> func myComplexOperation() -> Int {
> 	//set the default return at the begging using the ‘default’ keyword or some other keyword
> 	default 0
> 	//Some long complex code that might return a value
> 	//if the end of the function is reached, return the default
> }
> 
> The other alternative will be to allow naming the return value
> proposal2:
> func myComplexOperation() -> result:Int {
>        //set the default return at the begging using the output variable name
> 	result = 0
> 	//Some long complex code that might return some value
> }
> 
> Another alternative will be to set the default value directly like and optional parameter
> proposal3:
> func myComplexOperation() -> Int = 0 {
> 	//Some long complex code that might return some value
> }
Is this really that much more convenient than:
func myComplexOperation() -> Int {
    let default = 0
    // do something
    return default
}
to justify a whole language feature?
Charles
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160510/d4dbe6d9/attachment.html>
    
    
More information about the swift-evolution
mailing list