<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>This kind of pattern (which I've always considered the "builder pattern") is useful in various circumstances, but I don't think it is reasonable to assume that it's the appropriate pattern to use by default for any mutating method.<br></div>
<div> </div>
<div>I'd much rather see an explicit method cascade operator added (e.g. Dart's .. operator), which fulfills the same desire but without requiring any API or even ABI changes, and without adding the overhead of duplicating values all over the place (e.g. all the now-implicit-self return values that aren't actually used by the caller).<br></div>
<div> </div>
<div>-Kevin Ballard</div>
<div> </div>
<div>On Sat, Dec 19, 2015, at 09:21 AM, Tino Heth via swift-evolution wrote:<br></div>
<blockquote type="cite"><div>Hi there,<br></div>
<div> </div>
<div>this idea might be quite unconventional, but it is simple and wouldn't break any existing code.<br></div>
<div>Returning void has no use beside telling "there is nothing to return" and makes it impossible to perform method chaining, which drives popular systems like iostream and LINQ (the concept was promoted by Martin Fowler as fluent interface - but wikipedia has a good explanation on this: <a href="https://en.wikipedia.org/wiki/Fluent_interface">https://en.wikipedia.org/wiki/Fluent_interface</a>)<br></div>
<div>One of its most popular use cases is database access, which imho will become quite important for Swift as it might gain popularity in the server domain.<br></div>
<div>It is useful in other areas as well, but I'll stick to databases in an example:<br></div>
<div> </div>
<div>let kids = userDatabase.select(.name).where(.age < 18)<br></div>
<div> </div>
<div>This is already possible in Swift today, but with a simple change, it could be much more fun:<br></div>
<div>I guess void is the natural choice for a default return value - what else is guaranteed to exist in a function?<br></div>
<div>For methods, on the other hand, there is a real object that is always available: self.<br></div>
<div>If self would be the default return value, we would get method chaining for free in all places where we now stuck with void - and whoever doesn't like the concept can still ignore the value as he did with ().<br></div>
<div> </div>
<div>I have to admit that right now there is a proposal that wants to sanction ignoring non-void return values with warnings, which would interfere with this idea; but imho even in this case the workarounds wouldn't be that complicated.<br></div>
<div> </div>
<div>So, please give feedback wether it is worth the burden of writing a official proposal or start by creating a library with the current toolset and try to prove the usefulness of fluent interfaces ;-)<br></div>
<div> </div>
<div>Best regards,<br></div>
<div>Tino<br></div>
<div><img style="height:1px !important;width:1px !important;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;border-left-width:0px !important;margin-top:0px !important;margin-bottom:0px !important;margin-right:0px !important;margin-left:0px !important;padding-top:0px !important;padding-bottom:0px !important;padding-right:0px !important;padding-left:0px !important;" border="0" height="1" width="1" alt="" src="https://www.fastmailusercontent.com/proxy/876ec2df2e69b8cd5b353fc4cddefeb65e77b5b1368cbdc926b2895f0b45776c/8647470737a3f2f25723030323431303e23647e23756e64676279646e2e65647f27766f2f60756e6f35707e6d3148765176786c673171614a7d2236454230345272776e466340724177333f634c6d454c46527b6261516742324456743955607a5d22324a594a4a585a49436e6b4754665f6c48735766665944646d2236434f4573676d22324940545f4133347d223242465b444f44795c4437503e68673e4d43324d223649575f4445385d4860707a76727a43325767653633786b6b4a77656161616355663563716b6231363b41714455707963665c63627339307866537247347970536e6a4535385c637939724632654c4658374333317772595a5242594459384e6f4942394d22364d624f677d2232477d23344d23344/open"><br></div>
<div><u>_______________________________________________</u><br></div>
<div>swift-evolution mailing list<br></div>
<div><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br></div>
<div><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</blockquote><div> </div>
</body>
</html>