5 ms·
Anyone who does something like this in production code ... shouldn't be writing production code...
by jjuhl 9y ago
Anyone who does something like this in production code ... shouldn't be writing production code...
- TheRealPomax 9y agoThe problem is that production code never looks like the toy problem you can reduce it to. Someone could write the exact same thing but make it look reasonable, or even "a sweet hack", using an object property getter instead of a function to move something along in a finite state machine: if (state.step == DFA.INITIALIZED && state.step == DFA.RUNNING) { ... }
- earenndil 9y agoIn this case they should use bitfields and bitflags.
- TheRealPomax 9y agoOf course you should. No "look at this cool hack" exists that doesn't have a safer, easier to trace equivalent. Doesn't mean you won't find those hacks in a million code bases used in production, though, and a professional knowledge of "yeah.. okay that's possible, but come on" isn't a bad thing to have.
- jerf 9y agoI've seen something similar to the "junction" example someone mentioned in Perl 6 used, where a function that (with some justification) would allow multiple passwords for a given user to be valid set up a value that would compare equal to multiple things, then check in a single == with the password whether it was valid. I eventually nuked it and replaced it with the obvious for loop, which given as I also got to nuke the implementation of the class in question, meant a significant net reduction in line count, one less file in the repo, and one less wart in the code for new developers to stumble over.