Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Writing code from bottom to top instead of from top to bottom. Usually the interesting stuff happens in the bottom part and the top part is merely prepping data and taking care of edge cases: it's way easier to write it once you know how you're gonna end up using it.




Rule #5 of Rob Pike's rules of programming[0][1]:

"Data dominates. If you've chosen the right data structures and organized things well, the algorithms will almost always be self-evident. Data structures, not algorithms, are central to programming."

[0] https://users.ece.utexas.edu/~adnan/pike.html

[1] https://news.ycombinator.com/item?id=24135189 (HN Discussion from 8/2020)


This is such a good one and I have wondered for years where it came from. Thanks!

Counterpoint, if you're writing business logic - e.g. some math, a HTTP/JSON API, a database, etc - it may be better to start with your domain data and business logic. Write the most clear version of the business logic, then implement the details in their respective layers. That is, the layers may be replaced entirely over time, but your business logic shouldn't change if e.g. the data goes to GRPC instead of HTTP.

I was recently explaining to my non-programmer gf what programming is to me. I said that I first make some bricks and then when I have enough I try to assemble bigger bricks from small ones and then after a while build things from them.

I agree 100%. Bottom up of the way to go if you're doing it without deadlines, requirements or investors with expectations looming over you.


Damn. I would have written the exact opposite.

Moreover, it is counter intuitive, too. The instinct of most juniors is to build foundations first and it took me a long time to learn to do the opposite.

Each layer serves as a customer for the layer above. If you havent figured out what the layer above needs precisely by building it you're probably going to provide the wrong thing to it in the layer underneath if you write it first.

It's also more resilient to requirements mistakes and requirements changes - it's easier to change course on a feature after showing a UI to a stakeholder if you didnt build the lower layers.


I think we have different things in mind here - I believe you're thinking of upper vs lower layers of code and I'm thinking of the code being literally at the top or bottom of a script or function. Thanks for sharing your thoughts anyway!

Design top-down, implement bottom-up?



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

Search: