[swift-evolution] [Idea] Distinguishing code comments from text comments.

Xiaodi Wu xiaodi.wu at gmail.com
Mon Aug 29 16:26:02 CDT 2016


On Mon, Aug 29, 2016 at 4:15 PM, DifferentApps info via swift-evolution <
swift-evolution at swift.org> wrote:

> Thanks for your pattern suggestion.
> But it would be also possible to switch between implementations with the
> proposed syntax as shown bellow:
>
> /{
>    <code 1>
> }/
> do {
>    <code 2>
> }
>
>
That would be greatly inferior, as you'd have to edit the code in four
distinct places, versus a single one (change #if false to #if true).


>
> Le 29 août 2016 à 22:53, Magnus Ahltorp <map at kth.se> a écrit :
>
> >> 29 Aug. 2016 22:16 DifferentApps info <andre_ponzo at differentapps.com>
> wrote:
> >>
> >> The advantage is that you do not need to define a conditional flag for
> the #if.
> >
> > The good news is, you don't.
> >
> > #if false
> >  print("Disabled code")
> > #endif
> >
> > which is a time-tested way of writing C code (using #if 0).
> >
> > From the Swift changelog, where they even call it an idiom of C:
> >
> > 2014-04-30
> > […]
> > * You can now use the `true` and `false` constants in build
> configurations,
> >  allowing you to emulate the C idioms of `#if 0` (but spelled `#if
> false`).
> >
> > One pattern I use all the time, both in C and in Swift, is this:
> >
> > #if false
> > <experimental code>
> > #else
> > <old code>
> > #endif
> >
> > which makes it possible to switch between the implementations quickly,
> something you cannot do with the proposed syntax.
> >
> >> Code disabling (with /{...}/) is a tool useful when developing
> algorithm, and disabled code should not be aimed to remain definitively in
> a Swift file.
> >
> > Which is in no way dependent on if you use the proposed syntax,
> traditional comments, or conditional compilation.
> >
> > /Magnus
> >
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160829/e5d3dfd1/attachment.html>


More information about the swift-evolution mailing list