Languages Are Beautiful
Anne Neuberger is Special Assistant to NSA Director Michael Rogers and also the Director of the NSA’s Commercial Solutions Center.
The NSA, Neuberger said, has suffered a particularly “long and challenging year” dealing with the public loss of trust following the Snowden revelations. The agency is reviewing all of its activities to determine how to regain that trust. One change is more open engagement with the public. “This presentation is a starting point.”
Astronomers have discovered that much of the water on Earth—and the solar system—predates the Sun.
This isn’t really surprising, right? I mean, it lines right up with the Genesis creation. Still, thinking about things like this blows my mind.
1 In the beginning God created the heaven and the earth. 2 And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters. 3 And God said, Let there be light: and there was light. 1
A parenthetical statement that is a complete sentence should begin with a capital.
I used to debate this everytime I’d use i.e. or e.g. in my writing. Not anymore!
Right way:
E.g., this is a proper example.
I.e., something like this is correct.
Wrong way: 1
e.g., This is a bad example.
Apparently it is also good practice to include the comma.
Sadly this is how I’ve usually written it, except I almost always left off the comma. ↩︎
Welcome to my new blog! 1 All of my blogging in the past has been in the form of longer articles, mostly technology related, and mostly trying to teach a tip or trick.
I’m taking a different approach this time. I’ll be posting more random thoughts. Sharing articles I find interesting. Overall I expect this to feel more like reading my Facebook wall and that’s what I’m going for. 2
Here goes nothing!
One of the first things you’ll notice in Go is that two different types are commonly used for representing text. string and []byte. A quick example is the regexp package which has functions for both string and []byte.
string is immutable and []byte is mutable. Both can contain arbitrary bytes.
The name “string” implies unicode text but this is not enforced. Operating on string is like operating on []byte. You are working with bytes not characters.
Methods can be declared on both pointers and values. The difference is subtle but important.
type Person struct {
age int
}
// Method's receiver is the value, `Person`.
func (p Person) Age() int {
return p.age
}
// Method's receiver is a pointer, `*Person`.
func (p *Person) SetAge(age int) {
p.age = age
}
In reality, you’d only define getter and setter functions like this if you needed to implement additional logic. In an example like this you’d just make the
Agefield public.
Go doesn’t have constructors in the traditional sense. The convention is to make the zero value useful whenever possible.
type Person struct {
Age int
}
// These are equivalent.
// `p1` and `p2` are initialized to the zero value of Person.
// Neither of these are nil.
var p1 Person // type Person
p2 := Person{} // type Person
// You could also use `new` to allocate which returns a pointer
p3 := new(Person) // type *Person
It is most common to use the struct initializer. e.g.
p := Person{}orp := &Person{}if you need the pointer.
I’ve been working with Go on personal projects for several months. During that time, Go’s intended strategy for package management and versioning has largely eluded me. My understanding really started to come together over the past week which is why I wrote about my Go Project Structure and now am writing about package versioning.
My goal with this post is to help others who, like myself, have had a hard time reconciling Go’s approach to package dependencies and versioning with that of other languages.
Go is build around the concept of a GOPATH which is a common workspace for most (or all) of your Go source code. This works well but sometimes you don’t want the third party packages you depend on to be in your primary GOPATH. I can think of a few reasons for this:
• You have multiple Go apps and each depend on different versions of the same third party package. Ideally these packages would use a versioned URL so that the import paths are different but this isn’t always the case. (See http://gopkg.in, a great tool for package authors to use for providing versioned URLs.)