As devs, we sometimes have to work with new technologies we haven't used before. The pressure is high, and deadlines are near. It can be tempting to just copy code we don't fully understand.
But what if that code is really important, like controlling an airplane's autopilot or keeping medical records safe? Imagine working for NASA and developing systems where people's lives depend on your code. It's very important to be accurate and careful in such big jobs.
If a mistake is made, it could cause big problems, like an airplane going the wrong way or someone's private information getting out. That's why it's we really need to understand the code we are using, and avoid copy pasting code from the internet and hoping for the best.
There's a lot of great code out there, and you should use it, but above all else you should understand what it does.
Let's look at some ways to handle new code better.
1. Trying Out New Features
Imagine creating a feature that shows search results on a webpage. You could use a Spike, which is a way to try different ideas to see what works best.
You can create a new branch in your version control system, where you can try things without worrying about making mistakes. The main goal is to learn and find out what works best. The code you write in this test might be different from what you end up using, but you will learn a lot from it.
The idea of "spiking" a problem is to get more comfortable with the code that you're about to use and learn what it does.
2. Writing Tests First (TDD)
Test-driven development (TDD) might be new to you, but it's a good way to make sure your code works right before it's finished. First, you write tests that describe what your feature should do when it's working right. Then, you write the code that passes these tests.
This method helps you avoid mistakes and make sure everything works as it should, step by step. For example, first, make sure a search button shows up right, then make sure it works right when you click it. The idea is pretty straight forward and simple. However, the learning curve for most developers is steep.
Once you do master writing test, you'll find that by learning how to write the test - you'll also learn what the code does.
3. Paired Programming and Reviewing Code
Working with a friend on code, or pair programming, is a great way to solve problems better. You can learn from each other and catch mistakes that might be missed alone. Also, having team members look over your code can help make sure it's correct.
However, it's probably one of the most abused and misunderstood concepts in programming. Talking to anyone you like for 8 hours on end can be exhausting, now you imagine talking to a co-worker or complete stranger for that long. You'll be ready to find a new job.
If you're doing paired programing right, it can be a great tool in tackling code you haven't ever seen before. Whether or not the person you're coding with is better than you at coding. There will come a time when they spot something you haven't considered.
Just remember, not to pair for 8 hours a day.
5. Making Prototypes
Building a prototype, or a simple version of your idea, can help you test if your idea works before you make the real thing. This lets you try out parts of your solution on their own, making sure each part works right before putting everything together. This is especially helpful when you're trying new things, as it lets you spot problems early.
It can also be used as a tool for your team to see if they are heading in the right direction. I've seen PoC give teams confidence in the problem they are solving, and also see if a solution may not work. In either case, this is another opportunity to gain understanding of the code you are writing.
Learning to work with new technologies can be tough, but using the right methods can make it much easier. Trying new ideas, writing tests first, learning about new tools, working with others, and making prototypes can all help you write better and safer code. These steps take time and effort, but they save you from bigger problems later and help you do a great job. By using these methods often, you'll get better and more confident in handling new tech challenges.