Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25729
| Date | 2012-07-21 11:13 +0300 |
|---|---|
| From | Jan Riechers <janpeterr@freenet.de> |
| Subject | Re: Basic question about speed/coding style/memory |
| References | <500A5B47.1060805@freenet.de> <500A6215.8070703@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2368.1342858531.4697.python-list@python.org> (permalink) |
On 21.07.2012 11:02, Andrew Berg wrote: > On 7/21/2012 2:33 AM, Jan Riechers wrote: >> Block >> ... >> versus this block: >> ... >> Now, very briefly, what is the better way to proceed in terms of >> execution speed, readability, coding style? > Using if/else is the most readable in the general sense. Using return > (or break or continue as applicable) in this manner would indicate (at > least to me) that it's an exceptional or otherwise special case and that > the function can't do what it's supposed to. In that case, I would try > to catch an exception rather than use if/else whenever possible. I > highly doubt there is a significant performance difference between them. > Hello Andrew, Your answer is right, in other circumstances I also would stick to try/except, break-statements in loops and so forth. But the question was a bit more elementary. Cause, as I understand the interpreter chooses either the "else" (1st block) or just proceeds with following code outside the if. So if there is some overhead in some fashion in case we don't offer the else, assuming the interpreter has to exit the evaluation of the "if"-statement clause and return to a "normal parsing code"-state outside the if statement itself. I hope this explanation makes more sense in what I want to ask ;) Jan
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Basic question about speed/coding style/memory Jan Riechers <janpeterr@freenet.de> - 2012-07-21 11:13 +0300
csiph-web