It is a complete waste if you don't need that functionality. > Is 2 lines not an accepted tradeoff for being able to change the engine, and crucially, to draw numbers from any distribution you want? a 200% increase in code size! Now imagine that throughout the entire code base. >How do you mean, suboptimal? The fully generic version is 2 lines of initialization more than the restricted version. custom classes to model a domain) or generic ones (pairs, lists, maps, etc.), but generic doesn't always imply bloat and complexity. Of course, it depends completely on the context whether to use special-purpose datastructures (e.g. An example of this is Lisp's use of cons cells to represent data: regardless of the contents, and what it's meant to represent, we can always use `car` and `cdr` they're "generic".Ĭompare this to a typical OO approach, like a `Customer` object with a `name` and `dateOfBirth`: we can't access those fields without either writing those particular strings (`name` and `dateOfBirth`) in our code or use some complicated reflection approach to look up the names then use those to look up the data. On the other hand, code can also be "generic" by avoiding decisions, parameters and special-cases. I tend to distinguish between two uses of the word "generic": code can be "generic" by providing hooks/parameters to override every decision, which leads to complexity and bloat, as you mention. I think the reliance of modern programmers on libraries which offer highly generic (and thus almost inevitably sub-optimal) solutions is one of the primary reasons for software boat. Often generic solutions are the best trade-off in the end, but one should not assume that more generic is automatically better. and is much simpler and more straight-forward because of that. The specialized version does not cover non-uniform distributions, nor the use case where you need multiple PRNGs with independent states. ![]() Std::uniform_int_distribution distribution(1,6) Generic version (this is from C++'s standard lib): More importantly generic code is almost inevitably bloated, less efficient, and more complex compared to code which only attempts to solve the actual problem at hand, as opposed to attempting to provide a generic solution for all imagined use cases.Ī simple example would be a PRNG.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |