5 ms·
My favorite examples of overreliance on conditionals: https://cdn.discordapp.com/attachments/285492834444771328/286610945063780352/0b7b209f2d27afce50a56a1749461
by Houshalter 9y ago
My favorite examples of overreliance on conditionals: https://cdn.discordapp.com/attachments/285492834444771328/286610945063780352/0b7b209f2d27afce50a56a1749461de84d85ae235f21e803838d1a9782a5a4af.png https://cdn.discordapp.com/attachments/285492834444771328/28... https://i.redd.it/6fh5xb20ttly.png https://i.redd.it/6fh5xb20ttly.png http://i.imgur.com/GqcvMhp.png http://i.imgur.com/GqcvMhp.png
- Jtsummers 9y agoDear god, I think this would be what would drive coders mad if some Lovecraftian old one were a coder. I have a colleague that writes code like that last one. I know he won't change, but I wish he'd at least use a damned switch statement.
- chickenfries 9y agoThese are great, I need to start a collection like this. Here's something from this codebase, with names and variables altered but for the most part left alone. Note the hardcoded `ajax_max` variable. https://gist.github.com/anonymous/2d06bd45222999647d99df54fb098a51 https://gist.github.com/anonymous/2d06bd45222999647d99df54fb...
- adrianratnapala 9y agoActually the first example looks perfectly reasonable to me. I would have used changes of "if () return" instead of a huge OR, but the result would have been the same. The second example I can't judge. Probalby the variable name is bad, but not extraordinarily so. It's a lookup table, I can't tell if it is a good or bad idea without know what is being looked up.
- chickenfries 9y agoI think in the second one, a simple list of values that correspond to true would be more reasonable than putting this in your source code, if you just need a look up table. The way the comments are structured though, I wonder if each row an option map, (annotated by the comments along the top)
- Houshalter 9y agoThe second example was a 15 line switch statement that they replaced with a lookup because they thought it would be faster.
- Houshalter 9y agoWould could possibly be the advantage of hard coding divisibility checks against every prime number? There's so many problems with this. The simplest thing would be to just make an array of primes and iterate through it. There's also faster algorithms to check for primality.
- adrianratnapala 9y agoThat code is making an array of primes and iterating through it. It's just that the array is stored in instruction memory, and there is no explicit fiddling with indices or pointers. As for more advanced primality testing methods, I guess it depends on where the the fancier algorithms begin to pay off. It would not surprise me if this simple algorithm was the fastest for any input small enough to be stored in a single machine word.