[Discussion] "try" for function that does not throw


(Vladimir) #1

I didn't expect this is allowed(with warning):

try print("foo")

(Swift Ver. 3.0 (Jun 20, 2016))

Do we really need to allow 'try' for functions that does not throw exceptions?


(David Sweeris) #2

What's the harm?

- Dave Sweeris

···

On Jul 7, 2016, at 12:58, Vladimir.S via swift-evolution <swift-evolution@swift.org> wrote:

I didn't expect this is allowed(with warning):

try print("foo")

(Swift Ver. 3.0 (Jun 20, 2016))

Do we really need to allow 'try' for functions that does not throw exceptions?


(Chris Lattner) #3

This seems like totally fair game for a “warning: ‘try’ specified for expression that does not throw” with a fixit to remove it. Please file an enhancement request in bugs.swift.org, this isn’t something appropriate for an evolution proposal.

-Chris

···

On Jul 7, 2016, at 10:58 AM, Vladimir.S via swift-evolution <swift-evolution@swift.org> wrote:

I didn't expect this is allowed(with warning):

try print("foo")

(Swift Ver. 3.0 (Jun 20, 2016))

Do we really need to allow 'try' for functions that does not throw exceptions?


(John McCall) #4

I didn't expect this is allowed(with warning):

try print("foo")

(Swift Ver. 3.0 (Jun 20, 2016))

Do we really need to allow 'try' for functions that does not throw exceptions?

This seems like totally fair game for a “warning: ‘try’ specified for expression that does not throw” with a fixit to remove it. Please file an enhancement request in bugs.swift.org, this isn’t something appropriate for an evolution proposal.

Agreed.

John.

···

On Jul 7, 2016, at 3:26 PM, Chris Lattner via swift-evolution <swift-evolution@swift.org> wrote:

On Jul 7, 2016, at 10:58 AM, Vladimir.S via swift-evolution <swift-evolution@swift.org> wrote:

-Chris

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Haravikk) #5

None as such, but you argue that a warning in this case is safer; for example, if you had two similar functions, one of which throws, then typing try on the wrong one will produce a warning that can alert you to the mistake, while the current behaviour never will (in fact the presence of try may make the error harder to spot, as it *looks* correct).

So yeah, I'm surprised this is the case, should probably be turned into a warning.

···

On 7 Jul 2016, at 19:41, David Sweeris via swift-evolution <swift-evolution@swift.org> wrote:

On Jul 7, 2016, at 12:58, Vladimir.S via swift-evolution <swift-evolution@swift.org> wrote:

I didn't expect this is allowed(with warning):

try print("foo")

(Swift Ver. 3.0 (Jun 20, 2016))

Do we really need to allow 'try' for functions that does not throw exceptions?

What's the harm?


(Ben Rimmington) #6

<https://bugs.swift.org/browse/SR-2024>

-- Ben

···

On 7 Jul 2016, at 23:28, John McCall via swift-evolution <swift-evolution@swift.org> wrote:

On Jul 7, 2016, at 3:26 PM, Chris Lattner via swift-evolution <swift-evolution@swift.org> wrote:

On Jul 7, 2016, at 10:58 AM, Vladimir.S via swift-evolution <swift-evolution@swift.org> wrote:

I didn't expect this is allowed(with warning):

try print("foo")

(Swift Ver. 3.0 (Jun 20, 2016))

Do we really need to allow 'try' for functions that does not throw exceptions?

This seems like totally fair game for a “warning: ‘try’ specified for expression that does not throw” with a fixit to remove it. Please file an enhancement request in bugs.swift.org, this isn’t something appropriate for an evolution proposal.

Agreed.

John.


(Tino) #7

A try that isn't needed is suspicious… but imho there is a problem with warnings, but that isn't primarily caused by Swift itself.

Xcode creates warning as you type, and those often don't help, but just distract, as most of them aren't actually dangerous at all:
- Yes, I'm not using this value yet… but I promise I'll do so five lines further down
- The same with vars that are waiting for their first change
(those two are the worst for me)
Things like those don't help me at all, but are rather a distraction — but I'm no fan spoon-feeding in general, and would prefer to move most Swift-warnings out of the compiler and into a linter.

Tino


(Mark Dalrymple) #8

Xcode creates warning as you type

And the warnings also tend to obscure my typing (rdar://27141386 - warning
box occludes typing when trying to fix a warning).

I turn live issues off (even though that kind of breaks playground error
reporting - rdar://27162167 - playgrounds don't show any errors unless Live
Issues is on) - I know enough of what I'm doing to where I can wait until
the code isn't in an indeterminate state any more and then kick off a build
to error-check.

command-control-M is also a favorite keystroke to hide the in-editor
notices. You still get them in the gutter.

++md

···

On Fri, Jul 8, 2016 at 5:00 AM, Tino Heth via swift-evolution < swift-evolution@swift.org> wrote:

A try that isn't needed is suspicious… but imho there is a problem with
warnings, but that isn't primarily caused by Swift itself.

Xcode creates warning as you type, and those often don't help, but just
distract, as most of them aren't actually dangerous at all:
- Yes, I'm not using this value yet… but I promise I'll do so five lines
further down
- The same with vars that are waiting for their first change
(those two are the worst for me)
Things like those don't help me at all, but are rather a distraction — but
I'm no fan spoon-feeding in general, and would prefer to move most
Swift-warnings out of the compiler and into a linter.

Tino
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution