In untyped languages (Python, Javascript specifically) find myself making a lot of bugs / wasting a lot of time because I forget what's in the objects I'm passing around. For example, I forget things like "is this property a string or an array of strings" (...the time I've spent debugging because I thought I was indexing into an array when I was actually indexing a string...)?
I try to document argument/return types, but there are several problems with this (at least, how I'm currently doing it):
- when I'm developing a whole new feature it's hard to document and keep updating the docs as I go
- when I'm importing lots of functions from other places it's easy to lose track of info elsewhere
- I don't know how to document complex nested structure clearly — i.e. when a complicated object with lots of properties has an object property with a bunch of properties of its own
What's the best process / documentation method to keep track of these kinds of things and reduce my cognitive effort? An ideal solution would strike a balance with being able to prototype/develop quickly (not over-optimizing). Good open-source code examples would be especially welcome!