Blog AI/ML How GitLab Duo Code Suggestions helped me make long car rides fun
August 3, 2023
5 min read

How GitLab Duo Code Suggestions helped me make long car rides fun

AI-powered Gitlab Duo Code Suggestions coupled with Remote Development workspaces helped me create a Python-based guessing game application to keep my daughter entertained.

carride.jpeg

On long car rides with my daughter I have two options: Let her watch a movie or continuously play a game with her where she tries to guess a random number in my head. I often opt to play the game, but recently, my energy and patience weren't at their peak. This led to a moment of inspiration. Why not develop a simple application that my daughter could play on her own? The only hurdle was that I haven't developed an application in years, and, since then, new languages such as Python have emerged.

With the help of the AI-powered feature GitLab Duo Code Suggestions (Beta), I was able to quickly develop a Python application, despite having no prior knowledge of the programming language.

How I built the guessing game application

My application development journey began by launching the Web IDE powered by VS Code. From there, I navigated to Preferences and activated Code Suggestions, paving the way for my AI-assisted coding session.

Thanks to Code Suggestions, I had the flexibility to input code or compose comments in plain text English, and receiving automated code suggestions while typing. For instance, I included only these three comments, ultimately utilizing them to construct the entire application:

  • store a random number between 0 to 10
  • print a welcome message to Yael, ask to guess a number between 0 to 10
  • create a loop that will continue until the user guesses the number

To my surprise, not only did the code suggestions align with my comments, but they also grasped the underlying concept of my application, offering additional code without explicit comments. After making a few minor adjustments, here is the final code for the game:

import random

# Store a random number between 0 to 10
number = random.randint(0, 10)
counter = 0
# Print a welcome message to Yael, ask to guess a number between 0 to 10

print("Welcome to the guessing game, Yael!")
print("I am thinking of a number between 0 and 10, can you guess what it is?")

# Create a loop that will continue until the user guesses the number

while True:
   # Get the user's guess
   guess = int(input("Guess my number: "))
   counter += 1


  # Check if the user's guess is correct
   if guess == number:
       # If the guess is correct, print a message and break out of the loop
       print("You guessed it! My number was", number, "and it took you", counter, "guesses.")
       break
  
   elif    guess < number:
       print("Your guess is too low.")
   else:
       print("Your guess is too high.")

With the assistance of Code Suggestions, I was able to navigate the intricacies of Python coding, step by step. The suggested code not only aligned perfectly with my intentions, but also expanded my understanding of the programming language, enabling me to build a functional game.

After thoroughly testing the guessing game application using the debugging tool in VS Code, I was delighted to find that it worked flawlessly! However, a new challenge arose: How could I make this game accessible to my daughter while in the car?

How to leverage GitLab Remote Development workspaces Beta

If you have young children, you're likely familiar with their constant need for instant gratification. To satisfy my daughter's desire to play the new game on her iPad right away, I needed a solution.

Since the game wasn't available as a mobile or web application, I decided to utilize the power of GitLab Remote Development workspaces to create a mobile environment for her.

The workspace is a temporary development environment hosted in the cloud, which offers a simple setup process and numerous advantages for developers. Now, you might wonder how this is relevant to our topic. Well, Remote Development workspaces provides a link to access the environment. This became my workaround to allow her to start playing the game immediately within that development environment directly from her iPad.

This strategy turned out to be the perfect workaround, not only allowing her to enjoy the game but also exposing her to the captivating world of programming.

Understanding beta features

While my journey of developing a game in Python, with the help of Code Suggestions, has been incredibly valuable, it's important to acknowledge that the feature is currently in its beta phase. As is common with beta features, there are certain considerations to keep in mind. Due to the high demand and ongoing improvements, there may be occasional unscheduled downtime and potential delays in receiving Code Suggestions within IDEs. Additionally, it's worth noting that the suggestions generated by Code Suggestions may occasionally be of lower quality or incomplete. As Beta users, it is crucial to familiarize yourself with the documented limitations.

Demo

This click-through demo showcases how I used Code Suggestions to develop the guessing game application. I encourage you to give Code Suggestions a try today as you will have a lot of fun.

We are looking for your feedback!

Feedback from Beta users of Code Suggestions is invaluable. The GitLab team eagerly awaits your input, which will play an important role in further enhancing this feature and refining its capabilities. Together, we can shape the future of Code Suggestions and make it even more powerful and reliable. To send feedback, or report on issues, use the Code Suggestions feedback issue.

We want to hear from you

Enjoyed reading this blog post or have questions or feedback? Share your thoughts by creating a new topic in the GitLab community forum. Share your feedback

Ready to get started?

See what your team could do with a unified DevSecOps Platform.

Get free trial

New to GitLab and not sure where to start?

Get started guide

Learn about what GitLab can do for your team

Talk to an expert