Learning to code can sometimes be extremely overwhelming due to the sheer number of resources out there, maybe you googled "how to learn to code" or "how to learn programming" or "how to code" or even something as simple as "how to create a blog/website" and you got bombarded with dozens of websites with courses on how to learn to code or maybe your friend recommended you a beginner programming book with 900 pages and you're like this is just for beginners? Then you get confused on which route to take, read the book, or choose one of those courses you found online? So, before you make the decision, there are a few factors you should put into consideration. These are:
UPDATE: I've also made a video if you prefer watching rather than reading here
Which form of learning do you prefer?
Are you the classical type of person that prefers reading manuals before you start using something or are you the type that dirty your hands from the get-go and just figure it out as you go? If you prefer starting with a manual then you should probably consider choosing the book. Whereas if you prefer with getting your hands dirty from the very beginning, then you'd probably be more comfortable with the online course.
Are you learning for the long term or the short term?
Are you learning to code to change your career and find a career in the tech industry or are you just learning to build something you have an idea on? If you're trying to change your career, then I suggest you read a book(first) because you'll a more solid foundation of what you're about to get into. But if you're just planning to build something maybe for fun or just a hobby then you can just take a course on the particular language you'll be using to build it.
Consider the language barrier
I think this is highly underrated and overlooked. Most resources about programming are in English and not everybody is coming from an English background, some are just starting to learn the language and may not find many resources in their native language. This can be challenging to some people especially when it comes to video courses because they find it hard to follow the instructor. Here I suggest you read a book because you'll find it better to understand and you can read at your own pace and you can even find a translated version in your native language. But if you still want to go with the video course then you should, it can even help you improve your language skills.
What if you combine both?
I think this is the most efficient way especially if you're learning for the long term. Reading the books is great and learning from the courses is also great, then why not combine it to form great++(hey, just saying....). Of course, each of them has its pro and cons which is why I suggest using both. Let's look at some of the pros and cons.
Pros of Books
Books are Evergreen
Books rarely get outdated and you can always come back to them for future references. This is because books focus on the core concepts of the particular they're covering rather than the next cool framework. I'm currently reading Programming for Dummies, the book was first published in 1999 but the concepts it covers are still relevant today because it focuses on the foundation of the topic.
Books are great for offline reading
There are times when you'll be in a place stuck with no internet connection and you want to do something to make that time worthwhile. This is where you can use the power of books.
Books are great sharing resources for sharing
You might have a buddy that you're discussing a concept with, you might come across a difficult topic that you're finding hard to explain to them but when you point them to a book, they can get more information and maybe even understand more. In another case maybe you want to introduce a friend to programming, introducing them to a course may not necessarily pique their interest but when you give them a book, they might want to start with a little and if they seem interested they might get into it.
Cons of Books
Weight and size
If you usually buy physical books and keep them or move around with them, then this will be a potential disadvantage for you, especially if you have a lot of them since they tend to consume quite a bit of space, and carrying them around would be a hassle. Of course, there's no problem if you're only dealing with e-books, but you should put this into consideration when buying a physical book.
Some books depreciate quickly:
Books are non-interactive:
When you're reading a book you're just absorbing the information inside the book. This is good when you're reading something that is purely theoretical but in cases like programming, it is not, when learning programming you need to dirty your hands and practice, you need to write the code and execute it to make sure you understood what you're learning and you can't get that sort of interactivity when reading a book.
Pros of Courses
Unlike books, courses are very practical and interactive, you follow along and build projects along with the instructor or you're being provided with a UI where you can write your code and see whether you're right or wrong such as the case of CodeCademy and FreeCodeCamp.
Courses are constantly being upgraded by the instructor due to the constant evolution of technologies and so there's a low chance of missing out or getting old and outdated information.
Even though some of the best courses you'll find are usually behind a paywall, there are also high-quality courses that are very low cost and in some cases even free. A lot of instructors make their courses available free on youtube or low-cost platforms like Udemy, Coursera, and Skillshare.
Wide Variety of Choice
There are thousands of courses you can choose from today, and more are being published every single day so there's never a shortage of courses to choose from when learning to code.
Cons of Courses
No Quality Assurance
Unlike books that you can check for reviews on amazon or get recommendations from someone you trust, there's no way to get that in courses, especially when it comes from platforms where there are no review features and you don't know how good of an explanation the instructor gives.
Sometimes difficult to follow
Courses can sometimes be difficult to follow especially if there's a language barrier, this can be that the instructor is not a native speaker and is having difficulty explaining the concepts or you have difficulty understanding the information he's trying to relay.
Getting Stuck in a Tutorial Purgatory
Most courses are video-based so they can be considered as tutorials, in that case, you're just following the instructor in building the project, but what if you're trying to build a different project? That's where things can get nasty. You've built a project along with the instructor but you don't know how to build your project. I suggest after every project you build along with the instructor, you try to break it down and understand how he did it and why he did it.
These are just some of the pros and cons of both books and courses, which is why I suggest you should use both when learning programming. I suggest you start with a book(programming for Dummies) because it lays out the foundation for you, and then get a course when starting with a specific programming language, that way you know the concept behind a particular topic when you come across it. The bottom line is there's no right or wrong way to learn to code and if you feel you're not comfortable with a particular way, then try the other until you find what's right for you.