[swift-evolution] Constant initialization and unreachable code.

Alex Martini amartini at apple.com
Wed Oct 19 11:37:24 CDT 2016


> On Oct 19, 2016, at 4:50 AM, David Goodine via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Hey all,
> 
> I don’t know if this is really an ‘evolution’ topic per se, and I’m not on Swift Dev, but thought someone here could shed some light on this.
> 
> Often when developing code, if I need create mode switches (constant Bools) so that I can move back and forth between different features/implementations for testing, developing experimental features, migration, etc.  Currently if I write the following:
> 
> let useFoo = true
> 
> if useFoo {
> // Foo code
> } else {
> // Non-Foo code
> }

In your debugging, do you actually need this condition to be evaluated at runtime?  For example, in the debugger, are you changing the value of useFoo at runtime to switch which branch is used?

If not, maybe #if would be better — it makes the decision at compile time.  I don't get any warnings from the following code:

let useFoo = true

#if useFoo
    print("foo code")
#else
    print("non-foo code")
#endif

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


More information about the swift-evolution mailing list