[swift-evolution] thoughts on 'inout'

Radosław Pietruszewski radexpl at gmail.com
Thu Feb 11 17:51:10 CST 2016


If we were to change stuff for greater conciseness, don’t you think

	func addInt(a: &Int, b: &Int)
	addInt(&a, &b)

would be a less confusing solution than messing with : and = ?

— Radek

> On 12 Feb 2016, at 00:17, Oliver M via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 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 = 2
> var adder = 3
> var 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.
> 
> 
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

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


More information about the swift-evolution mailing list