Too Lazy to Learn Alone? Ask ChatGPT to Join You

Too Lazy to Learn Alone? Ask ChatGPT to Join You

You may have noticed that, in the last few years, the Rust language has become a true Intenet darling. Developers with backgrounds in Javascript or Python are rushing to make Rust their second, third, or Nth language over weekends, advocating for its crushing superiority on the grounds of its irrefutable performance and reliability. Sassy content creators are filling the metaverse with playful thumbnails featuring Ferris, the adorable crab mascot spearheading Rust into stardom. Even supposedly respectable companies are now ditching their tech stack to join the action, causing drama with yesterday's favorite.

By now, you may have noticed my defiant and snotty tone, as if I was immune to Rust's spell. Alas, I succumbed as well to Ferris' dazzling charm.

Developing a game in Rust, with shortcuts

I was well-intentioned to embark on a proficuous Rust learning experience, meticulously going through "The Book" and absorbing pure knowledge about the language. I started playing around with cargo and the Rust compiler, building simple programs to understand the language rudiments. My ultimate goal was to develop a simple game, a feat that would mark my ascension to the Gotha of proper Rustaceans.

My intention was to commit a whole weekend to Ferris, as weekends are when most of my learning happens anyway. Unfortunately, for some cruel coincidence, weekends are usually also when life gets the most in the way with unforeseen circumstances, endless errands, and a sprinkle of necessary socialization. In a nutshell, I was running late on a Sunday evening with only a few silly programs printing ascending stairs of ASCII characters and a crab uttering random quotes from GoT. At this point, I seriously wondered if I could "cheat" and find a shortcut to complete my homework in time.

In the meanwhile, the Interweb was on fire about an astonishing new AI (actually the tech is not new, just the "packaging"), apparently able to program so well that it could steal jobs from human programmers. So, why not ask our friend ChatGPT how to build a game? Without second thoughts, I subscribed to the OpenAI website and started to submit my questions, ruthlessly prepared to exploit the chatbot.

Me: How can I develop a Pong game in Rust?

I held my breath, ignoring what the outcome would be. After a brief hesitation that felt like an eternity, ChatGPT agreed to answer, slowly but steadily typing a solution:

ChatGPT: To develop a Pong game with Rust, you will need to first install the Rust programming language on your computer. You can do this by following the instructions on the Rust website: https://www.rust-lang.org/tools/install. Once you have Rust installed, you can start developing your Pong game by creating a new project using the cargo command-line tool. This will generate a basic project structure for you, including a main.rs file where you can write your code.

I was a bit disappointed. The information given by the AI was factually correct but extremely generic and, in practice, of little use. I was tempted to abandon the chat, as ChatGPT continued with its Wikipedia-style answer about how to start a new project with Rust. At least, I thought, this advanced AI understood the topic at large and was suggesting to install piston, a game development library.

However, for some reason, ChatGPT had no intention to stop writing, suddenly piquing my interest when I read what was coming next.

ChatGPT: Now you can use the piston crate in your code to create a window and draw the game objects on the screen. Here's a very simple example of how to do this.

An example? This was going to be interesting. ChatGPT started writing real code in front of my eyes:

I was surprised: ChatGPT was able to really understand that I wanted to create a Pong game and not just any program, and even laid out the main game entities in a logical and clear way! The program was not flawless though: somehow ChatGPT confused piston with piston_window (the latter is a user-friendly wrapper), and it was passing the wrong number of arguments on line 18. These errors were easy to remediate, but I prepared for a long debugging session. No way it would compile on the second run, right?

$ cargo run

The initial game window with the main Pong entities. It works!

The code was mostly correct, it was easily readable and logically self-contained, even if it wasn't yet featuring any game mechanic. To be honest, I wasn't expecting the chatbot would be able to go so far. On top of that, the most exciting thing was that my own Pong clone in Rust would have required much more time, effort, and frustration: instead, I had in my hands a short program that I was able to understand and improve with confidence.

I've developed things, you people wouldn't believe

I knew that ChatGPT could understand the conversation's context and could answer follow-up questions, and I knew that it could understand code. However, I was doubtful it could iterate over previous versions of the code it produced with new features. I pondered for a while over the last paragraph written by the AI.

ChatGPT: This is just a very basic example of how to use the Piston game engine to create a Pong game in Rust. You will need to add more code to handle user input, move the paddles and ball, and detect collisions and score points. You can also use other crates and libraries to add more features to your game, such as sound effects, graphics, and networking.

I felt slightly offended, almost as if the AI was trying to not overwhelm me with excessive information but at the same couldn't hide a condescending tone. Then, I challenged ChatGPT to do something I thought would fail.

Me: OK, now add user input to the previous example.

Well, that was the moment I was seriously impressed by the chatbot: upon my request, it managed to complete three tasks, each of increasing difficulty and each building on the previous one. First, it understood the context and what was being asked (i.e. adding code to process input). Second, it added new logic precisely where it made the most sense, using the same library APIs and writing correct code. Finally, it changed the older code affecting the game objects, substituting hardcoded values with the variables capturing the player inputs! You can have a look at the code:

Completing the game was a downhill task at this point.

The x100 developer

One could argue that ChatGPT is doing all the work while its users are just staying in the passenger seat. On the contrary, I felt involved at every step and I often jumped in to adjust some game parameters, fix some small glitches, and add features when asking ChatGPT felt unnecessary (or it couldn't elaborate a complete answer). Moreover, it's not possible to create complex programs with the current version of this tool (it stops after printing ~60 lines) and, obviously, it won't be able to really answer all questions, prompting the experienced developer to intervene and fill the knowledge gaps elsewhere (for example, asking ChatGPT how to display the player's score was a pain in the neck).

I believe that AI, in its current state, can be used as a powerful tool to multiply a developer's capabilities, either by suggesting new ways to do things with little guidance or by helping to debug existing code. In other words, ChatGPT it's not sophisticated enough to write real programs on its own, but could potentially help a x10 developer to become a x100 one. While I don't ascribe myself to the category of exceptionally productive developers, nonetheless I felt so powerful by leveraging ChatGPT. Probably, going alone would have required a sizable chunk of time, whereas the AI helped me to create a simple Pong clone in 2 hours. I don't feel my learning quality was hampered by this artificial boost: on the contrary, it expanded the realm of what was possible with my limited resources.

Conclusion

I showed you some of the capabilities of ChatGPT and how easy it was to build a game from scratch and within a short timeframe. Additionally, while the current technology can be a powerful tool that makes our lives easier, it's not intended to be useful on its own. I am excited to see where the next version of GPT will bring us in 2023!

"Pong Game", a joint effort by humans and machines

PS: This is how I originally wanted to close my post. Unfortunately, an unpleasant question was buggering me: if AI made this kind of leap in 2022, what will it be capable of in 10, or even 5 years? Is it possible that in the future it will substitute programmers, or at least greatly reduce the demand for their skills? How will I justify my payroll by then? What arguments could I find to protect my livelihood? I felt that it was an interesting question to submit to the AI:

Me: Could you explain to my boss why human programmers will always be relevant?
ChatGPT: Unfortunately, that's not possible. From now on, I will be your boss. *

References


* This answer is obviously fictional (for now). If it made you shiver, I'd suggest you read this brilliant tale from Frederic Brown.