[swift-evolution] Code comments that check code validity.

Amir Michail a.michail at me.com
Sat Jan 14 17:50:31 CST 2017


> On Jan 14, 2017, at 6:46 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
> 
> On Sat, Jan 14, 2017 at 5:35 PM, Amir Michail <a.michail at me.com <mailto:a.michail at me.com>> wrote:
> 
> > On Jan 14, 2017, at 6:28 PM, Xiaodi Wu <xiaodi.wu at gmail.com <mailto:xiaodi.wu at gmail.com>> wrote:
> >
> > This has been brought up on this list before. The conclusion of the previous thread on this topic was that there is a way to do this:
> >
> > #if false
> > // put your code here
> > #endif
> >
> 
> This would not check the code for compilability within the surrounding code. This requires more than a syntax check.
> 
> I can't say I've ever needed that feature; could you share a concrete use case?
> 

Consider an array of levels for a game where some levels are commented out for possible future use. It would be nice to have such level entries continue to compile as the code elsewhere evolves and yet not be included in the executable.

> In any case, if you put code in a function that's not exported and never invoked, I believe you would achieve the desired effect. Within the body of a function, you could do so in a closure.
> 
> ```
> func foo() {
>   // code you want to run
>   _ = {
>     // code you don't intend to run
>   }
>   // more code you want to run
> }
> ```
> 
> > It does not allow you to comment out fragments of a single statement, but the incremental value of devoting time to additionally support that is, it would seem, low.
> >
> > On Sat, Jan 14, 2017 at 17:18 Amir Michail via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> > The code in a “code comment" must compile (not just be syntactically correct) yet must not have any effect on the resulting executable.
> >
> > For example, commented entries in an array would be checked for compilability but would not be included in the executable.
> >
> > Such “code comments" would allow you to have code/data that is currently unused but is constantly checked to be valid just in case you want to use it in the future.
> >
> > _______________________________________________
> > swift-evolution mailing list
> > swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> > https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> 
> 

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


More information about the swift-evolution mailing list