HACKER Q&A
📣 nomy99

Do you visualize code before writing it?


Do you visualize code before writing it?


  👤 desertedisland Accepted Answer ✓
I've often thought that coding - for me - is more visual / graphical than anything else. If you could find a way to quantify + test people's ability to do that, you could throw rubbish coding challenges out the window and, given the state of tech hiring, be an instant millionaire.

Having said that, for me it's impossible to describe. There is a part of my brain that is putting things together (graphically, sort of) but simultaneously thinking dependencies, potential problems, optimisation, etc.. Then there's a part that is doing things based on experience and repetition - to be fair the second and third parts are more based on experience than anything else.


👤 yesenadam
Doodling on paper always helps. The more time spent with pen and paper first before typing starts, the smoother things go, and the less spaghetti to refactor later. Diagramming relationships of parts, program flow, data structures etc. I find everything much easier to think about with a picture of it in front of me. For the crux of an algorithm, I set/update the variables on paper to check it works. I can't imagine trying to do something complex without doing the planning on paper first. Once I think about it enough I find myself quickly writing the procedure/function down on paper. Typing it in becomes the first refactoring.

👤 macando
I visualize code more often when I read it than when I write it.

Aphantasia is the inability to visualize mental images, that is, not being able to picture something in one's mind.

There was a thread here on hn a while ago about this phenomenon and it seems even if one is not able to visualize things they can still be perfectly able programmers and even illustrators.


👤 bckr
I usually just make a todo list, expand that out into comments + pseudocode, and then fill in the details with real code. I guess a list is a kind of visualization.