Hacker Newsnew | past | comments | ask | show | jobs | submit | duc_minh's commentslogin

> 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)


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).


> 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).


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.


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.


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.


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.


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.


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


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.


114 rounds and counting with a max of 87 coins, a combo of 7. Guess I have some anti-Markov behaviours ¯\_(ツ)_/¯


Yeah, if you know it's markov, you can exploit that.


Took me off guard too :D I didn't expect to click on a random link on HN and see an article about my home country


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: