About infinite loops, newbie mistakes and a lesson learned.

Henrike Wiemker
4 min readDec 11, 2020

--

Photo by Nicolas Lobos on Unsplash

A couple of weeks ago, my bootcamp for web development took a side step into app development. After having learned about React for a couple of weeks, we students were supposed to try out React Native for one project during one week. It’s very similar and very different at the same time and it was a challenge.

In other weeks the projects and websites we are supposed to build are pretty well-defined. There is a clear topic and specific requirements that are supposed to be fulfilled. I’ve built a weather app, a movie site, a todo app and much more and all of these ideas I got from the bootcamp.

During the React Native week, things werde different. We were supposed to build an app, but the requirements were very broad. We could have build everything from a cat image randomizer to an app showing COVID19-cases. I decided to build a weather app for Mars, using data from a NASA api. We had done some projects using APIs and I liked those a lot — there is so much happening even in a very simple website if there is data coming in from somewhere else.

At this point, I didn’t know how much I would struggle with this API.

I started exploring the APIs endpoints and documentation and quickly saw that there was a limited number of requests allowed during one hour. In earlier projects, I had several times managed to build infinite loops when using APIs: My site would fetch data from the API which would update a variable which would trigger a rerendering of the site which would trigger a new fetch to the API which would update the variable… you get it. All this happens during milliseconds, so every request limit is usually quickly reached.

I told myself to be careful not to build an infinite loop this time. I carefully chose my lines of code, started the page…. and my poor computer went bananas trying to handle the data load. Of course I had built an infinite loop.

The only thing to do was to fix the code and wait, because at least for the next hour, I wouldn’t be allowed to do more fetches to the API.

Duruing the following days I slowly build up my app and started to like it. I showed the avarage temperature on Mars to the user, as well as wind speeds and air pressure and I even was pleased with the design I made (which I usually struggle with).

Then, one day before I had planned to hand in the project, my app stopped working. The error message told me that I had exceeded the number of allowed requests and I was puzzled. I hadn’t changed anything about the data-fetching part of the code lately and it had worked perfectly for two days or so. I couldn’t find the cause of the problem and frustration was growing. I started to think of a small, entirely different app that I could build within a day to fulfill the requirements without handing in my beautiful (but not working) Mars weather app. I also sent a message to one of my best friends just to share my frustration about this API which refused to cooperate with me.

The friend works with automation in the car industry and has (as far as I know) not done a lot of frontend developing. But her boyfriend has. So a couple of hours later I suddenly had a message from him, saying something like: “Sounds like a cool idea! Have you checked your API key? That can sometimes be a problem. And which API is it you’re using? Maybe I could look into it.”

The API key is a series of numbers and letters that is used to identify a user of the API. I looked at mine — and there it was, the cause of the problem. When I had started to explore the API’s data I had used a demo key that is provided for exactly this purpose. But not for more. It has a limited number of request. But instead of creating an account to get my personal API key I had just started building the app with the demo key and, in fact, exceeded the number of allowed requests.

I felt so dumb. This seemed to be the worst newbie mistake I could have made. My friend’s boyfriend didn’t even know which API I was working with and still he was able to solve my problem with just one qualified guess, based on experience. I felt ashamed but at the same time I was oh so happy that I could finish my Mars weather app and hand it in as a project.

And after a couple of days the shame disappeared. Yes, I made a newbie mistake, but I probably won’t do this exact one again. I solved it by sharing my frustration and failure. I could have asked my friend’s boyfriend immediately but I didn’t even think of it. I should have! Lesson learned: Dare to ask, share your failures.

--

--

Henrike Wiemker
Henrike Wiemker

Written by Henrike Wiemker

I’d been a science journalist for years when I decided to go inte programming. And I love it! Also a German living in Sweden, enjoying multilingual life.

No responses yet