4 ms·
Don't forget that in many cases, you can replace a conditional with polymorphism. http://c2.com/cgi/wiki?ReplaceConditionalWithPolymorphism http://c2.com/cgi/wi
by rcfox 14y ago
Don't forget that in many cases, you can replace a conditional with polymorphism. http://c2.com/cgi/wiki?ReplaceConditionalWithPolymorphism http://c2.com/cgi/wiki?ReplaceConditionalWithPolymorphism
- tedmiston 14y agoThis is a better suggestion than most of the article. Especially alongside a classic guideline like: "code to interfaces, not classes".
- technomancy 14y agoOr pattern matching, if you're lucky.
- huhtenberg 14y agoYou certainly can, but it doesn't mean that you should. Case in point - Linux networking code, and more specifically sockets handling part. Mr. Kuznetsov did an excellent job abstracting a lot of things behind interfaces (= blocks of function pointers), but at the same time this made it much much harder to follow the code. It's basically impossible to trace the code by hand without a pen and paper. (edit) To elaborate on the context - reading and tracing the code straight off the source files is a necessity of kernel development, routinely required for both debugging and writing new code.
- rcfox 14y agoSpend this afternoon figuring out GLOBAL and setting up to work with your editor. http://www.gnu.org/software/global/ http://www.gnu.org/software/global/
- huhtenberg 14y agoHow would this help to understand what sk->ops[SK_READ]->foo[index](bar) exactly calls?
- rcfox 14y agoIt lets you quickly jump to the definitions of the variables, their types, and their uses. (And then back to where you were.) It's not going to do all of the work for you, but it'll reduce some of the cognitive load.
- huhtenberg 14y agoThis is the same as ctags then, and it's completely irrelevant to the issue with over-abstracting things in the code.
- deleted 14y ago[deleted]