<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body 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() -> 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 -> 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, -> String
// Move `throws` to the end
func baz() -> String throws
// Change it to a prefix modifier (like `mutating`)
throwing func baz() -> 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> for those coming for a language such as Java.</div><div class=""><br class=""></div><div class=""><div style="color: rgb(0, 0, 0); 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></body></html>