3 ms·
They should put big intrusive warnings on operator overloads to discourage their use, like "Warning, you are using the complement operator for an operation whic
by sparkie 12y ago
They should put big intrusive warnings on operator overloads to discourage their use, like "Warning, you are using the complement operator for an operation which does not appear to be a complement. Don't do this!" (or alternatively, drop operator overloads from the language, because they are abused more often than not).
I don't really see how `name =~ "somepat"` is any more readable or writable than something like `name.matches("somepat")`, which can be trivially added as an extension of String, and needs no special syntactic support. Something like this:
extension String {
func matches(pattern: String) -> Bool {
return Regex.new(pattern).test(self)
}
}
- jonhohle 12y ago> They should put big intrusive warnings on operator > overloads to discourage their use, like… "Warning, you are using the addition operator to concatenate two Strings. Don't do this!", said no compiler, ever. Only C does the "right thing" with char*s or chars when using '+' ;-) In Swift, operator overloading requires no special syntactic support. Since it's a supported language feature, don't be surprised to see people use it.