<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I agree that this could do with revision. It looks particularly ugly when you’re dealing with throwing closures.<div class=""><br class=""></div><div class="">Recently I had a signature like:</div><div class=""><br class=""></div><div class=""><font style="font-size: 11px;" face="Menlo" class="">public&nbsp;func&nbsp;scan(length:&nbsp;File.ByteOffset.Stride?,<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;by frameSize:&nbsp;File.ByteOffset.Stride,<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with handler: (_&nbsp;range:&nbsp;Range&lt;File.ByteOffset&gt;,&nbsp;_&nbsp;data:&nbsp;UnsafeRawBufferPointer)&nbsp;throws&nbsp;-&gt;&nbsp;Bool)&nbsp;throws&nbsp;-&gt;&nbsp;File.ByteOffset.Stride</font></div><div class=""><br class=""></div><div class="">It can get difficult to parse the signature towards the end. Marking the handler and function as throwing closer to the beginning would make it more readable IMO. One thing it allows me to do more easily is to remove the spaces around the arrow for the closure parameter (just a little thing which I find helps me read the trailing closure/return type more quickly).</div><div class=""><br class=""></div><div class=""><div class=""><font style="font-size: 11px;" face="Menlo" class="">public throwing func&nbsp;scan(length:&nbsp;File.ByteOffset.Stride?,<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;by frameSize:&nbsp;File.ByteOffset.Stride,<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with handler: throwing (_&nbsp;range:&nbsp;Range&lt;File.ByteOffset&gt;,&nbsp;_&nbsp;data:&nbsp;UnsafeRawBufferPointer)-&gt;Bool) -&gt;&nbsp;File.ByteOffset.Stride</font></div></div><div class=""><br class=""></div><div class="">- Karl</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 26 Dec 2016, at 18:38, thislooksfun via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hello Swifters,<div class=""><br class=""></div><div class="">I've been writing a lot more Swift code recently, and I have found that the default placement of the 'throws' declaration is often confusing, especially to those of us switching from languages where the type of errors thrown is explicitly defined (like Java)</div><div class=""><br class=""></div><div class="">For example,</div><div class=""><div class="bloop_markdown" style="font-family: Helvetica, Arial; font-size: 13px; background-color: rgb(254, 254, 254);"><pre style="margin-top: 15px; margin-bottom: 15px; font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(204, 204, 204); overflow: auto; padding: 4px 8px; word-break: normal; word-wrap: normal;" class="">// This is pretty clear, this can throw an error
func foo() throws
{ ... }

// Also pretty clear, this returns a String
func bar() -&gt; String
{ ... }

// Confusing. Does this throw a String? Does it return a String? Does it do both?
// I personally keep reading this as 'this can throw a String'
func baz() throws -&gt; String

// Equivalent code in Java (not a model, just for clarification of why the above is confusing)
String baz() throws StringFormatException</pre></div><div class="">I therefore suggest either tweaking the syntax around, or moving, the `throws` keyword to avoid this confusion.</div><div class=""><br class=""></div><div class="">Some ideas I've had:</div><div class=""><pre style="color: inherit; margin-top: 15px; margin-bottom: 15px; font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); border: 1px solid rgb(204, 204, 204); overflow: auto; padding: 4px 8px; word-break: normal; word-wrap: normal;" class="">// Add a comma to separate them
func baz() throws, -&gt; String

// Move `throws` to the end
func baz() -&gt; String throws

// Change it to a prefix modifier (like `mutating`)
throwing func baz() -&gt; String
</pre></div><div class="">I'm still not sold on any of the above syntaxes, but I would love to hear your feedback.</div><div class=""><br class=""></div><div class="">This would affect existing code, but it would be a fairly small change that would result in very large readability improvements, especially for newcomers, and <i class="">especially</i>&nbsp;for those coming for a language such as Java.</div><div class=""><br class=""></div><div class=""><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">-thislooksfun (tlf)</div>

</div>
<br class=""></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>