Using Reflection in Go to assign a Value to a Property of a Struct Contained in a Map

Clock tower reflecting on the water; St. Michaelis, Hamburg, Germany

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

Exit sign

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 …

How to explicitly declare that a struct implements an interface in Go

rules to follow

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 …

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.