[swift-evolution] thoughts on 'inout'

Oliver M selectedfordeletion at yahoo.com
Thu Feb 11 17:17:25 CST 2016


Regarding In-Out Parameters:
My gut reaction to typing 'inout' in front of every parameter I want to call by reference is that it makes code look rather waffly.
So I'm reflecting an idea on this:

Use = to assign values.
Use : to associate variables.


A function declaration would look like this:
func addInt(add intToAdd = Int, to counterInt : Int ) {
    counterInt += intToAdd
}


Here is example code for a game of 'think of a number' where you pick a random number and do some basic maths on it.

//declare the function
func multiplyAdd(multiplyBy intToMultiply = Int, add intToAdd = Int, toNumber pickedInt : Int) {    pickedInt *= intToMultiply    pickedInt += intToAdd
}


//declare some variables
var multiplier = 2var adder = 3var pickNumber = 4

//call the function
multiplyAdd(multiplyBy = multiplier, add = adder, toNumber : pickNumber)

It takes a little getting used to, but it does look quite clean.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160211/f2829801/attachment.html>


More information about the swift-evolution mailing list