4 ms·
Unity's C# has always felt like C#'s mentally challenged cousin. C-not-so-sharp. The custom == convinced me that allowing operator overloading on built-in opera
by raincole 7mo ago
Unity's C# has always felt like C#'s mentally challenged cousin. C-not-so-sharp. The custom == convinced me that allowing operator overloading on built-in operators is one big mistake.
- orphea 7mo agoMany tools can be misused. Object.Member can throw a NRE, is it a big mistake to have the dot operator?
- raincole 7mo agoIt's such a weird question. Yes, "dot operator can throw a NRE" is of course a big mistake. A billion-dollar mistake, you can even say.
- orphea 7mo agoNo, I'm not asking if "dot operator can throw a NRE" is a mistake; I'm asking if the dot operator, the ability to access members at all, is a mistake.
- WorldMaker 7mo agoOne take on it is that yes, the single dot operator was an ancient mistake which is why so many programming language features are about making it smarter. Properties as mentioned in this article are an ancient way to fake the dot operator into a "field" but actually make method calls. Modern C# also picked up the question dot operator (?.) for safer null traversal and the exclamation dot operator (!. aka the "damnit operator" or "I think I know what I'm doing operator") for even less safe null traversal.
- kbolino 7mo agoFor those wondering, Unity overloaded the == operator in two specific situations, such that obj == null will return true even though obj is not actually null. More details on this archived blogpost: https://web.archive.org/web/20140519040926/https://blogs.unity3d.com/2014/05/16/custom-operator-should-we-keep-it/ https://web.archive.org/web/20140519040926/https://blogs.uni...