<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div><br></div><div><br>On Aug 17, 2016, at 11:59 PM, Tino Heth &lt;<a href="mailto:2th@gmx.de">2th@gmx.de</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><div><br class=""><blockquote type="cite" class=""><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Let’s discuss something else. Actually there is an easy fix: make all functions accept optionals. I think this is a really bad idea</span></div></blockquote></div>Indeed.<div class="">I don't think there is a good motivation to change the status quo:</div><div class="">You can't "sugar away" everything; sometimes, you just have to write a line of code that does what you want.</div><div class="">As you can "if let" convert as many optionals as you like in a single statement, it really doesn't hurt that much.</div><div class=""><br class=""></div><div class="">The precondition stuff looks exactly like guard inside the function to me… what's the benefit of that?</div></div></blockquote><br><div>It won't change the original function. It's like adding a new function. It won't affect the original function. For example: if view is non optional then the function won't throw.&nbsp;</div><div><br></div><div>func addSubview(_ view: UIView?) throw</div><div>func addSubview(_ view: UIView)</div><div><br></div><div>It's only a very rough idea. But this is not limited to checking nil. *Maybe* in the future we can achieve something like this:</div><div><br></div><div>----</div><div>func randomInt() -&gt; Int { }</div><div><br></div><div>precondition count &gt; 0 else { return nil }</div><div>func getCellSize(forItemsInRow count: Int) -&gt; CGSize { }</div><div><br></div><div>let numberOfCells = randomInt()</div><div>let cellSize = getCellSize(forItemsInRow: numberOfCells) // cellSize is optional, since numberOfCells can be smaller or equal to zero</div><div><br></div><div>let cellSize = getCellSize(forItemInRow: 4) // cellSize is non optional, since 4 &gt; 0</div><div>----</div><div><br></div><div>Even this:</div><div><br></div><div>----</div><div><div><span style="background-color: rgba(255, 255, 255, 0);">func randomPositiveInt() -&gt; Int { }</span></div><div>postcondition &gt; 0 else { fatalError() }</div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">precondition count &gt; 0 else { return nil }</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">func getCellSize(forItemsInRow count: Int) -&gt; CGSize { }</span></div></div><div><br></div><div>let numberOfCells = randomPositiveInt()</div><div><span style="background-color: rgba(255, 255, 255, 0);">let cellSize = collectionView.getCellSize(forItemsInRow: numberOfCells) // cellSize is non-optional, since numberOfCells is always positive&nbsp;</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">----</span></div></body></html>