If you want to know how exactly I taught myself to code then you may refer to this answer..
What exactly is programming ?
Now lets get to what is the best way to learn programming.
Put in simple words, computer programming is nothing but a way to instruct/ command a computer to perform a set of instruction.
You program a computer to perform a certain task, simple or complicated.
Henceforth you must know a way to communicate effectively with the computer.
In general as with human beings if you have the ability to communicate effectively with other people, you might be
able to convince them to do whatever you want.
Same is the case with computers, the more you are good at communicating with a computer the better it will respond to your request.
Hence to get better at communicating with computers, you need to learn their language.
Hence your first step would be to learn any language which allows you to communicate with the machine.
Step 1: Choosing a programming language.
Python is a great language to get started with as a beginner.
If you want to know how you can get started with Python then I would highly recommend you to go through this answer: Alisha khan's answer to How do I learn Python programming? What are resources?
In here, I’ve listed detailed steps so as to how you can get started with learning Python today!
Step 2: Getting better at solving problems.
Now you have learned a programming language and now can effectively communicate with the computer.
But that does not mean you are a programmer yet.
Knowing a language and its grammar wont make you a poet, in a similar way knowing a programming language
does not make you a programmer.
Always remember, programming is like poetry.
No matter how good you are with it, you can still get better.
You become a programmer by being able to solve a problem. Hence to become a good programmer, solve a ton
of problems.
Programming problems can be as simple as printing our a fibonacci series or as complex as predicting election
results based on tweets.
Step 3: Getting efficient.
In programming there are hundred ways to solve a single problem.
Once you get good at solving problems you now want to get good at finding the finding the best alternative to
solve a problem.
This is where your critical thinking abilities come into picture and you can only get good at it by practice.
No matter how intelligent of a person you are, there is no way getting around it except for practice.
Step 4: Don’t just write code, read it as well.
If you want to be a great poet/writer, you must also read a lot.
Same is the case with programming as well, you will also need to read a lot of code from other developers who are
better than you.
Reading other people’s code will give you a perspective of how they think and how others approach the same
problem.
It will also allow you to compare your code to other’s so that you can find what exactly were you missing.
Thankfully we have Github which allows you to peep into other people’s code.
Take action:
I can’t emphasis this enough, don’t just read this answer.
Instead take action and get started today.
I come across so many aspiring developers who are so busy in gathering information about programming that
they are left with no time to actually code.
If you want, go through this answer again, take notes and start right now.
I’m sure this will give you a head start from other guys who procrastinate.
Hope this helps!