Michael Sauter is a German web developer at SitePoint. He's maintaining the backend of the various SitePoint sites and works on new features and products. Usually working with Ruby or PHP - currently interested in Go and Docker.

Michael's articles

  1. A Closer Look At Functions in Go

    Functions are one of the basic building blocks of any programming language. However, the feature set and role they play differ quite a lot from language to language. In this article, we’ll have a look at what Go has to offer when it comes to functions. We are going to discover that functions are first-class citizens in Go and provide the developer a very rich feature set – with some interesting details that are not apparent at first. Let’s get started by covering the basics.

    Arguments

    A function in Go can take any number of typed arguments. All arguments are required, as there is no concept of optional arguments. Important to know as well is that arguments are not passed by reference, but copied into the function (with a few notable exceptions which we’ll get to shortly). This means that if the argument is modified inside the function, it won’t have any effect on the original value. The only way to circumvent this is to pass a pointer to the function. If you’re coming from dynamic languages like PHP, Ruby or JavaScript, then the concept of pointers might not be familiar to you. However, you would have used pointers implicitly as these languages pass (some) arguments by reference. The basic concept of a pointer is easy: when you declare a variable in your program, it lives at some location in memory. Pointers simply contain the address of that location (they “point” to the variable). That means that through a pointer, you can get the actual value and modify it.

    Now, back to functions. As mentioned earlier, most arguments are copied into functions. If a pointer is copied, it still points to the same address in memory, so you can modify the value. A simple example:

  2. A Closer Look at Go Interfaces

    Ever heard of “The best interface is no interface”? While that may be true for product design, it certainly isn’t when it comes to programming Go. On the contrary, it’s probably better to follow the principle “err on the side of too many interfaces”. Why? In this article, we’ll look at what interfaces are, how they are implemented in Go and why they are so useful. Let’s dive right in!

    What are interfaces?

    Generally speaking, an interface defines the behavior of an object and therefore how this object can be used by other parts of the system. The interface describes what can be done by the object, but not how the object actually caries out the instructions. As a consequence, the implementation of the object can be exchanged without breaking functionality for the consumer.

    In languages like PHP or Java, interfaces specify which methods a class must implement, and in turn each class declares which interfaces it implements. Many classes can implement the same interface, and the system can then operate on the interfaces instead of the implementation.

    Interfaces in Go

    In Go, interfaces have the same purpose, but there are a few differences to traditional languages which make interfaces much more useful and versatile. So, what are interfaces in Go? Firstly, an interface in Go is simply defined as a set of methods. For example, the Reader interface from the standard library looks like this:

  3. Redesigning SitePoint: Caching & Speed

    This entry is part 4 of 4 in the series Redesigning SitePoint

    This entry is part 4 of 4 in the series Redesigning SitePointOne of the objectives for developers of the new SitePoint website was to make it fast. Really fast. Before we dive into what we did, I want to show you where we’re coming from: Time to first byte: ~3 seconds Document complete: 6-9 seconds […]

  4. WordPress Multi-Environment: Setting Up SitePoint

    This entry is part 3 of 4 in the series Redesigning SitePoint

    This entry is part 3 of 4 in the series Redesigning SitePointIf you’ve ever set up WordPress, you know that it’s super easy and fast to install. However, if you’ve ever tried to set up WordPress on multiple servers, deploying automatically from a repository or running on different environments, you know that these kind of […]