I've been considering an approach to problem solving and code writing, and it's, to solve in parts until you solve in full. Let me explain.
I'm currently working on a feature for code-migration-helpers and I'm stuck. I think I understand how it should work, but representing it in code seems challenging because there are several moving parts. Basically, I want to add a tool for adding/modifying index files in folders and propagating added/modified index files to parent folders. Seems simple, but when you consider questions like,
- what if the file or symbol is already imported?
- what if it's imported but not exported?
- should we use wildcard * exports, and how should we handle existing wildcard exports? The list goes on...
A way to approach this complexity in code is to solve partially, like divide-and-conquer. To solve this problem, I need 3 things:
- what symbols to export,
- what symbols have been exported, and
- exporting new symbols.
Having separated the concerns, I have 3 placeholder functions:
async function decideSymbolsToExport(filepath: string, opts: Opts): Promise<string[]> {}
async function filterExistingExportedSymbols(symbols: string[], opts: Opts): Promise<string[]> {}
async function exportSymbols(symbols: string[], filepath: string, opts: Opts): Promise<string[]> {}
Now, what it'll eventually be may be a bit more complex than this, but I can pick each part and solve it as if the rest is in place.
I'm pretty sure there's most probably a name for this technique, but let me know what you think, and possible improvements.
You can check out my website ywordk.com where I cross-post these blogs and other non-Engineering-related things. I also have a book there, my projects, etc. Also, check me out on X @ywork if you feel like it.