Most developers would be able to work out that the answer to the test is "return not (X or Y)" (unless Python has a nor operator.. I don't know because I rarely use it) without even realising they're using De Morgan's laws, but...
1. If the app is anything bigger than a trivial case there will be bigger things to optimize. Individual code optimizations give you so little in return they're rarely worthwhile.
2. Unless you're doing it millions of times a second you won't actually see the time saving. If you are then you're probably better off generating is_taxed when the transaction object is generated (eg generating and caching the result).
3. If you're still at the point where this change will actually make a difference you probably should be using something that isn't Python.
I wonder if something like Nuitka would be able to optimize it automagically.
> Most developers would be able to work out that the answer to the test is "return not (X or Y)" (unless Python has a nor operator.. I don't know because I rarely use it) without even realising they're using De Morgan's laws, but...
> 1. If the app is anything bigger than a trivial case there will be bigger things to optimize. Individual code optimizations give you so little in return they're rarely worthwhile.
> 2. Unless you're doing it millions of times a second you won't actually see the time saving. If you are then you're probably better off generating is_taxed when the transaction object is generated (eg generating and caching the result).
> 3. If you're still at the point where this change will actually make a difference you probably should be using something that isn't Python.
Yes, and that would be a great answer to my question.
1. If the app is anything bigger than a trivial case there will be bigger things to optimize. Individual code optimizations give you so little in return they're rarely worthwhile.
2. Unless you're doing it millions of times a second you won't actually see the time saving. If you are then you're probably better off generating is_taxed when the transaction object is generated (eg generating and caching the result).
3. If you're still at the point where this change will actually make a difference you probably should be using something that isn't Python.
I wonder if something like Nuitka would be able to optimize it automagically.