<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I should also mention that this is from a class of error where it becomes more likely with expertise. Thus, the more you do it, and get used to doing it, the more your brain will automate the task. You see this type of thing pretty often with nurses, for example.<div class=""><br class=""></div><div class="">For anyone who would like a better understanding of the science behind designing to prevent errors, I recommend the book <b class="">“Human Error” </b>by<b class=""> James Reason</b>. </div><div class=""><br class=""></div><div class="">Also <b class="">"The Design of Everyday Things" </b>by<b class=""> Don Norman</b> has a pretty good chapter on the basics, and is much more accessible.</div><div class=""><br class=""></div><div class="">I really like that Swift attempts to do this! The use of forcing functions around optionals, for example, is brilliant. It is just that we are applying solutions rather haphazardly (without matching them to the underlying cause of error), and I think we can do better. That we are even considering these things is huge! I am just saying that there is an entire body of scientific research we can use to effectively accomplish this goal (and avoid known pitfalls)… we don’t have to reinvent the wheel.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Jon</div><div class=""><br class=""><div class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Sep 28, 2017, at 5:31 PM, Jonathan Hull via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">+1000<div class=""><br class=""></div><div class="">This is the way it always should have worked… and it is the way my brain still expects it to work. All of the extraneous “Public”s clutter the code and make it much more difficult to read. Without it, the relatively few properties marked Internal or Private stand out.</div><div class=""><br class=""></div><div class="">I know there is the argument about making people think about whether they want to expose each item… but it doesn’t work that way. Once you assign someone a rote task (assigning Public to most of the things), you lose the effect of having them think. From a cognitive psychology lens, when you give the brain a number of decisions to make in a row that are very similar, it will naturally make that task more efficient by automating as much of it as possible (i.e. thinking about it less). Mistakes become much more likely as a result.</div><div class=""><br class=""></div><div class="">Tl;dr: <b class=""> </b>Despite the<b class=""> myth</b>/intention<b class=""> </b>that the current setup makes you<b class=""> think about the problem more,</b> it actually does the<b class=""> opposite</b> and leads to an <b class="">increased risk of error</b>.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Jon</div><div class=""><br class=""></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Sep 28, 2017, at 10:44 AM, James Valaitis via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">When declaring a public class or struct the properties still default to internal.<br class="">```<br class="">public final class NewType {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/// This property defaults to internal.<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var property: Any?<br class="">}<br class="">```<br class=""><br class="">This is not the same for a public extension on the type, where then the access modifier is respected for any function or calculated property within the extension.<br class="">```<br class="">public extension NewType {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/// This function inherits the public modifier.<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func function() {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}<br class="">}<br class="">```<br class=""><br class="">I dislike this inconsistency, and I frequently find that when using my dynamic frameworks my code will not compile, and it will be due to my accidentally writing a public struct but not declaring the properties public.<br class=""><br class="">I believe in the idea that explicitly stating the access modifier leads to more legible code, but in my opinion it can be overdone, and I much prefer to explicitly state my intentions in the modifier on the definition or extension. For example:<br class=""><br class="">```<br class="">public struct Coordinate {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/// Should default to public.<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let latitude: Double<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/// Should default to public.<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let longitude: Double<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/// Should default to public<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>init?(latitude: Double, longitude: Double) {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>guard validate(latitude: latitude, longitude: longitude) else { return nil }<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>…<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}<br class="">}<br class="">internal extension Coordinate {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/// Convenience initialiser to me used internally within the module.<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>init(coordinate: CLLocationCoordinate2D) {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>…<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}<br class="">}<br class="">private extension Coordinate {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/// Private validation of the coordinate.<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func validate(latitude: Double, longitude: Double) -> Bool {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>…<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}<br class="">}<br class="">```<br class=""><br class="">This is legible and intuitive. The current behaviour is not.<br class=""><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></div></blockquote></div><br class=""></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></div></div></body></html>