Artificial Intelligence (AI)

Summarized using AI

ChatGPT for Legacy Ruby Application Refactoring

Sergey Sergyenko • August 30, 2023 • Warsaw, Poland

The video "ChatGPT for Legacy Ruby Application Refactoring" features Sergey Sergyenko discussing his experiences with using AI, particularly ChatGPT, in the process of refactoring legacy Ruby applications. Sergyenko begins by explaining his background and the setup for the talk, emphasizing that it is not a success story but a real account of how things went awry during his project.

He covers several key points:

- Legacy Code Definition: Legacy code is described as code that is not easily understandable or modifiable. It symbolizes a developer's legacy and can often carry a sense of pride, akin to inheriting valuable family property.

- Challenges with Legacy Applications: Sergyenko delineates the common struggle developers face with legacy code, where the tendency is to avoid interacting with it due to its complexity.

- ChatGPT's Role: Utilizing ChatGPT, he aimed to ease some of the burdens involved in upgrading and refactoring his old legacy code. This included creating Docker images and managing version upgrades with AI assistance.

- Human-AI Collaboration: Despite early successes, he encountered significant challenges, including miscommunication and loss of context within ChatGPT, leading to errors and typos. Sergyenko highlights that while ChatGPT provided helpful suggestions, it often lacked the contextual understanding needed for complex development tasks.

- Reflection on AI’s Limitations: The experience prompted him to pose questions about the future role of AI in programming, emphasizing that skilled human oversight remains essential for effective coding and problem-solving.

As the presentation concludes, Sergyenko shares valuable insights on leveraging AI for coding tasks, underscoring the importance of comprehension and interactive engagement with such technologies. He encourages programmers to use AI as a supportive tool rather than a complete replacement for human intuition and skills.

In summary, the main takeaway is the recognition that while AI, like ChatGPT, can assist in streamlining development tasks, it does not eliminate the need for skilled human developers to navigate complex issues effectively.

ChatGPT for Legacy Ruby Application Refactoring
Sergey Sergyenko • August 30, 2023 • Warsaw, Poland

ChatGPT for Legacy Ruby Application Refactoring
____________________________________________

► Looking for a dedicated software development team? Contact us at:

https://visuality.page.link/page

► SUBSCRIBE to learn more about software development:
http://bit.ly/SubscribeVisuality
http://bit.ly/SubscribeVisuality
http://bit.ly/SubscribeVisuality

► Read what clients say about us on Clutch.co:

https://clutch.co/profile/visuality

► Find us here:

Instagram: https://www.instagram.com/visuality.pl/
Facebook: https://www.facebook.com/visualitypl
Linkedin: https://www.linkedin.com/company/visualitypl/
X: https://twitter.com/visualitypl
Dribble: https://dribbble.com/VISUALITY
GitHub: https://github.com/visualitypl

Ruby Warsaw Community Conference Summer Edition 2023

00:00:09.599 Welcome. Sergi Sergyenko is the organizer of this year's Euroka, and he is doing an incredible job with that. He is speaking at multiple conferences and numerous meetups. Today, he came to us and presented as well. He's the CEO of Cyber Gazer.
00:00:28.740 It's difficult that one belt is that you didn't come yesterday for the pre-party, but we'll handle it today. However, there was a funny situation. As I mentioned, Sergi is the CEO, and he came with a presentation about trunk-based development. After the presentation, he stood in front of the whiteboard, arguing with the city of Cyber guys about whether it was cool or not. They were having a lively discussion, which was kind of funny given their differing perspectives.
00:00:45.600 Thank you for having me here. It's very nice to be on stage, and I enjoy bringing topics to the audience. However, it seems that most of the time, people don't want to have me on stage. I usually send out calls for proposals, trying to get into lightning talks. For those who don't know me, they sometimes trust me the first time, but after a few attempts, they typically don't accept my proposals again, so this might be the last time for me. Nevertheless, I will enjoy it as much as I can being here.
00:01:07.500 The idea behind this talk, given the context of this conference, is that it’s not a success story about legacy app refactoring. If you're expecting to learn how to effectively refactor a legacy application, you won't get much from this talk. Just to be fair, I thought the conference was supposed to be yesterday, and I got up thinking it was the conference day, needing to finish my slides. When I realized it wasn’t the case, I had to hastily prepare.
00:01:26.819 As always, when you think you have an extra day, you plan to rest. So, I thought I had the whole day to prepare. Then, the morning of the conference, I realized the topic I submitted was different from what I had been working on. I initially worked on a topic about how to do a Rails upgrade with ChatGPT. When I opened my notes about the legacy application, I realized I needed to rethink my approach. So now, my plan is to start with refactoring and then see how it relates to the Rails upgrade.
00:01:48.479 Honestly, everything that could go wrong with this process really did. Despite this, I still use Twitter. I wanted to hijack Nick's Twitter handle since it’s still available. I intended to register under his name and post some tweets. Unfortunately, I didn’t have time before the talk, but maybe, if we don't get too drunk afterward, we can cyber-squat his Twitter handle.
00:02:07.500 I work for Cyber Gazer, but nobody seems to pronounce the company's name correctly, regardless of the language. It's always mispronounced. The idea behind the name is simple—like Energizer for batteries, Cyber Gazer suggests a source of energy for technology.
00:02:26.580 When it comes to legacy code and legacy applications, this is something I often refer to in my presentations. Legacy code symbolizes a developer's legacy—something that outlasts us and that we can be proud of, a reason to show something to your kids. I recall working on a project ten years ago as a junior developer, and it gave me the opportunity to look through my old commits. I had initially planned to present my first production project with its entire GitHub history, showing that it still functions today.
00:02:44.400 However, I decided against that, as the code from back then was quite poor, and it wouldn’t be advantageous to showcase it. Instead, I considered using some community projects. There are good examples of code that have been committed to history. For instance, the picture shows a pile of books that Margaret Hamilton created for launching the Apollo spacecraft—this is code all of human society can be proud of.
00:03:09.660 The niche of creating lasting code is still open; if you write quality code, you could find yourself standing next to Margaret in the future. Many different approaches exist for working with legacy code. I'm not going to dive deep into that today, but just to highlight a few definitions, legacy code is often described as code that lacks test coverage. For me, however, legacy code refers to code that no one understands, including yourself, and that you cannot change freely.
00:03:23.100 If you cannot change it as you wish, it requires too much energy to dig deeper, which leads to the decision to rewrite it from scratch. This brings up the fundamental law of programming: people love to write code but often dislike reading it. No one spends their nights happily reading through pull requests, thinking, 'Wow, what a great method!'
00:03:42.600 Another perspective on legacy code draws a parallel with inheriting property or wealth from grandparents—something to be proud of, like a family picture, a sofa, or a bank account. Conversely, if you inherit code written by a previous developer, it’s often not something you feel proud of. During job interviews, when you're asked about the age of your codebase and someone boasts about having a rich ten-year-old codebase, you might feel like you’ve drawn the short straw.
00:04:02.539 Code becomes legacy as soon as it is written, and in many cases, all code ultimately becomes legacy. The critical question is, how do we create good legacy code? The main answer is that the code must bring value in an efficient manner. When people are genuinely committed to it, and it delivers value, it remains unchanged within the application.
00:04:20.580 In most cases, businesses don't want you to mess with code that works. It will likely outlast you. If we compare this to biological systems, while humans cannot be viewed as legacy because we die, what we create, such as paintings or software, can last longer. However, software has its own lifecycle; nothing lasts forever in programming. With the rise of AI, there is now potential for software to create something valuable that can last longer.
00:04:43.740 To maintain human bodies—similar to how we sustain biological systems—there is a process of cell regeneration called autophagy, which allows our bodies to self-repair. Over time, we have different sets of cells but still have the same body. For engineering systems, this is symbolized through refactoring. We need to design applications that can easily adapt to changes while maintaining their integrity.
00:05:01.680 Now, let me share a story from ten years ago. I initially considered presenting my first Ruby project, but I found another good example. Ten years ago, something significant happened in Belarus. The Belarus Ruby and Rails user group rebranded itself as simply the Belarus Ruby User Group. This split the community in two, with the Rails members taking one direction and the Ruby enthusiasts taking another.
00:05:20.580 As part of this community, we had our own website, brook.by, and I managed to retrieve this old site. I’ve made screenshots, unsure if the internet archive would be available. You can see this from the README file. Interestingly, it required Java, which I didn't understand at the time because it wasn't common to mix Java with Ruby back then.
00:05:44.340 Looking at this old code, I thought it would be a perfect opportunity for this presentation to showcase a community website. My goal was to get it up and running, and then upgrade it while refactoring along the way. Starting the installation seemed easy to me since I didn't frequently do Rails upgrades.
00:06:04.800 There are many materials available, so I decided to try it first before diving into the books or articles. I wanted to install it on my machine, but after several attempts, it still didn't work. I concluded that I must have been approaching it incorrectly. I reminded myself that everything we do should be straightforward, fun, and low-stress.
00:06:24.540 Continuously facing challenges and frustrations didn't bring me any joy, so I concluded that the solution was simple: let’s use ChatGPT. It could help with the tedious tasks, and I could still enjoy the process of using it to manage my old legacy application. I initiated a conversation with ChatGPT and outlined the current versions I’d be using.
00:06:44.520 It was a friendly conversation, and we shared details about each other's lives. ChatGPT provided me options that were helpful for my project. I used to rely on Vagrant but decided to shift to Docker, as that seemed to be the industry standard. I asked ChatGPT to create a Docker image for me, and it complied with helpful commands and examples.
00:07:05.880 I faced some challenges at first because there were various issues, but after a week—working not full-time but a couple of days throughout the week—we managed to build a functional Docker image. Not only did we get it running, but I also created a Docker Compose file for the project.
00:07:27.660 To demonstrate that everything was in place, I decided to run it live. I had the database set up too. When I executed it, it worked perfectly, and I was thrilled with my progress. I felt proud of my achievements and even shared the news with my mom, saying, 'Hey Mom, I’m getting back to coding!'
00:07:53.280 Regarding upgrades, I had never done that before, but I thought it would be easy since I had ChatGPT assisting me. However, the process took an unexpected turn when ChatGPT suggested I read a detailed upgrade guide. Initially, I was resistant, thinking that since I had AI support, I could skip this step, but it pointed out that the success in upgrading was contingent upon knowing the details of each version.
00:08:15.399 When I disclosed my intention to upgrade from version 3.2 to 4.0, I was informed about the resources available to check compatibility and guided to use several tools to identify potential issues. Following that, I felt overwhelmed at times because I expected a quicker solution from ChatGPT rather than being directed to study various materials or tools.
00:08:40.020 Nevertheless, the clock was ticking with the conference only days away, so I dove headfirst into the project. At one point, ChatGPT suggested that I hire a team of professionals to assist with the upgrade. Instead, I decided to tackle it myself using the resources and guidance that ChatGPT provided, aiming for a successful upgrade.
00:09:07.860 After spending considerable time working on the setup using the pro version of ChatGPT, I realized it was becoming a challenge to navigate through the technical aspects. I envisioned it as a fun process, pulling in its full potential. I hoped that ChatGPT would recognize me as the 'Lord of Darkness' while I humorously referred to it as 'Gomp.' However, as I progressed, the first signs that it wasn't going smoothly began to appear.
00:09:27.780 As I provided my Gemfile details, an unexpected problem arose: ChatGPT didn’t refer to me by name anymore. There was no more recognition, no respect shown in our interaction, and as we moved forward, ChatGPT ended up offering guidance that was often irrelevant or incorrect. At that point, I had to take control and insist it followed my instructions closely, affirming I did not want any more jokes; I needed it to focus on the task at hand.
00:09:51.780 This time, I assumed a serious demeanor, pushing past the distractions, and successfully made progress with my project. The output I received was promising, reinforcing the need to track every step associated with the changes to avoid any future confusions.
00:10:18.420 I established a tracking mechanism, asking ChatGPT to lock every step to preserve what we had accomplished to that point. We broke down the process into actionable steps, and for every suggestion given by ChatGPT, I ensured to integrate it sequentially to maintain a clear and consistent path forward.
00:10:35.720 However, things took a turn when ChatGPT began losing the context of our discussion. After exchanging several messages, it became evident that there was no way to backtrack and revisit prior solutions or strategies we had devised together. This lack of continuity proved to be very challenging.
00:10:57.240 To resolve these complications, I decided to actively participate in the process. I recommended outlining updates more strategically, allowing us to re-evaluate the Gemfile collaboratively to ensure that we didn’t overlook essential updates while integrating new versions effectively.
00:11:20.940 This collaborative approach allowed us to identify specific gem versions corresponding to my current setup, enabling a smoother transition during the upgrade process. As we proceeded with the new versions in the Docker container, the interactions felt increasingly productive, navigating through the dependencies effectively.
00:11:39.840 However, we faced a significant hurdle when tackling the first major upgrade issue from Rails version 3.2, which led to some conflicts in the gems. ChatGPT suggested if there were issues with gems, it would be best to pinpoint some commonalities for better identification and possible resolution of conflicts.
00:12:02.940 It become clear that I needed expert assistance to navigate through specific gem conflicts. ChatGPT steered me in the right direction but wasn’t always effective with precise resolutions. It also generated the first issue where typos crept into the gem versions ChatGPT produced, causing further bumps in the plan.
00:12:25.740 When I updated the Gemfile and received errors related to the updated version, I discovered a glaring typo left uncorrected by ChatGPT. The missing dot in one of the version numbers caused my build process to fail, which illustrated the pitfalls of relying solely on AI for such tasks.
00:12:47.220 Upon fixing the typo, I tried to build it again. Unfortunately, I was met with a bundler exception as it couldn't locate the specified gem version. Due to irregular suggestions for links and versions proposed by ChatGPT, I felt as if the situation devolved into disarray, with the AI producing erroneous version descriptions for several gems.
00:13:06.420 As I dug deeper into the errors, it became apparent that I was dealing with gem versions that didn't actually exist. For every command and build attempt I executed, more errors arose due to mismanaged dependencies on the part of the suggestions provided by ChatGPT. It turned into a long and tedious process, characterized by confusion rather than clarity.
00:13:28.140 These continuous back-and-forth exchanges with ChatGPT led to a realization that, while AI might be an innovative tool, it cannot entirely replace the value of human developers. The interpretation of error messages and an understanding of best practices for upgrading still require a human touch to ensure meaningful outcomes.
00:13:50.520 ChatGPT was useful for pinpointing some issues but often lacked the contextual understanding needed to grasp the full scope of my queries. If a coherent upgrade strategy were formulated, any change should be grounded on my latest input. The AI tended to overlook specificity, not offering the precision needed to execute effective solutions.
00:14:12.840 Despite numerous attempts to communicate my needs, ChatGPT remained obstinate in its generic responses and didn't initiate very many clarifying questions. This limitation further complicated the upgrade process, as understanding the necessary steps often remained obscure.
00:14:34.740 Despite the issues faced, I pondered if traditional upgrades would yield significantly better results with the same challenges being presented. My overall experience led me to introspect on the future of AI in engineering. Will it evolve into a dependable partner or remain a whimsical assistant?
00:14:56.640 Toward the end of my experiments, I hoped to present my findings on how ChatGPT could be leveraged for gem upgrades and refactoring, but the results had kept me on edge. It wasn't just about having the AI as a running partner; it was about navigating unforeseen complications together.
00:15:23.640 As I wrapped up my experimentation with ChatGPT, I echoed my sentiments on its capabilities and limitations. While AI holds great promise, it currently lacks the nuanced understanding and capacity to maintain context throughout complex coding tasks.
00:15:45.060 Looking back, I remain skeptical about the extent to which AI can replace human intuition and understanding in programming, especially in the context of legacy applications. If we learned anything, it's that AI, though a powerful tool, also requires skilled human oversight.
00:16:06.720 Furthermore, I expressed a desire for ChatGPT to engage in a more iterative learning process by performing checks on my knowledge level. If it could align its interactions according to an individual's skill set, it could effectively enhance the learning process instead of merely delivering standard responses.
00:16:29.220 Ultimately, while I remain hopeful for the future of AI-enhanced development practices, I think thorough evaluation and engagement are key to making the most of these tools. I'm ready to embrace new AI assistance, but the journey will come with hurdles.
00:16:52.080 Thank you for your time. I'm open to questions, and I'd be happy to discuss my journey, insights, and challenges I faced along the way.
00:17:11.640 One of the first queries regarding my use of AI was about whether I had engaged in suggested actions to mitigate context loss by summarizing previous conversations and providing that summary in a new chat. I echoed this, mentioning, however, that the context seemed to unwind very quickly even while trying to engage the AI with an extended dialogue.
00:18:38.640 When assessing the context window used, I mentioned I kept it under 11 steps and within a four-hour window, observing the limitations when interacting with it. The discussion quickly turned toward the emotional toll of working with the various limitations presented by ChatGPT during development tasks.
00:19:11.580 As I queried whether I would be willing to repeat my experiment, I indicated a desire to take some time away before engaging in future endeavors with AI. I shared some light-hearted comments about updating my social media status to signify my openness to new AI assistant opportunities.
00:19:58.679 Considering this interaction, I emphasized the value in leveraging AI to strengthen the learning process rather than limiting it. Ultimately, I reflected on how establishing effective and mutual communication with AI could really elevate programming practices when applied with diligence and thought.
00:20:27.900 It's critical to ensure that artificial intelligence functions in a manner that encourages growth in the programming community, developing with both functionality and comprehension at the forefront of our future engagements.
00:20:49.560 Thank you again, and I look forward to your questions.
Explore all talks recorded at Ruby Warsaw Community Conference Summer Edition 2023