A friend of mine just introduced me to the Eclipse IDE, which may or may not end up replacing IDLE for me.
Anyway, one of the features of Eclipse is error warnings as the code is *displayed*, rather than waiting for errors to pop up at runtime.
This code got flagged:
if self.tag == None:
return ""
elif self.tag == "_text": <-----
return "\t"*tablvl + self.value
elif self.tag == "_toplevel":
s = ""
for i in self.children:
s = s + "\n" + i.__str__(0)
return s
the line marked <----- got flagged as "unnecessary else", since the return "" technically prevents the code from getting to 'elif self.tag == "_text":' unless the if falls through.
Stylistically, what is your opinion? Would you write the code like that, or like this:
if self.tag == None:
return ""
if self.tag == "_text": <-----
return "\t"*tablvl + self.value
if self.tag == "_toplevel":
s = ""
for i in self.children:
s = s + "\n" + i.__str__(0)
return s