4 ms·
De Morgan's laws are complex-and-not-frequently-used? What are you even programming? I don't want to hire programmers who have to constantly be looking up how
by copsarebastards 11y ago
De Morgan's laws are complex-and-not-frequently-used? What are you even programming?
I don't want to hire programmers who have to constantly be looking up how to program--that's an enormous waste of time. It makes sense to be looking up APIs, because interfaces change and have caveats. But DeMorgan's laws, divide and conquer algorithms, basic data structures, should all be in your brain. These are the building blocks of software and if you don't have them you can't build software.
> Also, in the real world a candidate would probably google De Morgans laws.
So I hand you a function to optimize:
def is_taxed(transaction):
return (not transaction.buyer.is_nonprofit()) and (not transaction.location.is_duty_free())
What about this problem would indicate to the candidate that they should Google "De Morgan's Laws" if they didn't already know it?
- onion2k 11y agoMost 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.
- copsarebastards 11y ago> 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.
- Sir_Substance 11y agoOk, maybe de morgans laws are a bad example for a complex idea, but I'll tell you this: I'd have to look them up to know they are called de morgans laws, as the name is not relevant to their use.
- copsarebastards 11y agoRight, I don't care if people know that they are called DeMorgan's laws, I only care that they understand them.
- deleted 11y ago[deleted]