In this article, I have explained how OpenAI’s ChatGPT transformed our team’s Android and iOS app development process, enhancing code review, enabling code conversion, automating data class generation and test writing, and simplifying routine tasks, while highlighting the need for human oversight and precision in commands.

When our team first embarked on the journey to modernize our Android and iOS app development process, we didn’t expect a language model like OpenAI’s ChatGPT to play any role in it. Yet, here we are, breaking the conventional bounds of software development and integrating AI into our everyday coding routine. And guess what? It’s been quite a game-changer.

First Encounter: Code Review

In any development team, code review is an important aspect of everyday work. We peer review each other’s code and ensure the code written enhances the application’s overall code quality at the end of the day. However, with time constraints and due to the fact that engineers get occupied with their work, a so-called dedicated code review is often used to end up with a thumbs up or LGTM with possibilities of improvements buried and not explored in the code.

This was a problem and we tried to do many things to catch the issues early. We were looking for something that could work with our developers to tell them what can be done to make the code better. So one fine day we thought of giving AI a shot. A simple Python code was written, which read a directory full of source code and send to OpenAI’s GPT 3.5 Turbo to get them reviewed. After a few experiments with the prompt and it was ready. The AI started reviewing the code and giving meticulous actionable inputs which could make the code way better.

AI-aided code review

The GPT-3.5 turbo engine did more than just highlight our missing semicolons or mismatched brackets. It delved deeper into the logic, the architecture, and the very soul of our code. As if it was a seasoned developer, it made shrewd observations, catching issues and suggesting improvements before our work even reached a human reviewer’s eyes. It was like having an extra set of meticulous, tireless eyes, streamlining our development process and making our code better.

One such result of reviewing a file is shown below. This is beautifully done and with thorough care. In some cases it even gives the optimized code also (you have to modify your prompt for this).

Review for NetworkClient.kt: 

1. In line 3-6, the JSON parser configuration is hardcoded in the class. 
This can be extracted out into a separate configuration class, which can be 
reused across the application.

2. In line 9-21, the HttpClient is defined as a getter function, which can be a potential performance bottleneck as it creates a new instance 
of the client on every invocation. 
This can be corrected by making it a lazy variable, which would create the HttpClient instance only when it is first accessed.

3. In line 30, the GlobalScope.launch is used to launch a coroutine, which is not recommended as it can cause memory leaks. 
Instead, it should be replaced with a coroutine scope that is limited to the lifetime of the request.

4. In line 35, the result.body() is called twice, which can be avoided by storing the response body in a variable and using it in both places.

5. In line 40-44, the logic for handling 401 errors and refreshing the token is not clear. 
It can be improved by extracting it into a separate function and providing a clearer error message.

6. In line 49-55, the catch block is catching a broad Exception and providing a generic error message. 
This can be improved by catching specific exceptions and providing more meaningful error messages.

7. In line 56, the client.close() is called outside the coroutine, which can cause issues with the request lifecycle. 
It should be moved inside the coroutine to ensure that it is only called when the request is completed.

Breaking Language Barriers: Code Generation

ChatGPT, our new team member, didn’t stop at code review. Next, it took on the task of code generation. We used to write the same logic twice: once for Android in Kotlin and again for iOS in Swift. Then one fine day it occurred to us, why not try and see how it works if we ask ChatGpt to do the coding? We already have the code written in either Kotlin or Swift. It is only about conversion. What’s wrong with trying?

In the first experiment, we wrote a functionality entirely in Kotlin and then pasted the code in ChatGPT (without sensitive things, obviously) and asked it to produce Swift code for the same logic. It was brilliant. The code written within seconds could have taken more than a week’s development effort.

ChatGPT saved us from this repetitive task. It took our Kotlin code and, with a swift (pun intended!) transformation, returned beautifully written, optimized Swift code. After a brief human review and minor tweaks, we were able to introduce the AI-generated code to our codebase. It was nothing short of magical.

The Class Act: Generating Data Classes

API responses, in their raw, unstructured form, can be quite a headache to study and then model to a Data class. We had some other tools that we used internally but those needed some sort of cleansing operation on the JSON before they could be fed in to create data classes. That was an annoying and time-consuming thing and we wanted to make this swift.

We found another ally in ChatGPT when it came to generating data classes. With a simple copy-paste of the API response, we got back ready-to-use data classes in an instant for both platforms. This AI-powered class wizardry drastically cut down our manual effort and made dealing with API responses a breeze.

For example,

This prompt in ChatGPT:

create codable model and Kotlin Data class from below JSON using swift and Kotlin respectively

{"services":[{"label":"Money Transfer","icon":"https://raw.githubusercontent.com/someurl/P2P.png","order":45,"isNew":"false","serviceType":"Banking","cta":"P2P"},{"label":"Cardless Cash","icon":"https://raw.githubusercontent.com/someurl/CC.png","order":2,"isNew":"false","serviceType":"Banking","cta":"CC"}]}

The output:

import Foundation

// MARK: - Services
struct Services: Codable {
     let services: [Service]
}

// MARK: - Service
struct Service: Codable {
     let label: String
     let icon: String
     let order: Int
     let isNew: String
     let serviceType: String
     let cta: String
}

and in Kotlin

import com.google.gson.annotations.SerializedName

data class Services (
     @SerializedName("services") val services : List<Service>
)

data class Service (
     @SerializedName("label") val label : String,
     @SerializedName("icon") val icon : String,
     @SerializedName("order") val order : Int,
     @SerializedName("isNew") val isNew : String,
     @SerializedName("serviceType") val serviceType : String,
     @SerializedName("cta") val cta : String
)

The Test of Time: Writing Tests

Unit and UI tests have always been an integral part of our development process, albeit a rather laborious one. We used to spend days writing the tests for a feature. After seeing our success in other fields with ChatGPT the question came to mind. Can we leverage its power to write tests as well?

Enter ChatGPT, which turned days of test-writing into mere minutes. Just feed it a class or a flow, and voila! Out comes a set of well-structured unit and UI tests. A couple of iterations and reviews later, we had robust tests ready to vouch for our code’s reliability.

Scripting with Ease: Automation Scripts

And when it came to automating our routine tasks, ChatGPT proved its mettle yet again. From generating developer action summaries from GitLab to creating release branches across multiple repos, ChatGPT turned laborious day-long tasks into a few quick commands. Our newfound productivity was indeed a joy to behold.

Too good to be true?

However, our journey with ChatGPT hasn’t been all rainbows and unicorns. The AI has its quirks. At times, it produces outputs that leave us scratching our heads. Slight changes in input phrasing can lead to markedly different outputs. It doesn’t ‘understand’ our commands the way a human would, and sometimes it misses the mark on context or intricacies.

But here’s the thing. ChatGPT isn’t meant to replace us, developers. It’s here to aid us, to make our lives easier, and to streamline our workflows. Its outputs, while impressively accurate most times, need to be reviewed and validated by us humans. It’s in this symbiotic partnership that we’ve found our rhythm, a rhythm that mixes the speed and efficiency of AI with the meticulousness and context awareness of human intellect.

Human and AI collaboration

While we’re stoked about what we’ve achieved so far, we also understand that feeding the right data to ChatGPT is crucial. Garbage in, garbage out, as they say. So, we’ve learned to be precise and detailed in our prompts, giving AI the best possible starting point. Also, from an IP point of view, it is important to have a policy around what to share with ChatGPT and what part of the product we keep for us, humans. This comes with some iteration and observation. But the overall product is benefitted from the AI.

At the end of the day, we are in control. We still make crucial decisions, interpret the AI’s outputs, and ensure they are suitable for our specific use cases. It’s like having a superpower that needs to be handled with care. Yes, ChatGPT saves us a ton of time and effort, but it doesn’t diminish the importance of our role; instead, it allows us to focus on the truly creative and critical aspects of our work.

Closing Points

In conclusion, our adventure with ChatGPT has been both exhilarating and enlightening. We’ve learned that with the right approach, AI can be a formidable ally in the world of software development. It has reshaped our process, infused new energy into our team, and heightened our productivity. This is only the beginning. We’re excited about the road ahead, and we can’t wait to see how much further this AI-powered revolution will take us!

How are you using AI in your daily work? Let me know in the comments. Also, if you are interested in the Python script we wrote to review the code, let me know in a comment and I will share the GitHub URL with you!

Resources

Swagata Acharyya

Swagata Acharyya

Swagata is a passionate Solution Architect with rich experience of over 16 years. He has been instrumental in designing and delivering innovative mobile solutions across diverse sectors like Fintech, Cabin Innovation in aviation, Entertainment...