• Why Coding Your Own Makes You a Better Developer
  • Originally by Danny Moerkerke
  • The Nuggets translation Project
  • Permanent link to this article: github.com/xitu/gold-m…
  • Translator: quzhen12
  • Proofread by: Jiapengwen,Baddyo

Why does coding yourself make you a better developer

To truly understand the wheel, you need to reinvent it

The other day, I was interviewing for a senior development position for a JavaScript developer. In this interview, my colleague asked candidates to write a function that would execute HTTP calls, and if that didn’t work, try multiple times.

Once he started writing code on the whiteboard, he could just write pseudo code. If he had a better understanding of the problem, we would have been happier. But unfortunately, he couldn’t come up with a good solution.

Given that he might be nervous, we decided to take it easy and ask him to write a function that converts the callback into a Promise.

A bit of bad luck.

Of course, I can say he’s seen code like this before. He knows more or less how it works. A pseudo-code solution would prove that he understood the concept.

But the code he wrote on the whiteboard made no sense at all. He had only a vague understanding of the concept of JavaScript Promise and could not explain it well.

If you’re a junior developer, you can avoid this, but if you’re applying for a senior developer position, it’s not enough. How does he debug the complex Promise chain and explain to others what he’s doing?


Developers are used to abstraction

As developers, our work is full of abstractions. We conceptualize code that would otherwise need to be repeated. As a result, we unthinkingly apply these concepts and assume they work when we focus on the more important parts.

In general, they work, but it’s valuable to really understand the abstract code when you’re dealing with complex situations

The candidate for the senior development position wrote the promise abstraction without a second thought. He’d probably know how to use it if he’d seen it somewhere, but he didn’t really know what it meant, so he couldn’t reproduce it in a job interview.

He could have just memorized the code, which wasn’t hard at all:

return new Promise((resolve, reject) => {
  functionWithCallback((err, result) => {
   return err ? reject(err) : resolve(result);
  });
});
Copy the code

I’ve done that. Maybe we’ve all done it. Memorize a piece of code so that you can use it directly to get a sense of what it means.

But if he really understands the code, there’s no need to memorize it. The code will be written. It will be written.


Understanding source code

Back in 2012, before front-end and back-end became popular, jQuery was the best in the world, and I was reading “Secrets of the JavaScript Ninja” by John Resig, the founder of jQuery.

This book teaches you how to create your own jQuery from scratch and gives you an understanding of the thought process behind creating a library. Although jQuery has faded from the limelight in the years since, I highly recommend reading this book.

One of the things THAT came to me most from reading the book was the feeling that I should have come up with this idea myself. The steps described are so logical and straightforward that I feel like I could have built jQuery if ONLY I had wanted to.

In reality, of course, I could never do it — I’d think it would be too complicated. I would have given up thinking my methods were too simple and naive to be effective. I would take it for granted that jQuery works. I probably won’t even spend the time later researching why it works. I would use it like a black box.

Reading this book changed me. I started reading the source code and found that many of the solutions were straightforward, even obvious.

Now, of course, designing your own solutions is another matter entirely. But reading the source code and re-enabling existing methods yourself is exactly what will help you write your own code.

As a developer, the inspiration you get and the methods you learn in this process will make you change. You’ll discover that the library you used and thought was magic isn’t magic, just a neat and clever solution.

Understanding the code takes time, step by step, but it also allows you to go through the same piecemeal progression that the founders went through. This gives you a better understanding of the programming process and gives you more confidence to create your own solutions.

When I started using JavaScript promises, I thought they were magic. When I realized they were based on callbacks, my view of programming changed forever.

The pattern designed to get rid of callbacks is to use… Callback to implement?

It changed me. I realized that the code wasn’t too complicated for me to understand. It’s easy to understand if I have enough curiosity and willpower to dive in.

That’s how you learn to program. That’s how you become a better developer.


Reinvent the wheel

Go ahead and build your own wheel. Write your own data binding, write your own promises and even your own state management solution.

It doesn’t matter if no one uses it. You grow from it. If you can use it for one of your own projects, that’s great. You will develop better and grow more.

The point is not to apply your solution to production, but to learning. Writing your own executable code for existing scenarios is a great way to learn from the best.

That’s how you become a better developer.

If you find any mistakes in your translation or other areas that need to be improved, you are welcome to the Nuggets Translation Program to revise and PR your translation, and you can also get the corresponding reward points. The permanent link to this article at the beginning of this article is the MarkDown link to this article on GitHub.


The Nuggets Translation Project is a community that translates quality Internet technical articles from English sharing articles on nuggets. The content covers Android, iOS, front-end, back-end, blockchain, products, design, artificial intelligence and other fields. If you want to see more high-quality translation, please continue to pay attention to the Translation plan of Digging Gold, the official Weibo, Zhihu column.