| ▲ | duc_minh a day ago |
| > Sometimes the best optimization is not a clever algorithm. Sometimes it is just changing the shape of the data. This is basically Rob Pike's Rule 5: If you've chosen the right data structures and organized things well, the algorithms will almost always be self-evident.(https://users.ece.utexas.edu/~adnan/pike.html) |
|
| ▲ | jeswin a day ago | parent | next [-] |
| I wouldn't give too much credit to rules like this. Data structures are often created with an approach in mind. You can't design a data structure without knowing how you will use it. If anything it's the other way round, if you're not talking about business domain modeling (where data structures first is a valid approach). |
| |
| ▲ | scott_w 17 hours ago | parent | next [-] | | > If anything it's the other way round, if you're not talking about business domain modeling (where data structures first is a valid approach). And even there, the data models usually come about to make specific business processes easier (or even possible). An Order Summary is structured a specific way to allow both the Fulfilment and Invoicing processes possible, which feed down into Payment and Collections processes (and related artefacts). | |
| ▲ | ssivark 20 hours ago | parent | prev | next [-] | | To elaborate on @jeswin's point above (IDK why it got downvoted)... a data structure is basically like a cache for the processing algorithm. The business logic and algorithm needs will dictate what details can be computed on-the-fly -vs- pre-generated and stored (be it RAM or disk). Eg: if you're going to be searching a lot then it makes sense to augment the database with some kind of "index" for fast lookup. Or if you are repeatedly going to be pllotting some derived quantity then maybe it makes sense to derive that once and store with the struct. It's not enough for a data structure to represent the "fundamental" degrees of freedom needed to model the situation; the algorithmic needs (vis-a-vis the available resources) most definitely matter a lot. | |
| ▲ | sublinear a day ago | parent | prev [-] | | If you don't know enough to design a data structure, requirements are missing and someone talking to the client is dropping the ball big time. | | |
| ▲ | jeswin a day ago | parent [-] | | Where did I say any of that? I'm saying that if you care about performance, data structures should be designed with approach specific tradeoffs in mind. And like I've said above, in typical business apps, it's ok to start with data structures because (a) performance is usually not a problem, (b) staying close to the domain is cleaner. | | |
| ▲ | reverius42 21 hours ago | parent | next [-] | | You said: "You can't design a data structure without knowing how you will use it." But the whole discussion involves knowing how you will use it; the advocacy is for careful consideration of data structures (based on how you will use them) resulting in less pain when designing/choosing algorithms. | | |
| ▲ | jeswin 21 hours ago | parent [-] | | My point is that one doesn't follow the other. To design good data structures, you need to know how it'll get used (the algorithm). > If you've chosen the right data structures and organized things well, the algorithms will almost always be self-evident. This is what I was responding to. |
| |
| ▲ | reverius42 21 hours ago | parent | prev [-] | | See also: "Show me your flowcharts and conceal your tables, and I shall continue to be mystified. Show me your tables, and I won’t usually need your flowcharts; they’ll be obvious." https://en.wikiquote.org/wiki/Fred_Brooks |
|
|
|
|
| ▲ | ZaoLahma 19 hours ago | parent | prev [-] |
| Full agree on this. I (deep, deep in embedded systems) have seen this too often, that code is incredibly complex and impossible to reason around because it needs to reach into some data structure multiple times from different angles to answer what should be rather simple questions about next step to take. Fix that structure, and the code simplifies automagically. |