How does one memorize how to code?

Besides repetition, does anyone know of any special techniques used to memorize how to code? I’m currently taking a PHP course at Learnable.com and I can look at all the code examples, understand what it is doing, and what the instructor is explaining. But my fear is that if I was being tested on it, and was asked to do it all on my own I would fail miserably. Any suggestions from any experienced programmers out there? It seems very daunting at the moment.

Simple solution though keep in mind that simple is not the same as easy. Open up a new file and write the code yourself. Keep repeating until you have it right.

Yeah, that is what it takes isn’t it? I’m a pretty accomplished guitarist and that is synonymous with what I’d tell someone learning to play guitar. Thanks for the reply. I guess I was checking to see if there was some other system that I may have not been aware of.

Hi robgraphix1, welcome to the forums,

Looking at examples and following tutorials is OK. But for me that’s only to get a feel for things - a start.

What really helps me learn is giving myself a “project”, and working through the process (with frequent trips to the documentation) one hurdle at a time, learning new things on a “need to know” basis.

While “there is no need to reinvent the wheel” is true, doing so can be good for the learning experience.

Thanks for the reply! That is a great suggestion. Would you happen to have any " first project" suggestions? Perhaps something you tackled when you first started out? Thanks again!

I agree. Actually creating something that uses what you are learning makes it easier to learn. It turns the process around so that instead of being presented with things that the language can do and trying to memorise them without any context of where you’d use them you instead look at things that you need to do and learn the commands the language provides to do them. This makes it easier to learn what the commands do because you are starting from the need to do something and finding the commands that do it. Also with a decent project you will get lots of practice at the really common things you need to do and so will have the most useful commands memorised so that the parts of the language you don’t know as well and need to look up will also be those parts that you don’t need as much.

I had a few things I wanted to do, but I don’t recall exactly what they were after so many years. I think one was how to save “wildflower data” and show it. I didn’t know database stuff very well so I went with CSV.

If you have a special “passion” for something, or even if not, a good way to think of something is to catch yourself saying something like “I wish there was a way to ____” and then try to figure out how to do it. Who knows, others may be waiting for you to figure it out. Lots complain but few take the initiative.

I can definitely understand where you are coming from. It’s definitely more of a one step at a time approach and then chalk it up as a victory. Then I guess what you learn there can aid you in the next step. Wow programming since 1978! You must have quite a few skills! When did you start to feel confident?

That’s quite a coincidence. A friend of mine who is a PHP programmer just said the same thing to me. I guess it makes sense. Think about something you want to do and then see if you can build it.

Here is a fairly simple javascript tutorial app which shows a list of phones and then additional details for each phone

http://angular.github.io/angular-phonecat/step-12/app/#/phones

Make the same app except for guitars.

The phone database is just a json file. You could expand that use a regular database with access via php code.

That would get you going.

Agreed with the above.

You absolutely should give yourself a project - something YOU are interested in. The best way to engage your brain is to enjoy the subject (and thus, the outcome).
The way I learned PHP to begin with was “I want to have a website that interacts with a database so i can display <X>.” Which forced me to learn mysql interaction, and displaying records from a single page.
And while i was doing that I thought “It would be cool if I could…” which leads off into another train of practice.

There is… VERY little you could say in “It would be cool if I could…” that you cannot do with a combination of PHP, HTML, and JavaScript. (PHP for the server side, HTML as the display, and Javascript as client-side).

Eventually you’ll start coming to the point (What i call Level 2 Programming) where you start thinking to yourself “Is there a better way to do X.” Note that you shouldnt try to get to this level before you can ‘do the basics’ (Level 1) by rote. IE: A level 1 programmer writes:


for($i = 0; $i < count($array); $i++) {
  if($array[$i] == "Some value") { echo "Value $i!"; }
}

Which is purely functional code. It works. Its not the best way of doing it, its not the quickest way of doing it, but it works.
Then you start thinking “That’s ugly. Can I make that better?”.
So… “okay, yes, i can stop the loop when i find the value by exiting.”
Followed eventually (after a lot of time looking at the PHP manual, or by hanging out on forums like these) by “Wait… that’s array_search.”

Thanks a lot! I will be mess around with that tut!

Thanks for the reply. Yeah, I am currently a Level 1 and am looking forward to the moment when I’m confident enough to feel as though I could improve on someone else’s code.

Dont be afraid to go back and look at your OWN code, as well. There have been dozens of times I go back, look at the code i wrote in the past, and think ‘what the **** was i thinking there?’ (This is where Level 3 programming kicks in, the self-destructive point where you scrap the whole thing and start again :P)

I find that often occurs once I start Level 1 with a new language and see something I hadn’t come across before that gives me a whole new way of looking at something in code I wrote in one of the many other languages that I already know quite well.

You memorize the syntax, but you dont memorize how to code, instead you learn through experience and become comfortable with time.