Suppose I have a class with a string instance attribute. Should I initialize this attribute with \"\" value or None? Is either
Either might be fine, but I don't think there is a definite answer.
None is better than comparing with "", since "" might be a valid value,"" is probably better, because its actually a string, and you can call string methods on it. If you went with None, these would lead to exceptions."" can help with that.If you have a loop, say:
def myfunc (self, mystr = ""):
for other in self.strs:
mystr = self.otherfunc (mystr, other)
then a potential future optimizer would know that str is always a string. If you used None, then it might not be a string until the first iteration, which would require loop unrolling to get the same effects. While this isn't a hypothetical (it comes up a lot in my PHP compiler) you should certainly never write your code to take this into account. I just thought it might be interesting :)