Lurker News
I'm around 40 and recently I have been asked to port an API from one language to another. The code I'm porting is average code, not terrible, but plenty of little things to complain about.

I feel like my past self could have handled this task, but I am really struggling. Porting this API will require a deep understanding of the existing API, which, of course, has several layers of abstraction.
I can't seem to hold more than about 2 levels of call stack in my head. There's the entry point function which calls other functions, which call other functions, which call other functions, etc. You know how it is, code calls other code, and logically it forms a tree of calls and return values that often goes several layers deep. I struggle to hold more than about 2 levels of this call stack in my head. By the time I'm down in the weeds I've forgotten what I'm doing, what the purpose of the actual API call is.
I don't know how to break this into small enough chunks that I can understand it or make progress on. Imagine I gave you the code for the sha512 algorithm, and a hash, and asked you to find the pre-image (the input). This is how I feel. Where do I even get started? How do I find even a single chunk of manageable work to break off.
The hard part is, several other developers are making progress on porting this API. Why can't I? What happened?
I don't know if this task is just an especially bad fit for me, or if my mental abilities are declining?

Comments (510) 299 threads

Earlier comments
vaughan#
My biggest pain point with programming is I am constantly rebuilding mental models of software projects.

I think its a problem with the way we write software. I think all code we write should be visualizable at different levels of granularity, and should be able to show data flowing through it inline. We have all these principles about writing good software such as it should be testable, performant, self-documenting...but I would argue the most important thing is that it should be visualizable! And easily debuggable.
---
I would suggest using a visual debugger and an IDE with static call hierarchy features (sometimes called find usages or find all references).
You should think about how you would build it from scratch. Then fit the existing API to your own mental model of how you would build it. Then it will be easier to understand why people did things a certain way. Many times I will see someone's code and wonder why they came up with such a complicated abstraction layer, but then when you build it yourself you see how it comes very naturally. The problem is for most projects you are looking at the end result of someone else's journey of building from scratch and refactoring along the way as needed.

mgkimsal#
> several other developers are making progress on porting this API

You didn't mention tests. How do you know their 'progress' is actually correct or even good?
I'm presuming the 'several other developers' are younger than you, hence your concern about age. Without some measuring stick to know if what they're doing is correct, you can't tell if they're just doing more work or actually doing it correctly.
> How do I find even a single chunk of manageable work to break off.
How is anyone else finding work to break off? Is this a free for all, or are there any planning sessions to identify things? Without that, you might be overwriting or reworking something someone else already did.
You may want to ask for some pairing with someone else who you think is doing this better/faster than you, and just ask to work with them for a couple hours.
Talking through the problems with someone else might help turn a corner with respect to mental models. How are they reasoning about current code? How are they tracing through the paths? Someone else deep in this problem may be able to come up with language or examples that resonate with you in a way that random HN people can't.

okl#
> I can't seem to hold more than about 2 levels of call stack in my head.

If you keep thinking that you can't then you won't.
I recommend you to stop worrying and do the work. In time you will find ways to accomplish your tasks. In any case you can't go buy a new brain so why spend time worrying?
Looking at it differently: Even if a young you had greater mental ability, did young you have the same skills, experience, knowledge etc.?

captainbland1 reply#
Don't think about it holistically. Try to just port the smallest, most independent parts you can one at a time and link them up. The approach I'd take (as a developer with shoddy memory to begin with) would be to find my way to the leaf nodes and start porting them, then work back up the tree. Hopefully that way I shouldn't have to have more than 2 levels in mind at any given time anyway.
mypalmike#
I agree. While some programmers seem to be able to hold massive quantities of complex spaghetti in their heads, many of us are not. As long as each layer is well designed and the layering itself is well designed, 2 levels is about all you should need to consider at any given time when immersed in the code.

Load more comments