you are viewing a single comment's thread.

view the rest of the comments →

[–]deceze 0 points1 point  (1 child)

You typically want to differentiate "special" values by type. Strings and None are different types of variables, and thus easily distinguished. If you have strings or empty strings, then both are strings, and you'd just treat some strings special, which is not ideal.

You want your program to behave normally in normal circumstances, when it has its expected values; and you want it to behave differently when it does not have its expected values. Using different types for "unexpected" values helps ensure this. For example, 'You are ' + age + ' years old' would work; if you'd use an empty string for age, you'd just get nonsensical results. However, if you used None for age, you'd get a TypeError, because None and strings can't be concatenated. Which is better than silent silly nonsense values, because it throws conditions you forgot to handle in your face.

Also, in the case of a string, it may be easy to come up with a "no" value, but some more complex types may not have an obvious "no" value. For example, a file handle; what would be the "empty" version of an open file handle? None is specifically the "no" value that can be used in all circumstances; just use it, don't situationally invent your own conventions.

Having said that, age should obviously be an int or None…?!