Learning Golang. Day 4

Learning Golang. Day 4

Here I am at day 4. Today, I learned about the range function and started the slices exercise…​but got stuck.

Today’s session felt like a pretty short one. It wasn’t. It was the same length as the previous 3 sessions. However, it was almost wholly spent doing the slices exercise.

I’m trying not to be hard on myself for finishing the exercise and taking a while to appreciate the exercise’s requirements. I misunderstood them the first few times, so kept re-reading the instructions until they sunk in. It’s odd, but at times like this, I crazily expect myself to understand things straightaway, and am not always patient while learning a new domain of knowledge.

After I felt comfortable that I knew what was being asked, using Goland (my, current, favourite Go IDE) I started playing around with some ideas for a solution. I skipped backward and forward throughout the tour to find the various functions and language elements that had been covered up to this point, and tried to stick just to those. I wrote up a small solution for the Pic function and checked that it worked. It did, but when it came time to run it, the code failed.

It took me quite a while to appreciate what was going on, that being that pic.Show takes a function, not the result of a function, which is what I was passing to it. By the time I realised this, my Pomodoro timer was down to 35 seconds.

I kept looking and looking at the code, hoping to have a lightbulb moment so that I could finish up the implementation before the time was up. Alas, it didn’t happen.

As often happens with me, when I get stuck on something, I didn’t let it go and pushed on for a minute or two longer. I know that I said I’d stick to the 30-minute time limit. But I didn’t want to, today. I felt that I was, potentially, on the cusp of getting the concept at hand, so felt it was worth working just a bit longer.

I looked at the source of pic.Show and finally appreciated why the code wasn’t working; that Pic function is called inside pic.Show, where it is passed two integers. Given that, hopefully in the next time session, I’ll be able to finish up my implementation of Pic and move on with the Go tour.

See you next time!

You might also be interested in these tutorials too...

Learning Golang. Day 5
Fri, May 13, 2022

Learning Golang. Day 5

Here we are on day 5 – the end of the first week. Today, I solved the Slices exercise!

Want more tutorials like this?

If so, enter your email address in the field below and click subscribe.

You can unsubscribe at any time by clicking the link in the footer of the emails you'll receive. Here's my privacy policy, if you'd like to know more. I use Mailchimp to send emails. You can learn more about their privacy practices here.

Join the discussion

comments powered by Disqus