CodeNewbie Community 🌱

Cover image for When should I use code?
Vicki Langer
Vicki Langer

Posted on • Originally published at dev.to on

When should I use code?

You can use code whenever you want. Programmers often joke that they’ll take 20 hours to code something that would have taken them only 20 minutes to do. Imagine the person who programmed the robot vacuum.

an XKCD comic strip with 3 boxes. <br><br>
1st box: stick figure 1 asks "can you pass the salt?"<br><br>
2nd box: stick figure 1 sits there waiting for the salt<br><br>
3rd box: stick figure 1 says "I said-" and stick figure 2 responds "I know! I'm developing a system to pass you arbitrary condiments". stick figure 1 responds "It's been 20 minutes!" lastly, stick figure 2 says " It'll save time in the long run!"

Does it make sense, timewise?

Personally, I’d count how often I do it, estimate how long it would take to automate or code the thing, then see if the hours programming is going worth the effort. For example, if it takes 10 minutes to do dishes and you have to do it every day that would be 3650 hours per year. Would 100s hours of programming be worth coaxing a computer to do dishes for you?

an XKCD comic "Is it worth the time" chart. "How long can you work on making a routine more efficient before you're spending more time than you save." Don't forget the time you spend finding the chart to look up what you save. And the time spent reading this reminder about the time spent. And the time trying to figure out if either of those actually make sense. Remember, every second counts toward your life total, including these right now.

Xkcd.com made this chart to show how much time is saved by automating something. Let’s look at making an automatic cat snack dispenser. Let’s say it takes 5 seconds to open a bag of treats and give them to the cat. We’ll also say you give the cat some snacks 1 time per week. The snack dispenser would cut 5 seconds from your snack process because you don’t have to do it anymore. This chart shows that over 5 years, our cat snack dispenser would only save 2 hours. Is it worth it? That’s up to you. It probably depends on how long it would take to code the snack dispenser and how demanding your cat is.

Going back to the dishes example, after programming a computer to do dishes, it now only takes 5 minutes. So, 5 minutes have been shaved off of the time it takes to do the daily task. This would save 6 days over 5 years. Is it worth it? That’s up to you. Though, it may depend on how long it takes to code this automatic dish washing machine.

Typically, when the gain from your code is more than your loss, get to coding.

An exception to the rule

When we are learning, this may be a little different. You’re also gaining a better understanding of code every time you use code to do something. In this case, you would gain the benefit of the code and the knowledge on how to do the things you learned to build that code. So, it may very well be worth building that automatic cat snack dispenser even if it doesn’t fit my gain > loss rule. The cat would really appreciate it.

Oldest comments (0)