Transcript from the "Coercion Best Practices" Lesson
[00:00:32] And if its not already a number, make sure it's obvious that you're turning it into a number. If you make your types obvious in your programs, the vast majority of all those weird quirky corner cases that you've heard people moan and complain about go away. They really do go away as long as it is very clear.
[00:00:50] I'm doing something numeric and both of these things are a number, then we really don't have a lot of corner cases to worry about
[00:01:23] And it sounds very wise at the outset, but I am troubled by this statement. And I wanna point out why I'm troubled by it, because it uses terminology that is not particularly well agreed upon across the broader programming communities. So for example, what does he really mean by useful and dangerous?
[00:01:42] If I asked you or you or you what useful and dangerous means, I'm gonna get three to five different answers. I'm gonna get a lot of different answers to precisely what does useful and dangerous mean. And so if we don't have a clear definition for those words, then we can't really make much action out of this wisdom.
[00:02:43] What does dangerous mean and what does better mean? So to answer that question, I wanna give you a very brief alternate definition for those words. If we're gonna use this quote, I'm gonna give you a different alternate definition. First of all, I would say useful is when the reader is focused on what's important.
[00:03:00] So if the reader of your code can see something and they are focused on the thing that they really should be focused on, then I'd call that useful. If the reader is focused on something and they really can't figure out what's gonna happen, I would call that dangerous.
[00:03:16] So we shouldn't have stuff that's hard to figure out. You should avoid things that are hard to figure out. And most importantly, to determine whether something is better or not, I would say that when the reader understands the code better than before, then that code is better. That is the ultimate metric is that is it more understandable, is it more readable, then it's better.
[00:03:37] Now you may disagree with those definitions, but I think at least putting a pin on some definition and saying this is what I mean by useful, this is what I mean by dangerous, and this is what I mean by better. At least we can have a more productive conversation about the decisions we should be making in our code.