<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi Ewa!<div class=""><br class=""></div><div class="">In commit 93786d8e264d095256169a6a2552970ea785036f, you wrote: “Removing isSwiftVersion4, isSwiftVersion5. We’ll need to come up with a better way to conditionalize code based on language version.”</div><div class=""><br class=""></div><div class="">This is certainly true! I wondered what would happen as new versions came along. :-)</div><div class=""><br class=""></div><div class="">It seems to me like the right approach is this:</div><div class=""><span style="font-family: Courier;" class=""><br class=""></span></div><div class=""><span style="font-family: Courier;" class=""> bool isSwiftVersionLessThan(unsigned major, unsigned minor = 0);</span></div><div class=""><font face="Courier" class=""> // hopefully we’ll never need ’minor’ level precession</font></div><div class=""><br class=""></div><div class="">With such an API, bug fixes, version specific behavior, and future features are easy to implement:</div><div class=""><br class=""></div><div class=""><font face="Courier" class=""><b class="">// Bug fixed in version 4</b></font></div><div class=""><font face="Courier" class="">if (isSwiftVersionLessThan(4)) {</font></div><div class=""><font face="Courier" class=""> // old way</font></div><div class=""><font face="Courier" class="">} else {</font></div><div class=""><font face="Courier" class=""> // new way</font></div><div class=""><font face="Courier" class="">}</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><div class=""><div class=""><font face="Courier" class=""><b class="">// Version 7 feature work</b></font></div><div class=""><div class=""><font face="Courier" class="">if (isSwiftVersionLessThan(7)</font><span style="font-family: Courier;" class="">) {</span></div><div class=""><font face="Courier" class=""> // pre feature logic</font></div><div class=""><font face="Courier" class="">} else {</font></div><div class=""><font face="Courier" class=""> // new feature work logic</font></div><div class=""><font face="Courier" class="">}</font></div></div></div></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class=""><b class="">// Broken behavior specific to version 3 and 4, but not version 1, 2, and 5+</b></font></div><div class=""><div class=""><font face="Courier" class="">if (isSwiftVersionLessThan(5) && !</font><span style="font-family: Courier;" class="">isSwiftVersionLessThan(3)</span><span style="font-family: Courier;" class="">) {</span></div><div class=""><font face="Courier" class=""> // Swift 3 and 4 code</font></div><div class=""><font face="Courier" class="">} else {</font></div><div class=""><font face="Courier" class=""> // normal path</font></div><div class=""><font face="Courier" class="">}</font></div><div class=""><br class=""></div></div><div class="">Alternatively, the API could be “isSwiftVersionGreaterThanOrEqualTo()” but that seems like a mouthful. Similarly, the API could be “isSwiftVersionInHalfOpenRange()”, but that seems awkward because the future is hopefully endless.</div><div class=""><br class=""></div><div class="">What to people think?</div><div class=""><br class=""></div><div class="">Dave</div></body></html>