This solution had me literally working on-again off-again for a full week. One of the main reasons it took so long was I was trying to write a wrapper to simplify because I find the reflect package in Go so unintuitive and hard-to-work-with. But it turns out that trying to write a wrapper around an …
A better alternative to “return early” – PHP / WordPress edition
Yes, complex conditionals are worse. But there is a third, better way. And no, it does not involve GOTOs. Me This post is about a coding pattern I have never seen used by anyone else for writing guard clauses, especially when those guard clauses are complex. This pattern results in code that is significantly more …
Continue reading “A better alternative to “return early” – PHP / WordPress edition”
Pros and cons of leveraging Go types
Go is a great language — probably one of the best — but it is not without its warts. Let me illustrate one aspect of Go that is really useful, but also one of the issues that using that feature causes (aka an experience report.) Pro One of the many great features in Go is …
On Typing Strings in Go
One of the niftier aspects of programming in Go is you can create named types derived out of existing types. For example, let’s consider storing and passing a URL. Depending on their needs programmers get to choose either a string or a class to represent URLs in many others languages. Often times programmers will choose …
How to explicitly declare that a struct implements an interface in Go
One of the things I love about Go and find to be a strong supporter of serendipitous interface standardization is Go’s implicitly declared interfaces. However, there are times you really, really want to explicitly declare an interface, such as when you have a larger interface and you want your IDE and/or the compiler to tell …
Continue reading “How to explicitly declare that a struct implements an interface in Go”
How to specify a zeroed UUID in MySQL
Photo by Chris Barbalis on Unsplash Working on a recent project that dealt with data synchronization across disparate systems, I realized I could not use the oh-so-easy INT for primary keys. Instead I chose to use the emerging best practice of employing UUIDs for distributed databases. However, the library functions in Go are not friendly …
PHP delegation vs. GoLang type embedding
PHP implements composition (vs. inheritance) of object class properties and methods to other classes using delegation. Go on the other hand implements composition with type embedding. Read this post to learn about the differences and to appreciate the benefits of Go’s approach compared to that of PHP.