This proposal consists in adding a functionally that I find useful in VB .net, 
that lets you set a default return value of a function at the begging rather 
than at the end

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
}

In all of the cases the compiler will check that a default return is set before 
exiting the function
It could be some combination of the 3 proposals

Thanks
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to