There has been a lot of research into this topic in the recent years. My understanding is influenced by the following :
1. The Talent Code by Daniel Coyle.
2. Mastery by Robert Greene.
3. The Mundanity of Excellence.
4. Why Skills trump Passion by Cal Newport.
The best thing for you to do would be to read these for yourself.
CHOOSE THE CHALLENGE : This is something really important. You need to choose a challenging problem you want solve or a skill you want to master, which lies just outside your comfort zone. If it is easy, you'll feel bored. If it is too difficult, you'll feel overwhelmed. Choose something which lies just outside your comfort zone. This leads to what is usually called as the flow experience.
THE PROCESS : To simply put it, mastering a skill is a process with approximately the following steps.
1. Watch someone perform it and visualize yourself doing it.
2. Break the skill into its fundamental building blocks(fbb).
3. Choose one of the small fbb's and try to perform it.
4. At this point, you will not be able to get it right. So, slow down the performance drastically . Go step by step, making each step perfect.
5. Then, make it faster again. Play around with the pace of performance till you are fluent.
6. Repeat the performance everyday.
THE MOTIVATION : As you can see, the process is painful. You need to understand how to replenish the motivation fuel. Talent Code gives a good approach. But I prefer the one given in "The Mundanity of Excellence". Basically, motivation comes from three things : Fun, Reward and Challenge. Everyday you must try to experience these things to remain motivated. Have fun at the workplace. Attack a small challenge which lies just outside your comfort zone everyday. Achieve small targets everyday and reward yourself for doing so.
THE ATTITUDE : You need to get the attitude of a craftsman. The goal is to achieve mastery over your craft. So, when choosing jobs, prefer areas where you can achieve mastery instead of fame or money. Cal Newport explains this really well.
THE TOOLKIT - BECOMING A CRAFTSMAN : This is something out of my experience. So, how exactly can you be a good craftsman ? It's all about your tools. Imagine an empty toolkit in your hand. Now, all you got to do is fill it up with all sorts of tricks of the trade. If you can master tools that are valuable and rare, you will stand out from your peers. Enjoy collecting different tools and mastring how to use them. While learning programming, just imagine this toolkit. Everyday learn some new trick or technique and put it into your toolkit.After a few years , you will have a big toolkit and you will have the capacity to solve the big problems in your field of expertise.