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 Packages, variables, and functions and Flow control statements: for, if, else, switch and defer in the Basics section of The Go Tour.
The things that stood out most for me were that Go, technically, only has one looping construct, 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 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:
1
2
3
4
5
6
7
8
switch($someValue)
{
case(1):
case(2):
case(3):
// ... take some action
break;
}
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 the Go Blog, for an introduction to them.
See you next time!
Join the discussion
comments powered by Disqus