Ask HN: How do you write efficient and elegant systems / APIs?
I have seen very elegant and efficient open source repositories.
Recently I had a few breakthroughs, where instead of searching for an answer from the bottom up, I visualized the solution from the top down. I imagined how I would access the API as another engineer and that helped a lot.
How does one improve their skill at making / writing a more elegant and efficient system or architecture?
7 comments
[ 3.4 ms ] story [ 26.5 ms ] threadI always design from the outside in. How do I imagine this API and flow to work, and then how do I structure data and storage. Think of the developer experience before you think of your experience as the implementor of the API.
The most serious problem I run into is keeping the documentation synchronized with the project. For everything non-trivial it seems I always get to a point where the project is so far from the docs that it's not worth going back to update. Do you discard the documentation when you've built the thing?
The problem is that there is now another variable you would need to keep track of: your UML diagrams / documents.
I guess creativity comes into play. For example if I am designing a video editing API. I could think bottom up and start from frames/buffers maybe. I might reason that I require a:
- Renderer - Singleton that is an editor which holds our sequences - Interfaces that can be exchanged for different types of editors - etc.
However the other approach is top down. Imagine how the ideal api looks like and go from there:
editor.addSequence(sequence) editor.process(item: [ .transaction(action: editAction), .transaction(action: saveAction), .transaction(action: finishAction) ]
^ so for example I might start from there and build the system from that point of view.
Anyways would appreciate more of a discussion here.
When it comes to writing code for the user Kenneth Reitz is the master in my eyes.
https://github.com/requests/requests