[swift-evolution] Import Conditionals

Sean Alling allings at icloud.com
Mon Oct 17 17:05:03 CDT 2016


Description

In an effort to both (1) reduce boilerplate code, and (2) promote cross-platform reusability I propose that we implement the following Import Conditional Operators: 

`||` and `&&`

Currently, import conditionals must be implemented like so:

```
#if os(Linux) || os(FreeBSD)
	import Glibc
#else
	import Darwin
#endif
```

With import conditional operators this would be condensed to:

```
import Glibc || Darwin
```

The first library/framework (Glibc) would be imported if found and the the second (Darwin) only in the event the first should fail.

Other Caveats:

(A) —  we could limit this to one conditional operator per import line OR we could implement order of operations. Obviously, there are tradeoffs of both that we should discuss.

(B) — if-conditional statements currently explicitly show the import conditions (i.e., os(Linux) || os(FreeBSD)) this would be a detriment to this new feature. I would argue that the reduction of boilerplate code would in itself be worth this abstraction.


--
Sean Alling

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


More information about the swift-evolution mailing list