How to learn to code: Our beginner's guide to coding & programming

A laptop being used to write code - GettyImages-1221204650
A laptop being used to write code. (Image credit: Getty)

To survive in the modern world you need certain life skills: Skills like knowing how to turn off motion smoothing on your parents’ TV, or how to perform the latest TikTok dance. But perhaps more than anything else, it is knowing how to code that will prove the most life changing.

If you can master the most modern tools of the coding trade, then you can unlock new job opportunities, a higher income, and spend less time on menial admin tasks that code can do for you. But how do you get started with coding? What are the first steps? Read on to find out.

But first, be sure to check out the Live Science guide on coding vs programming if you're not sure what coding actually is yet. When you're all set up and ready to code, Live Science also has a best laptops for coding guide.  

What language should I learn?

(Image credit: Getty)

If you’re not sure where to begin, JavaScript is a great starting point. According to Stack Overflow’s 2022 developer survey, JavaScript is the most popular programming language in use today, and it’ll give you a solid grounding in the fundamentals of object-oriented programming.

JavaScript is extremely flexible, having transcended its origins as a scripting language to display dynamic content on websites to become a more general purpose language. For example, you can even use it to interact with hardware and run backend systems using a ‘runtime’ called Node.

Ultimately, choosing which language to learn depends on what you want to do. For example, if you want to build iPhone apps, then a great place to start might be with Swift. This high-level programming language lets you generate basic apps with standard features like menus, and buttons, in just a few lines of code.

If you want to jump in at the deep end and build complex software, C# is the place to go (or Rust, if you want to learn a cutting-edge language). But if you just want to go with something simple, the best place to start is with Python, which is both easy to pick up and pretty powerful. Python is incredibly useful for countless small computing tasks that might otherwise take you hours in a Microsoft Excel spreadsheet.

What platform should I write code on?

Man at wooden desk with tablet, laptop and smartphone (Image credit: JKstock via Shutterstock)

If you want an absolutely fool-proof way to start, pick up a Raspberry Pi. It’s a tiny computer about the size of your palm, but fully functional, and can be used either with a monitor and keyboard/mouse plugged in, or it can run “headless” on your home network, acting as a local web server.

This means that you can run your code on a completely separate computer and, if anything goes wrong, it’s easy to wipe clean and start again — no need to screw with your real, work-critical operating system while experimenting with code.

Another alternative, particularly if you want to develop web apps or write Python scripts, could be to lease a computer in the cloud using Amazon EC2. It’s fiddly to set up, but will grant you access to a remote Linux box on which you can do, well, whatever you like, for a small fee every month.

If you're introducing a child to the world of coding, there are plenty of coding toys available that will teach kids the basics of conditional logic and other major concepts, all without making it seem like hard work.

What apps should I write code in?

(Image credit: Apple)

Every language has a slightly different development environment. Some languages have fully-featured development suites. For example, Apple has Xcode, which is a fully-featured Mac app for writing iPhone, iPad and Mac apps.

But there are also more general purpose apps available. The most popular integrated development environment at the moment is Microsoft’s Visual Studio Code, or VS Code, according to Stack Overflow’s survey. Visual Studio Code works with a number of different languages to highlight the syntax as you write, making it much easier to make sure your variables, strings and classes are all in order.

Finally, if you’re really hardcore and want to feel like you’re in The Matrix, you could always write directly in your operating system’s terminal, using an app like Nano or Emacs. But this probably isn’t the best place to start for absolute beginners.

Where can I learn online?

(Image credit: Codecademy)

There are plenty of places you can learn to code online, often for free. Sites like Udemy and Code Academy will teach you the basics in no-time, splitting the learning up into different courses and lessons, so that you can learn at your own pace in a safe environment.

If you’re feeling more ambitious, sometimes the best way to learn is by doing — and messing around with someone else’s code. The way I learned wasn’t through any formal training, but by taking code written by other people and modifying it to suit my own purposes.

We've put together a guide to the sites that we think offer the best online coding courses out there to help you choose.

How can I get support?

Man pointing at a laptop screen showing code - GettyImages-1288272415

(Image credit: Getty)

The secret that every coder will tell you is that the trick to writing code isn’t storing everything you need to know in your head all at once, it’s knowing where to look to see how everyone else did it before you.

The most powerful tool in the programmer’s arsenal is Google, because when an error message pops up, the chances are that you’re not the first person to see it, and someone will have figured it out and posted the solution on StackOverflow.

StackOverflow is a forum website that works a bit like Reddit. Queries are posted, and the many thousands of helpful coders who hang out there can offer assistance. Just make sure that you thoroughly search to see if your problem has already been solved on an earlier thread before posting!

GitHub is another platform where you can find help when coding. Writing code isn’t like writing a novel, it’s more like a collage, where you can bring in code that someone else has written to solve a particular problem.

For example, if you’re writing a Twitter app using PHP, there’s no need to start from scratch when interacting with the Twitter application programming interface (API), because TwitterOAuth already exists, and takes care of most of the hard work for you. Or, want to control your LED lights? Then you can simply use WLED to communicate with the guts of the electronics, and instead focus your code on designing intricate patterns.

And finally, one other potential major source of future help could be in the form of ChatGPT, the AI-bot that has captured headlines since it launched on Nov. 30, 2022. ChatGPT doesn’t just speak great English, it can code too, so you can easily ask it to write code for you, explain why a piece of code works the way it does or debut something you’ve written.

Will ChatGPT make learning to code redundant?

Artist's rendering of a sentient artificial intelligence robot. (Image credit: Getty)

It might feel like an unusual time to want to learn to code, given we’re witnessing the generative AI revolution in real time. Tools like ChatGPT and GitHub CoPilot — another AI tool — are astonishingly capable and can write code for us, to do exactly what we need, with little more than a brief text prompt. So, is AI going to make learning to code pointless?

No, but it's going to change how we code. Though it's still early days, in the future, AI tools like ChatGPT are going to become for coders what calculators are to accountants and mathematicians: Useful tools for solving particular problems, but just as a calculator can’t tell you whether certain purchases could reasonably qualify as expenses, an AI assistant can’t make sure your software is doing exactly what you need it to do.

It’s still important to know how to code — just as a mathematician needs to know how long division works, even if they don’t need to do it themselves every time.

How can I stay motivated?

(Image credit: Shutterstock)

Making your code work isn’t always easy. In good times, writing code is like solving dozens of little logic puzzles, and can give you the same rush of endorphins as when you complete a tricky crossword or Sudoku. But in the bad times, any children nearby are going to learn a few new swear words, as you curse your computer for not compiling the code you have written, or not doing the thing that you want it to do.

Getting past this comes easier to some, as we covered when we looked at why some people are more motivated than others, but we've put some general tips below to help you keep your drive up.

How can you stop yourself from rage quitting? One way is to make sure that you’re not just trying to learn for learning’s sake, but to find a real world problem that you want to use code to solve. Thinking to yourself “Wouldn’t it be cool if I could take this data from one source, and put it into another?” will lead you down the rabbit hole of learning about how to interact with databases and APIs, or wondering if you can make your smart lights flash when you receive an email will teach you about interacting with hardware, and so on.

And if you solve enough little "problems" like this, the knowledge will slowly add up. 

How long will it take to learn to code?

If you learn by doing, and put time into it, you’ll build up your basic skills in a matter of weeks and months. But you’ll never “finish” learning how to code. Platforms and programming languages are constantly evolving. 

Sometimes, transformative new technologies will shake up everything we thought we knew — like the birth of AI — so it’s important to keep your skills sharp and continue learning. But the good news is, that’s the fun part! 

And who knows, maybe you'll eventually get good enough to hack time like Hackerman. That's why we're all here, after all, right?

Freelance contributor

James O’Malley is a freelance technology writer and data wrangler. He was previously editor of Gizmodo UK, and over the years has written for everywhere from Wired, Engineering & Technology, TechRadar, Which? Computing, and PC Pro. He has a Masters Degree in International Relations and takes every opportunity to flex his coding muscles.