WEEK 8: ENTRY 2
Ever heard the saying “Bad programmers worry about the code. Good programmers worry about data structures and their relationships?” Well, it is very much true in my scenario at my internship today. As a new Go programmer, I was much worried about writing the code and making it work as it should. I worried less about the code structure, but my manager is very worried because my project would be used in production and if someone else is going to work on it, they shouldn’t struggle to read and understand my code. Therefore, I was tasked to refactor my code. When I say refactoring, what I exactly mean is grouping my different functions into different directories and having different Go files. Since I have multiple logic for different API calls and data manipulation, I was required to arrange these logics and API calls into different directories and files.
Although both my Elasticsearch API and BigQuery API calls used the same http client, the API responses in both cases are in different data formats. So too, the functions I wrote to make these API calls used different packages and functions to read the data from the API. As a result, I made a package directory, which has two separate directories that have Go files for both API calls. Prior to today, I used Python import statements to call other functions; however, Golang imports are quite different. Unlike python imports Golang imports require you to import the package that you use in other directories. In addition, the way we pass the return value to another function is quite different. I struggled with this because I have never done these Golang imports. Passing a function’s return value requires you to also pass in what the data type of that return value is.
I can conclude that I gained a better understanding and insights on how to pass parameters to totally different functions in a different directory. Besides, I also now appreciate the fact that I am more fluent with troubleshooting errors with Golang print statements. However, I am still slow in resolving issues when I encounter them. I intend to work on my pace and troubleshooting speed faster than I am currently doing. I plan to google the right thing and read documentation on stack-overflow answers rapidly.
Comments
Post a Comment