Second Contribution
This is the second post in my multi-part Late Hacktober series. This post is about my second contribution to an open source project during the 2023 Hacktoberfest. Lately, I've been focused on learning and improving my C#. So, I wanted to work on a project using C# and something that was connected to game engines. Luckily I found a "good first issue" here, which is about using StringBuilder class instead of String.
String vs Stringbuilder
One of the project members had made the observation that one of the custom classes in the code base which was in charge of code generation was using the String class with += operators, and string interpolation, for string concatenation. He recommended that it is more efficient to use a StringBuilder class instead of using String, because the StringBuilder is a mutable item compared to the immutable String. This was interesting to me because first of all, I had never used the StringBuilder class and it was an opportunity to learn something new, and secondly, because it made sense to me that if the string value is not fixed and it will be constantly changing, to use a mutable class in order to avoid memory duplication. So, I went over the StringBuilder documentation to understand how it works and what methods I can use to fix this issue.
Working on the Issue
After going over the issue requirements and understanding what and where I needed to implement the fix, I asked the project owner to assign me the issue, which he happily did. Like my first contribution I forked the repo and created a new branch to work on. The implementation was not complicated at all, I just had to replace the String class with the StringBuilder, use StringBuilder methods for string concatenation and override one of the functions with a custom logic. After I implemented the logic, I tested my changes to make sure that it did not break anything in the code base and that it did what was needed. When I was satisfied that everything worked fine, I commited my changes, pushed them, and made a pull request. Afterwards, one of the project members reviewed my code, approved it, and the project owner thanked me for my contribution, and merged the code, which will be included in his next release.
What I Learned
I really liked how appreciative the project owner was of my contribution, even though it was nothing complicated or huge. This made me feel good about contributing to other people's projects, and made me want to do more contributions even after I finish college. It was also a great learning opportunity which allowed me to learn the difference between StringBuilder and String and when to use each one. I will have to go over some of my own C# personal projects and update them, to use StringBuilder instead of String where I have a mutable object.
Top comments (0)