![]() |
| ||
| Style question 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: 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: |
| ||
| Re: Style question Lint Filters give warnings that are not always sensible. Using elif instead of all if is faster, since Python has to evaluate all the if, but stops at the first true elif condition. In your case it doesn't make much difference since you have a return statement, which will stop Python from going through the rest of the if conditionals. So 'if' is less to type than 'elif'. |
| ||
| Re: Style question Thanks. My feeling was that the first was more human-readable. Do you agree? |
| ||
| Re: Style question I agree! Since you are just going down the line with the same variable, if/elif makes more sense IMHO. The if/elif ties the conditional together. |
| All times are GMT -4. The time now is 9:41 am. |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC