Learning Golang. Day 1
For the longest time, I’ve been meaning to learn another software development language in-depth, in addition to my primary development language, PHP. I’ve decided that the language is Go.
Today was a slightly slower day for learning Go than was yesterday. However, I learned about flow control statements, and defer, panic, and recover.
:idseparator: - :idprefix: :experimental: :source-highlighter: rouge :rouge-style: pastie :imagesdir: /images :source-linenums-option: on :tip-caption: 💡
It was slower largely because I didn’t get as much sleep last night, so I was far more awake yesterday when I started learning Go. That said, today, I finished the https://go.dev/tour/basics[Packages, variables, and functions] and https://go.dev/tour/flowcontrol[Flow control statements: for, if, else, switch and defer] in the Basics section of https://go.dev/tour/list[The Go Tour].
The things that stood out most for me were that Go, technically, only has one looping construct, https://gobyexample.com/for[the for loop]. However, because some of its components are optional, it can function as several, different looping constructs, such as the while loop in C, Java, & PHP.
Secondly, the break
statement isn’t required in https://gobyexample.com/switch[switch statements].
This might take me a bit of getting used to, as I’m used to being able to write switch
statements in PHP that pack one case up against another as a way of checking multiple conditions.
For example:
That said, I don’t see this being an issue, rather just something that I need to get used to.
The language aspects that really grabbed my attention are defer, panic, and recover. Of these three, defer makes the most sense. It’s fascinating how you can set up a function to execute after the surrounding functions return. I see clear advantages in cleaning up resource handles using it.
For panic and recover, I’ll need a bit more time to fully appreciate them. Check out this article on https://go.dev/blog/defer-panic-and-recover[the Go Blog], for an introduction to them.
See you link:/learning-golang/day-3/[next time!]
For the longest time, I’ve been meaning to learn another software development language in-depth, in addition to my primary development language, PHP. I’ve decided that the language is Go.
Today, on day 14, I created a custom method to remove code duplication creeping into the weather station codebase. Come read the fun story behind getting that done.
Here we are on day 13. Today, I continued learning Golang by working on the Golang version of my PHP/Python weather station, adding a function to render static pages. Let me share my learnings with you.
Here we are on day 12. I didn’t solve anything. I’m feeling that these exercises are becoming arbitrary and pointless.
Please consider buying me a coffee. It really helps me to keep producing new tutorials.
Join the discussion
comments powered by Disqus