Last week I had started to answer questions on Quora. It's surprisingly addictive I should say, so I kept answering a couple of questions every day. As my interests include programming and various languages, I get plenty of "How do I learn to program in X?" or "As a beginner, how to choose a project?" It's great people are interested in learning to code, but I feel like most have the wrong motivation or they look at it the wrong way.
For me, starting to code was natural. It wasn't some kind of "I want to learn to code python so I can get a job." It was simple: "I'd like to find out how to make a program. I don't know how they are made. I want to find out."
This is a long story made short. I started with random documents in Word and saving them as .HTML. I thought I'm building websites.
Later on someone showed me CoffeeCup, some flash animation drag&drop creator thing that lets you add links.
I made random things with that.
Then someone else pointed me to an online website maker that would also let you edit HTML. I started copying snippets from the web to make text glow or whatever things I found. Same person also showed me Pascal but we didn't get far beyond if statements.
Later on, somehow, I was introduced to this computer club in my hometown. They were building software in Visual Basic. It was amazing - I could build applications that can actually do things when I click buttons. I built various small programs I found interesting - no guidance on the choice of project, I was just building things. I built two games, sort of playable, using images, timers and keyboard inputs.
Sometime after that I was into building a skateboarding website - a project that kept me busy for years. I went from knowing how to make HTML pages to full-blown PHP websites using a CMS and then rewriting everything without the CMS.
I got involved with the forums of PHP-Fusion, the CMS I used, helping others to the point where they (the maintainer for the Romanian forum) invited me to a trip on the sea side, for free.
Then ended up at a national competition, InfoEducatie, where I've been introduced to object oriented programming and MVC. Got kicked in the butt so hard about the quality of my code that I stepped up my game and won the competition the following year.
I was coding every day. I was going to competitions during high-school, almost every week for a while - I wasn't missing a competition. Sometimes winning, sometimes losing... didn't matter. I was learning a lot from the workshops they organised and other people.
That's how I learned to code. It was never a goal. It was the means to build projects and go to these competitions. When I got to University I learned a lot about the theory behind various things. I learned about Machine Learning and AI. During uni, I went to hackathons all the time. Lots of things you learn from hackathons - about business, about programming, you make friends... It's another story about hackathons and competitions.
Let's get back to the topic now.
How do you learn to code?
You build stuff. What stuff? Anything that's interesting at the time.
Yeah, but what's best to build?
It really doesn't matter. The only thing that matters is that you are passionate about the project - that will automatically make you want to step up your game every time and build the best thing you can.
Good - you're pushing yourself! Keep pushing. Get help. Figure it out. Anything but don't quit. You will get stuck often. Take my word on this: you will feel good when you figure it out.
How to pick a language? What language to pick?
Doesn't really matter either. As a software engineer, you must be able to pick up a new language in a relatively short time, as you code in it. Yes, you will have to refactor, but that's not the point. You will be moving forward and learning at the same time.
Anything I should understand before starting to code?
Some things. Understand the concept of variables. How programs execute line by line. What a function is and how to call a function. If statements. For statements. While statements.
You can learn those as you program but you might need to read some tutorials/guides on them so everything makes sense.
Do understand those things!
How about algorithms and data structures?
You will need them. You can practice them on various websites like https://HackerRank.com. You can learn them from books, intro to CS online courses, tutorials, etc.
It's probably a good idea to follow a intro to CS course. But not instead of building a project, more like in parallel.
Difficulty of projects?
If you pick something you can't even start, after you spent lots of time trying to figure it out, it might be too hard. If you build something that's easy, and you don't get stuck much, it might be too easy. You want something to push yourself at all times, but not something so hard that you can't even begin - you will lose motivation.
You can always pick a very challenging project and make it easier as it goes. You want to build an amazing game with 2D graphics and multiplayer? How about a text-based single player one for the first version? You keep the core ideas, you implement the core logic and you draw the graphics later on, and add the multiplayer later on.
Should I learn language/framework X over language/framework Y?
Learn the one you like more - and get started. Don't procrastinate too much on the decision.
Programmers get all personal about languages. You can start a religious war on a language vs another. It's normal (for programmers) to have opinions based on personal preferences (about languages/frameworks). Pick the one you like and build a project. Then learn the other one.