Dan, +1, that is an excellent writeup of why implicit self is so dangerous. It's exactly because it's sneaky and hard to find. Similar to bad access errors (which, for a wealth of reasons, is impossible to "fix", but implicit self errors ARE possible to fix.) <br><br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 16, 2015, 8:19 AM Dan Loewenherz via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> > On Dec 15, 2015, at 8:10 PM, Kenny Leung via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>
> > I think the mandatory self problem is analogous to never wanting to use x!, as! or try!. If you restrict yourself to always using self.whatever, it is not unusual to someone else, and if they leave off the compiler flag or pragma that enforces this, the code will still compile.<br>
<br>
The big difference is that “!” is instantly recognizable as a code<br>
smell (because there’s an operator which makes you feel bad for using<br>
it) and implicit usage of “self” is not at all, (because, well, it’s<br>
implicit). If you want to eliminate issues of force-unwrapping in your<br>
codebase—even discounting any compiler flags—you can simply search for<br>
the exclamation mark or use a simple regex and replace. There’s no<br>
similar easy way to address implied self.<br>
<br>
Indeed, both the ability to force unwrap and use of implied self can<br>
lead to bugs, but they’re of a different variety. By force unwrapping,<br>
you know that you’re opening up the possibility of a nil reference.<br>
The bugs stemming from implied self are much more sneaky, bizarre, and<br>
hard to track down (again, there is nothing that can give it away,<br>
such as an operator).<br>
<br>
Perhaps most importantly, any developer can make a mistake, and<br>
despite their tendencies towards explicit self, can forget to use if<br>
it’s a situation where its presence would prevent a bug. At least with<br>
“?” and “!”, you’re forced to make a decision (and one of those<br>
decisions makes you feel somewhat guilty…).<br>
<br>
Dan<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>