I took martial arts classes in college. They were a blast! Well, until the instructor decided I was his favorite demonstration tool and kept throwing me around the room to teach the class how to arrest falls.
Other than that, it was an exciting few terms of energetic classes and faux sparring with friends. One of the most memorable parts of the courses, though, were the forms we had to memorize.
These were patterns of moves that are used to judge skill and the level of expertise of the participant. Had I continued my studies past two terms of courses, I'm sure I would have learned many different forms as I progressed through the ranks.
Each form is a set pattern and is, at least among the lower levels, easy to memorize and repeat. For quite a while, practicing my forms became a daily routine. I'd repeat the same moves over and over again, turning them from a conscious effort at reproducing the pattern into subconscious muscle memory.
Repetition is the key to memorizing forms. It's the key to memorizing most anything, really.
Several developers have started cultivating a practice of completing daily or weekly code katas. These are specific challenges meant to test some of the more rudimentary skills developers need to hone to be good at their jobs.
This isn't to say that specific code katas are simple. Many are difficult and very challenging, but every one of them exercises the parts of our brains that solve coding problems on a daily basis. Practicing code katas regularly has the same effect on a developer as practicing forms does on a martial artist.
Converting something you need to think about into muscle memory.
Practice Makes Perfect
Whenever I see a coding interview, it usually involves a developer struggling to remember the correct boilerplate to bootstrap a project. Or searching for the correct argument order for a method in the language's standard library. Or re-deriving a common algorithm. Or ... the list goes on.
But practicing these skills helps to perfect them. It gives you the ability to, from memory, bootstrap a method or an algorithm or design an interface. You've done this before, it's easier to do it again. It's easier still because you don't have to think, you can just do.
Practicing also helps you to learn and improve. Developers don't often have time available to refactor production code. But there's nothing that says you can't spend a few minutes each day practicing and rewriting a small component just for the sake of learning. You might even stumble upon an extra optimization that will make a difference in production.
Or you might just learn a new pattern that will save time and energy the next time you build a similar system.