Swift: Lack of conditional compilation makes common debugging idioms more difficult
| Originator: | rix.rob | ||
| Number: | rdar://17427612 | Date Originated: | 23-Jun-2014 07:34 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode6-Beta2 (6A216f) |
| Classification: | Serious Bug | Reproducible: | Always |
Summary: The lack of conditional compilation makes it more difficult to implement common debugging idioms such as logging in debug builds. For example, it isn’t clear how one would implement Swift.assert without this. Steps to Reproduce: 1. Try to write an inline unit testing library. Expected Results: I expected (hoped) to find an easy, obvious, and well-documented way to exclude unit test cases from release builds. Actual Results: I realized that although I can definitely add tests, and I can probably even run them, it’s rather more difficult to see how to ensure they get compiled out of release builds. Regression: N/A Notes: It may be that this is possible to ensure via linker flags or some such. If so, I’d sure like to know about it :) My project Lagrangian ( https://github.com/robrix/Lagrangian ) looks like it should adapt very elegantly to Swift despite the lack of macros, due primarily to Swift’s function & operator overloading (and possibly a bit to reflect()/Mirror, but I doubt I’ll even need that). This appears to be the only missing ingredient—colour me delighted!
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
What about auto closures?
For example:
func assert(@auto_closure cond : ()->Bool, @auto_closure log : ()->String) { #if DEBUG if !cond() { println(log()) // exit? } #endif }