CyberSpy

Rantings from a guy with way too much free time

Getting func(y) with Channels

Here's a little golang puzzle Take a look at the function below that computes a mystery value for the function $f(x)$. Any idea what the function is? Take a close look at the first line where we create a channel. Notice that the channel isn't some boring int or string channel. No, this is a channel of type func(int, chan int, chan bool). Wait what??? That's right, this channel takes a function that takes an integer and two channels as function parameters. Continue reading

Once Upon a Reflection: Looking Deeper into Golang reflection

I often reflect upon my code… One of the coolest features of the Golang programming language is the reflect package. As the package documentation states at the onset of the package: Package reflect implements run-time reflection, allowing a program to manipulate objects with arbitrary types. The typical use is to take a value with static type interface{} and extract its dynamic type information by calling TypeOf, which returns a Type. Continue reading

Wanna learn you some Go? Tutor up over here!

Rob

Go Get Interfaced: Enums in Golang

Golang, Interfaces, and Enums So here's a nice golang idiom that I ran across years ago that I found generally useful. Golang, unlike languages like c doesn't natively support enumerations. Instead, constants typically are used when creating a list of enumerations. But, go is a strongly-typed language, so we can do better than simply using constants - we can type our enumeration with the use of a type declaration. type DogState uint By defining a type for our enumeration, we can consistently pass and return typed-values among our functions operating on our enumeration. Continue reading

Gogo

Here we gogo! Years ago, I wrote an interesting article that I thought might be worth re-posting (and revising) here on my blog. For a while I got into programming in golang and in the early going (pun-alert!), there were a lot of idioms that were not well understood by a noob. One of those paradigms was channels, go-routines, and signals used simultaneously. Taken separately, they are more easily understood. But when taken together, there can be some confusion. Continue reading