Blog article

In my previous posts (part 1 & part 2), we developed a Calendar widget capable of picking a date while respecting some basic business rules using Phoenix LiveView. I am sharing the code we created so you can get a clearer understanding of what we have accomplished in a just a few hours of work.

In this article, we share our reflections on how AI tools have aided us throughout our process and the key factors that make a difference in their usage.

Making sense of programming with AI tools

The main takeaway from this experience is that choosing the right moment to switch to ChatGPT or similar assistants that work outside the code editor is crucial. It is smart to balance the times you interact with the chat and when you regain full control of the code. In particular, developers usually aim to achieve a flow state incompatible with the frequent usage of an external tool that requires continuous back-and-forth.

When developing software or adding new features, it can be helpful to seek external assistance to gain insights and move beyond the initial stages of the task. We get a sense of that in our previous posts about creating the LiveView component. Asking the chat to generate an appropriate amount of skeleton or boilerplate code is often a good idea, but always try to scope it explicitly to get the most out of ChatGPT.

Using bullet points to specify reasonable iterations is a good strategy for better results. Similarly, you can divide the task into several prompts rather than asking everything at once.

Ask specific and scoped things

You have to expect that as you produce more code and dive deeper into the details, the responses from ChatGPT will likely become less accurate. Simultaneously, the quantity of code you did not write directly increases. As developers, we would eventually reach a point where it is more laborious to investigate and fix problems created by the received code than to program things unaided. Depending on each individual, investing too much time and energy in conversing with a chatbot using natural language may outweigh its benefits sooner or later.

When you notice that turning point in your development process, it’s time to start working directly inside your code editor. Make sure to iterate your code by adding new elements, fixing any issues, and refactoring your work until you feel you have complete ownership of the code. As the code’s author, you need to understand and make sense of each line of code produced by any AI assistant.

As it is now 2023, you no longer have to program alone. While spending time on the code editor, you can use integrated tools like GitHub Copilot, which serves as your companion. If this is your first time using it, adjusting to the appearance of code suggestions that pop up unexpectedly may take some time. It may feel like someone else is controlling the keyboard and interrupting or competing with you as you type!

Understanding how and when code suggestions will pop up may take some time. I’ve become more capable at predicting when to pause typing for an instant to allow Copilot to generate helpful hints. Also, I’ve learned to anticipate when the suggestions may not be accurate.

What about the state of these tools with Elixir, Phoenix, and LiveView?

It has some ups and downs.

We can assume that ChatGPT was trained with an amount of Elixir code comparatively smaller than other languages and stacks, resulting in lower accuracy. In addition, we know that anything added to Phoenix/LiveView in the last two years was not part of the training data. It may also be the case for Copilot. Nevertheless, you can obtain some good ideas by doing your homework with the received code. If you examine the final implementation of the Calendar component from previous posts, you may notice elements inspired by the code suggestions received.

The date manipulation functions in the ChatGPT code snippets for our Calendar widget are a helpful reminder of what Elixir offers. Despite typos and mistakes, I quickly recalled some rarely used functions.

Another idea to share here is to consider using ChatGPT after completing some programming cycles to get feedback. Again, please keep in mind that the comments you receive may contain minor inaccuracies or even terrible errors. However, receiving valuable ideas in the response is still possible, even if you’re a seasoned developer.

Remember to bring an updated version of your code whenever you come back to the chat so that it can provide relevant answers based on your current progress.

Here is an interesting paradox. If you still need to gain experience with Phoenix/LiveView, you will likely see more benefits on receiving code from ChatGPT or event Copilot. But at the same time, you may have to fix or edit things, which could be harder if you’re less experienced with the Elixir stack. It’s important to note that using AI tools as a full replacement for human collaboration in the form of code reviews or mentoring could be very risky. This is especially true for Elixir codebases, and I recommend complementing with something other than AI, especially while you’re learning the tech stack.

Where is my copilot?

Final words

No matter your tech stack, if you have yet to try using those AI tools, please consider investing time to experiment with them. I recommend exploring and finding your unique hot spot; you must fine-tune the time you spend in ChatGPT and the number of times you allow Copilot to write code for you. Ultimately, the turning point will depend on the developer, their experience, and the things which drain energy or motivate them. But in any case, it is reasonable to think that most programmers will increase their productivity and code quality by using that assistance to some extent.

Although ChatGPT and GitHub Copilot have some weaknesses, they will likely improve with time. In particular, ChatGPT’s new capabilities to browse the internet means that it can incorporate recently generated knowledge into frameworks and approaches like Phoenix Live View, which have rapidly evolved. In plain terms, AI tools will continue to learn and acquire knowledge, thus influencing the way programmers write code in the future, regardless of the technology used.

Of course, there is a learning curve to mastering the usage of these AI assistants. And the results will be better if you learn how to use them wisely. You can start by carefully reading the ChatGPT best practices and checking the GitHub Copilot shortcuts list.

I am passionate about optimizing the use of available tools to enhance my programming work. Have you discovered any effective approaches or strategies you want to share? Let me know.

Header image credits: Photo taken from
Meme credits: Imgflip Meme Generator