Learning GO with TDD
by Graciele Damasceno
In recent years, the use of Test-Driven Development (TDD) has become increasingly popular in software development. TDD is a software development process that emphasizes writing automated tests for your code before you actually write the code itself. In this blog post, I will explore my journey learning GO with TDD, and how was it to learn a new programming language as an experienced developer.
Learning GO with TDD: A Journey of Discovery
As a seasoned developer, I have come to realize the importance of writing automated tests for my code before actually writing it. Even though I still feel some resistance by inverting the “normal” process of development (more on that later), it is undeniable how writing tests before code improves the general flow of writing the logic itself. I also was eager to learn a new language in order to keep my brain fresh for new technologies beyond those used my the workplace horizon. To achieve this, I decided to learn GO with Test-Driven Development (TDD). In this blog post, I will share my journey and the insights I gained along the way.
Background: A Quick Look at GO
Before diving into the details of learning GO with TDD, let me provide a brief introduction to the programming language: GO is an open-source programming language developed by Google in 2009. It is designed to be efficient, simple, and easy to use, making it a popular choice for developing web applications and backend applications.
Why Learn GO with TDD?
There are two main reasons why I decided to learn GO with TDD:
- Improved code quality: TDD helps me write better code by forcing me to think about the tests before writing the actual code. This ensures that my code is testable and maintainable, which is especially important when working with a language like GO that has a lot of built-in functionality.
- Deeper understanding of GO: Learning GO with TDD helped me understand the language better. GO has a unique syntax and set of features compared to other programming languages, and using TDD helped me get a deeper understanding of how these features work together.
A Very Welcome Guide
To quick-start my development, I followed the amazing Leaning GO with Tests, which is an excellent resource for learning GO with TDD. The website provides a step-by-step guide that takes you through the process of learning go from the basics to more advanced topics. It was very helpful to have an outlined tutorial to follow.
Challenges and Insights
Even with a clear path ahead, learning GO with TDD was not without its challenges. Here are some of the insights I gained along the way:
- Go’s syntax: One of the biggest challenges I faced was getting used to Go’s syntax. Even having previous experience with Java and Python syntaxes (we could argue that the latter is quite similar in a sense to GO), still was a bit challenging to turn off the previous knowledge and get used to the way GO is structured. GO has a unique syntax and set of features that can take time to get used to. For example, the language uses a functional programming style, which requires a different way of thinking about code.
- TDD forces you to think about tests before writing code: One of the most significant benefits of learning GO with TDD is that it forced me to think about tests before writing code. This helped me write more robust, modular and maintainable code.
- Writing tests first helps you identify potential issues early on: By writing tests before writing the actual code, I was able to be mindful and identify potential issues early on and fix them before they became bigger problems. This saved me a significant amount of time and effort in the long run. Writing tests before code also helps ensure that my code is simple and easy to understand.
- GO’s concurrency model is unique: GO has a built-in concurrency model that allows for parallel processing. However, this can also lead to race conditions (when multiple concurrent processes or threads access and modify shared data concurrently, resulting in unexpected and unpredictable behaviour) if not handled properly. By writing tests first, is possible to identify potential race conditions early on and write code that is more robust and fault-tolerant.
- Testing design patterns: Writing tests before writing the actual code helped me write better code by forcing me to think about the tests first. This also allowed me to apply design patterns such as Dependency Injection (DI) in order to make my code loosely coupled and more robust.
- Tests first can be hard!: One personal limitation that I felt in this journey was the act of think about testing first instead of coding the solution entirely at once. It was a very conscious effort to fight the urge of creating all the logic before the tests. It felt wrong at the beginning, but think I got the grasp of it by the end, and it became easier.
- Learning new concepts: This was my first time learning TDD with GO, so it was important for me to learn the language as I went along. Learning a new programming language can be challenging at first, but it is definitely worth the effort. The benefits of learning a new language are many, including increased productivity and improved code quality.
Conclusion
Learning GO with TDD was a exciting and rewarding experience. If you are a developer looking to improve your craft, I highly recommend giving TDD a try when learning GO or any other programming language.
I hope this blog post has provided you with some insights into learning GO with TDD. If you have any questions or comments, please feel free to reach out to me on the comments below or LinkedIn. Happy coding! 🥳
References
Further Reading
If you are interested in learning more about TDD and GO, here are some additional resources:
Subscribe via RSS