3 ms·
"The point being: strings and booleans are an overlapped type space." That's the problem. Because they overlap for comparisons, you can't tell an empty string
by wvenable 18y ago
"The point being: strings and booleans are an overlapped type space."
That's the problem. Because they overlap for comparisons, you can't tell an empty string apart from boolean false. It would be safer if it wasn't that way.
But the function returning false is perfectly valid. It's not any different from returning null or some other value because it is distinct from a string.
In PHP, like your Perl example, you could easily write "if (is_bool($str)) {...}" if you wanted to. It's not really any different. The problem is that you don't get an error if you go ahead and treat that boolean as an empty string.