3 ms·
There was an "OMG Bad Code!!" scene toward the end of the Silicon Valley series that I caught. Many people ragging on the founder|coder for writting a clean sn
by defrost 4y ago
There was an "OMG Bad Code!!" scene toward the end of the Silicon Valley series that I caught.
Many people ragging on the founder|coder for writting a clean snippet of linear search function when he obviously should have done better and used a binary search (or some other algo) .. ergo "Bad Code!!".
What was missing from that was any context about the volume of expected data per "need to seach this" call etc.
It's entirely possible that every instance was to quickly search an already primed cache of data and that the optimal performance on the target hardware was to minimise branching and linearly rip through a small chunk of data in a load page.
Or, maybe not.
Point being, context and bigger picture plays a part here also.
- asdguinui 4y agoIn fairness to the scene, this was the code in question: https://stackoverflow.com/questions/65753731/why-searching-a-sorted-list-using-brute-forcing-is-funny-to-silicon-valley-show https://stackoverflow.com/questions/65753731/why-searching-a... Hardly clean, I think you'd agree. In any case, you shouldn't use explicit iteration to solve this problem without a good reason. Every language should have both linear and binary search as part of its standard library.
- epgui 4y agoUhhh not sure why you were downvoted to oblivion. I can easily see other people disagreeing with you, and I’m not saying I agree, but what you said was not unreasonable. Vouched.
- Jtsummers 4y agoNew accounts whose first comment includes a link tend to get filtered and marked dead without user interaction, it's part of the automated mod system. They basically get caught up in the spam filter, I vouch for them a lot when (like the one you vouched) they are actually contributing.
- epgui 4y agoAh, thanks for the extra context! I did not know this!
- defrost 4y agoCheers for the detail - I only dimly recall it in passing as I'm not much of a TV series consumer. I agree that you shouldn't especially choose one algorithm over another without reason and I feel comfortable choosing a linear scan of short sections of cached data in pipelined situations where branching overheads are steep. Was the case in the TV episode such a scenario? I have no knowledge of that myself.