points by DonHopkins 6 years ago

I visualize and remember code that way. For me, it's hard to forget somewhere I've been, even if I only imagined being there.

Each function is a little building like an office or a shop, which has a sign out front telling what services or products it sells, and contains everything inside you need to solve some kind of problem or produce some kind of product or service (where equipment in the room is like references to other objects and functions and imported libraries).

You're standing behind the front counter, just about to receive a customer though the front entrance door with the parameters you need for one particular instance of that problem.

You go into the back room, solve the problem, then deliver the results out the exit door at the back of the building (or through any of the other earlier emergency exits, if you had to exit prematurely or throw an error and run away).

The front/back flow is a metaphor for the top/bottom flow of control through a function.

https://en.wikipedia.org/wiki/Nassi%E2%80%93Shneiderman_diag...

If you squint you can see the example Nassi-Shneiderman diagram in that article as a map of a building, with its front at the top, and exit at the bottom.

You can have internal hallways and rooms for branches and loops, like a Nassi-Shneiderman diagram. The "Sub to Determine Wiki-Article" room is like the front entrance lobby of a theater where buy your ticket. The "Select Favourite Genre" room is like the stage of The Price is Right, and you get to pick what's behind door #1 (History), #2 (Science), or # (Geography), or else choose Other. They each have one or two rooms behind them with your rewards, and then they all finally exit out to the same back stage loading dock, where you take your wonderful prize (or consolation donkey) home.

klondike_klive 6 years ago

You've given me a very useful framework for remembering functions, thanks!