WEEK 3: ENTRY 1

 At my internship today, I was tasked with learning Concurrency, which consists mainly of Goroutines  and Channels in the Go programming language. As mentioned in one of my previous blogs, my project would be coded in Go programming language and these two concepts are very instrumental in Go. As a result, I am currently spending time learning the language and getting familiarity with the Go codebase my team built. So what are goroutines? Unlike how the flow of processes or code lines in a conventional coding programming language like Python gets executed, goroutines are used to run different parts of the code at the same time. It is usually done with the Go keyword called go. For me, this way of writing code and calling functions  is very unfamiliar. Transitioning from Python to Go has really been a tough transition because with Python, I never had to do with running the different parts of my code base at the same time. I mostly just called the functions in the order I want the program to run. Thus, it was both a moment of awe and unfamiliarity because I used to think that all programs need to follow a sequential pattern when getting executed. This could be why most people will prefer to use Go programming rather than other programming languages because goroutines give one the avenue to execute their program in a more organized and fast way without having to worry about the fixed flow of the program. 



Another concept I learned today was Channels in Go. Perhaps, this is the most challenging Go programming concept I have come across thus far.  I have spent more than three hours trying to understand this concept. I  watched Youtube videos and read a couple of documentaries, but I am still unable to grasp it fully.  Channels are basically like pipes through which the goroutines can communicate. Sounds easy right? Well, unlike how it sounds, it is a concept that needs close look because it involves sending and receiving values, which needs to be fully understood and monitored to ensure desired results at the end. I initially went with the idea that Channels merely send and receive values. Thus, I was struck by how much more one needs to know about channels to use them well.  The basic syntax is, ch <- v, which simply means that the value of v is sent to ch. The arrow represents the direction of flow of information. But why do I find them really hard to understand if the syntax is that easy? It turns out that it involves much more than that. I am clearly lost as to why they must be defined before they are used. Also, for the channel to work, it must have a sender channel and a receiver channel. This concept baffled me at first because prior to understanding that logic, I was only creating one channel and assigning values to another variable, which never works. I realized that for a channel to work, these conditions must be satisfied: 

  1. A receiver and sender is not blocked

  2. Only a sender should close a channel, and not the receiver. 

  3. Sending on a close channel will cause a panic, which throws a deadlock error.

Overall, it was amazing to see how concurrency in Go works; however, I must say that I would have to spend another day or two to fully grasp and implement Go channels on my own. I intend to use the documentation that my manager recommended to go over this concept.





Comments

Popular posts from this blog

WEEK 4: ENTRY 3

WEEK 6: ENTRY 3

WEEK 7: ENTRY 1