3 ms·
...But this isn't a matter of picking the right data structure, like swapping out a stack for a queue. The problem arises for elementary structs of finite size,
by legerdemain 6y ago
...But this isn't a matter of picking the right data structure, like swapping out a stack for a queue. The problem arises for elementary structs of finite size, simple data objects. If the list of operations a type needs to support never changes, of course it's more feasible to create a type that supports those operations.
The actual area to learn about here is designing for extension, and software architecture in general, so you can get better at identifying what kinds of changes are going to be simple and what kind will be expensive, so you can tailor your solution to the range of situations you think you're going to face.
- phkahler 6y agoMy solution to represent shapes allows trivial extension in both way presented in TFA. Adding triangle simply requires some kind of definition in terms of what already exists. Adding a new measure (area/perimeter) means defining that once for what already exists. The fundamental mistake here is building code that reflects human concepts rather than more fundamental mathematical ones. Generalization is not the same as extensibility. Writing general purpose code is harder up front. Extending your code for every new shape leads to complexity problems.