Skip to Main Content

The Best Ways to Teach Yourself to Code

Yes, you can teach yourself how to code. Here's how to do it.
By Lifehacker Staff
We may earn a commission from links on this page.
Two laptops and a computer on a desk, their screens displaying code
Credit: Nitinai Sangunsri / EyeEm - Getty Images

If you want to learn how to code, taking your first steps can be daunting, but here’s the big secret: There are plenty of free and cheap resources you can use to get all the help you need, learn new techniques, and make the process as fun as possible. Whether you’re an adult looking to transition into the tech industry, a student looking to learn the latest language, or a hobbyist who just wants to understand how software and services work, all you need is a computer and internet access to start your programming journey. Here are some of the best tips and resources to set you off on the right foot.

First, ask yourself why you want to learn to code

Take a few minutes (or longer) to think about the reasons—the real reasons—why you want to learn a programming language, and be honest with yourself. Are you trying to learn the bare minimum to score a promotion? Are you looking to make a big career change? Do you want to create the next great app? Thrill your roommates by programming your various smart devices to do something awesome? Your answer can help determine which programming language(s) you should master, as well as what sort of commitment (in time and money) your goal may need. Some goals might benefit from a formal computer science education, others could do just fine with a short-term coding bootcamp, and some goals might just need interactive tutorials and free online courses. Knowing your reasons will help you choose the best path.

Choose the right programming language

Once you figure out why you want to code, you can more easily pinpoint which programming language you should tackle. While there is no single “best” programming language to learn, some languages are more user-friendly than others. HTML and CSS are considered the easiest entry points into the coding world, but they are only really useful for developing basic websites. For more interactive websites involving payment systems or databases, you’ll need to know languages like Javascript, PHP, SQL, and Python. Mobile app makers use Swift or C to make iOS apps, and Java or Kotlin for Android apps. Video game developers may turn to Unity or even C# to bring their games to life.

If you still can’t decide on your starter programming language, most professionals recommend learning Python, C#, or JavaScript, as they offer the widest utility and career flexibility. To help you make up your mind, check out this great infographic (you’ll need to zoom in) that compares a few popular programming languages.

Above all else, just get started learning something. Once you become comfortable with one programming language, you’ll be able to pick up the next one much faster.

The best online courses to learn how to code

If you want more control over your learning schedule (or don’t want to go at it alone), an online coding course might be a better option than an in-person coding bootcamp. But there are many different online classes that teach the same programming languages, and it can be hard to figure out which ones are worth your time and money.

If you don’t mind practicing solo, check out The Odin Project, a free option that pulls together some of the best open-source content for turning a coding newbie into a programmer.

Want more one-on-one coaching and career prep without doing a full-time bootcamp? Try signing up for the subscription-model certification courses from Udacity or Treehouse, where you have the opportunity to ask a tutor for help instead of suffering your coding mistakes or questions alone. There are also cheap Udemy courses for beginners that even full-time bootcamp and computer science students sign up for to supplement their learning.

But no matter how many courses you take, many beginners still find it hard to apply their relatively basic knowledge. To that end, many recommend the free Practical JavaScript course from Watch and Code, which revolves around a single project that you continually iterate.

Focus on learning computational thinking

Instead of hyper-focusing on a specific programming language, you can also learn to problem-solve in a way that a computer will understand. In other words, improve your skills in concepts like pattern recognition, algorithms, and abstractions. There’s also lingo, like loops, which are bound to pop up in any language you use. The better you understand these principles, the easier it will be to learn the next language (and design better products or projects as a result).

Thanks to the internet, you don’t have to enroll in a four-year college program to learn the fundamentals of computer science; a number of college-level classes are available online for free (or a nominal fee).

I can’t recommend Harvard’s CS50x Introduction to Computer Science enough. You can audit the course for free via edX and earn a certificate by completing all the assignments, or you can go at your own pace and watch all the lectures posted on YouTube. You can build your own DIY college-level computer science program with this selection of fifteen online courses.

The best books to learn how to code

The best way to learn to code may involve you getting up close and personal with a real book that you can follow from beginning to end. In a perfect world, this will give you a more comprehensive introduction to coding than jumping around from topic to topic on a website.

You can probably find an e-book for any language or framework you’re trying to learn on GitHub, but many web developers swear by Jon Duckett’s colorful series on everything from front- to back-end web development.

As a self-taught programmer, you might also benefit from books that offer broader advice on the profession. You’ll improve your thinking and habits, traits you can apply to any language you decide to learn. Steve McConnell’s 900-page Code Complete: A Practical Handbook of Software Construction is considered the definitive guide for best practices, with data-backed advice on everything from project design to debugging code.

A corollary to that behemoth is Clean Code: A Handbook of Agile Software Craftsmanship by “Uncle Bob” Robert Martin. Martin believes code should be efficiently written for easy testing and scalability, making this a must-read for many modern dev teams.

Since programming is really about problem-solving, you’ll appreciate the thought process and “back of the envelope” solutions that Jon Bentley shares in Programming Pearls. Every chapter ends with a number of challenges that are often used in technical job interviews, so make this book part of your job prep.


Some of the best coding books available:


The best interactive tutorials and coding games

Reading lines of code on a screen or in a book can look like gibberish, but when you see an example in action, that abstract concept can make a lot more sense. That’s the beauty of interactive coding tutorials you can find around the web.

For example, FreeCodeCamp not only breaks down coding concepts into small chunks within your web browser, but it also pairs each concept with a relevant exercise that you have to solve before moving on to the next topic. That way, you can’t just skip ahead to the fun stuff; the site really forces you to debug your code as you learn.

Coding games are also a fun way to get your feet wet. If you have an hour to kill, you can give the simple Hour of Code games a try. Additionally, many schools already use the Minecraft: Educational Edition to teach kids programming basics with coding blocks, and even JavaScript.

Want a more complex game development tutorial that you can put on your resume? CodinGame might be more age-appropriate if you don’t feel like punching blocks all day long.

Try a kid’s toy

Who says adults can’t learn from the same STEAM/STEM toys and video games that get kids hooked? After all, these products are designed to teach coding logic and syntax without boring easily-distracted children. If you want to better understand the relationship between hardware and software, then you’d enjoy the Piper Computer Kit 2, which has you building a Raspberry Pi-powered computer. Using this DIY laptop, you can learn to code through its custom Minecraft Story Mode challenges, use the drag-and-drop Blockly language to learn physical computing, or just pick up some basic Python from the pre-installed lessons.

While you probably won’t be able to create your own droid from Star Wars, you can learn to code one with Sphero’s BOLT. Using the companion app, you can control your droid ball using the drag-and-drop coding blocks called Scratch, or level up to JavaScript to program more advanced moves.

Teach your favorite devices (and assistants) new tricks

Do you have a smarthome device like an Amazon Echo? You can put your coding skills to the test by creating customized mini-programs to get more functionality out of your devices’ digital assistants. Amazon’s Alexa may already know many basic voice-command “skills” like reading the latest news headlines, but you can teach her more complicated tasks by coding in Node.js, Java, Python, C#, or Go. (Or, if you want to start with something easier, try the simpler Alexa skill blueprints site.)

It’s possible that your interest in coding is more limited—you might just want to learn enough Python to make your Raspberry Pi do cool projects, for example. If so, you can adopt a DIY approach to learning by checking out the many projects others share on its website.

By recreating existing projects, you’ll learn more about the inner workings of your highly customizable device. You might even find yourself inspired to create new ways to use your mini-computer and delve further into the world of code. (You can even enroll in UC Irvine’s The Raspberry Pi Platform and Python Programming for the Raspberry Pi Platform.

The best videos about learning to code

Sometimes, it’s just easier to watch someone show you how it’s done. You can find all kinds of educational videos about nearly any coding-related topic nowadays: ex-Googlers sharing solutions on coding interviews, YouTubers live-streaming their coding marathons, and even programming veterans showing you how to troubleshoot a specific error in any language you want.

I recommend checking out CS Dojo, TheNetNinja, and Harvard’s CS50 YouTube channel. If you don’t have time to search for a perfect coding video or channel, you can also check out LinkedIn Learning’s vast video library.

Practice with personal projects

No matter how many certificates and coding workshops you complete or how many programming languages you learn, the proof of your coding skills will be in your programming project. While your personal project doesn’t have to be as ambitious as creating the next Google Maps, it should be something you’d want to work on 24/7 to constantly improve and expand its scope.

Start small, but think big. Your project should involve skills you currently have in your toolbox, but you should also have a plan for future features and skills you’d need to turn that vision into reality. Without applying your coding skills in a few projects, you wouldn’t even be considered for professional coding gigs—so start planning and practicing. (Maybe use your coding chops to build an amazing setup for game night.)

Celebrate the small victories

Coding is all in the details, which is why you need to “celebrate small victories,” as one of my programming professors put it. It takes practice to make each element work on its own, as well as constant testing to ensure each line of code will work with all the rest—without errors. If you don’t do seemingly minor things right like closing a HTML tag, you’d be stuck debugging a simple syntax error rather than writing more impressive and complex code.

You need to be patient with yourself; don’t expect to code the next Fortnite after just a few months of study or a few bootcamps. Coding an error-free wedding RSVP form on a website or making a simple-yet-correct number prediction game is already a significant achievement for a beginner. If you get stuck, don’t give up. You should absolutely look for help everywhere you can find it, but also know when to take a break to avoid burnout. And then try, try again.

Google your error messages

This is the best piece of coding advice: If you can’t figure out why your code is broken, you can always look for solutions online. You’re probably not the first person to make your mistake, after all, and someone on the internet has surely already found a solution to your issue. Just copy and paste your error message into Google or your preferred search engine, add a pair of quotation marks around the entire phrase so that you’re not just searching for keywords, and hit Enter.

If you’re still having issues, you can always post your question on developers’ forums like Stack Overflow, Reddit’s programming subreddit, or GitHub. It never hurts to phone a friend—or internet stranger.

Hack someone else’s code

When you reverse-engineer someone else’s code, testing each line to see how it works, you’ll get a better understanding of the big picture. Thanks to the tons of open-source code that’s out there, you can learn just about anything by examining someone else’s flawless work. Just remember to share your code back with the community if inspiration strikes and you improve a part of the program you were fiddling with.

Get a mentor (or teach someone else)

You might be able to find some helpful online mentors through GitHub or meet other veteran developers at a local coding Meetup event or hackathon. Once you gain some experience with programming, you might be able to answer other peoples’ questions or even teach what you’ve learned to newbies—a great test to see what you learned.

Attend a coding Bootcamp

If you want to go pro and become a full-time developer, an intensive and in-person coding bootcamp might help you out, particularly if you learn best in a structured environment with real people to motivate you. However, these types of bootcamps are often the most expensive and time-intensive to attend: You’re looking at around $15,000 or more for just the tuition, plus perhaps living expenses for a few months until you graduate.

Schools like Flatiron School and Grace Hopper do offer scholarships or deferred tuition to make these bootcamps more affordable. Check out Course Report for a comprehensive breakdown of the many online and in-person bootcamps—including detailed reviews from their alums, which can help you decide whether a bootcamp is going to help you achieve your programming goals.