My iOS calculator with GPT3

I wrote my first app with GPT3 and these are some of my notes and my takeaways.

I always wanted to try GPT3. I bookmarked a YouTube tutorial to try GPT3 with Python. And sure enough I never started it. (If only I could learn from bookmarks!!)

Then chat GPT was launched. Like million others I couldn’t get enough. After some interesting and some stupid questions, I decided to try programming. I saw on Reddit that GPT3 can churn out working code in multiple languages.

I always wanted to write a small app.

So I took the opportunity of some downtime between interviews (I’m looking for a new job!) and asked GPT: “what do I need to do to write a calculator for iOS”?

Boy, was I blown away!!!

I decided to write this article to share my experience and my learnings.

Structure drives behaviour

If you ever spoke with me about work for more than 5 minutes, you probably heard me saying that “structure drives behaviour”. When you start seeing the world this way, there is no way back. If you are old enough to understand this analogy, it’s like that guy who could see the people walking when looking at the green screen in the matrix.

GPT was always so powerful, and I was always attracted to it when reading r/GPT3 but yet the barrier to entry was still too great for me. The moment the barrier was reduced (structure) I started using the platform (behaviour).

What can GPT3 do and what it cannot (or I didn’t know how to ask!)

It’s important to understand that without GPT3 my app would have never been completed, but my logic and rudimentary experience in programming was also absolutely necessary to complete the project. I am just trying to give you realistic expectations. If someone knows nothing about software development and never wrote a line of code, I’m worried it might be hard to pull off. All in all, GPT was essential to laid out the skeleton of the code and the UI. Without any knowledge of Swift it would have taken likely hours to get something going. GPT3 made it possible for the basic UI to be visible and working within minutes. This significantly reduced the level of frustration, put the project within reach and made in orders of magnitude more likely for me to complete it.

It is also great at answering tedious questions in a way that is very tailored to my specific case. Instead of the traditional “Google programming”, where you type a question when you get stuck and then try to apply the stackexchange (or your fav dev forum) answer to your case, with GPT3 you can paste your code and ask the AI why you get this particular error code or how can you make the background colour of the button change when you click that button (r/oddlyspecific) and it replies with the code that achieves that objective (or close enough) 🤯 – it really is mind-blowing. I can see this tool replacing Google for many use cases.

It’s way too exciting!

This section and the the rest of this article don’t relate much to GPT3. They focus more on my personal experience during the project. I relived my uni days when I literally couldn’t go to sleep until I figured out a certain problem. One night I was up till 3am refactoring the code to figure out a sneaky edge case. I wonder (and if you’re reading this, pls share your experiences) how full time developers handle this. Is it normal to get so excited to solve a problem? Is it easy to unplug at the end of the day when it’s not “your” project or do you keep thinking about it? As soon as I had 10 minutes I was on Xcode coding and debugging.

Scope creep is real!

I didn’t start with an MVP (bad PM!) I had the same UI that you see in the screenshot since the beginning and I kept adding stuff without thinking of the risks. As a product manager, it’s great to see first hand how true it is that test cases grow exponentially. E.g. I wanted an operator (*, /, +, -) button to change colour when pressed. What I thought would be very easy to do, took me few hours due to edge cases I didn’t foresee. GPT suggested to use a Boolean and toggle() to switch colour. The result was the if I typed 3x3x4 the colour changed the first time I pressed X and then went back to normal the second time! I think this will give me more perspective when trying to nail an MVP.

I still think on new features I want to add! I’ll change font so that you can use the calculator to write stupid “words”. If you’ve used digital stand alone calculators long time ago you understand what I mean.

Edge cases and QA

This project renewed my admiration for software engineers and QA engineers. The first hurdle when developing a calculator is that sometimes you need to show a string on the screen which is not a “proper” representation of a number. “2", “2.”, “2.0", “2.000" are all the same number: “2". The extra characters are meaningless untill you type another digit between 1 and 9. Nailing that logic took me a few hours and a lot of “2.0.4" shown on the screen 😓

A superficial QA (“2.01", works!) would have left a tons of bugs in the code.

So shout-out to devs and QAs who are passionate about their work and allow us to enjoy bug free apps and websites.

Refactoring

Even for such a small project at some point I had the need for a non-trivial refactoring. I decided to group a few variable to represent the current state of the calculator. The number, the string currently on screen and 3 more. That became necessary when I couldn’t figure out a nasty bug and I realised that I was doing too many direct changes to these variables breaking the internal coherence of the current state. It gave a small window into the struggles of engineers who need to chase a bug in a code they probably didn’t write, always with less time that they would like.

Geeks are geeks

I know this project sounds dull to most of you but I also know it sounds exciting to some. I know who among my friends would get excited about playing with GPT3 for software development and the challenges even a simple calculator has. I spent a fun few hours chatting with them. ♥️

Apple Developer Program

My last thoughts goes to the mind blowing number of apps considering you must pay $100 per year for the privilege to publish an app. What made me sad was realising that you cannot even publish on test-flight without paying. I was hoping to share my app with a few friends, but it might be destined to live as a single unique copy in my own phone! If you have experience please share it. I would need to sell 350 copies if I charge $0.29 to recover the cost. Do you think it’s realistic?

If you have an idea for another simple basic app that I could tackle in a week, let me know! I’m trying to write a snake game next but I’m worried it will prove too much!

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store