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 …
Adding Delegation to PHP
In summary I am proposing the PHP leverage the use
statement like the PHP trait
does, but with a class
modifier to allow for automatic delegation of method calls to contained instances.
Also I am proposing we leverage the disambiguation syntax that is already available for traits, and extend it in a few ways that traits do not address such as:
- Use
as
to allow for renaming from the property names for delegate classes, - Add
include
orexclude
to allow including or excluding specific methods, and - Add
use method
to allow for including specific methods.
Pros and cons of leveraging Go types
UPDATE: Since writing these over 3 years ago I have since learned a lot more about GoLang and its type system. Ironically, I now realize that GoLang has type aliases that are effectively what I was lobbying for. ORIGINAL POST: Go is a great language — probably one of the best — but it is …
On Typing Strings in Go
UPDATE: Since writing these over 3 years ago I have since learned a lot more about GoLang and its type system. As such I now realize that GoLang has type aliases to address the need that I was writing an experience report about. ORIGINAL POST: One of the niftier aspects of programming in Go is …
Go’s unfortunate err != nil idiom
All-in-all, I am a big proponent of the errors-as-values approach to error handling in Go. I definitely agree with the general wisdom of handling errors when and where they occur, and not delegating them using exceptions. So this post is not about how many people find needed to handle errors through code an annoyance. To …
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”
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.
Proposal: Contracts in Go (Not Generics)
Photo by Cytonn Photography on Unsplash #Update When I wrote this I did not remember that the draft design for Go2 generics chose to use the name “Contracts” for a new language feature to provide a Go-idiomatic response to generics. Still, I stand by my use of the name contracts for this proposal as I …
GoLang Strict Typing and Interface Slices
Photo by Louise Lyshøj on Unsplash This is a GoLang Experience Report. …but you cannot define the rows parameter as type []RowInserter because []interface{} won’t match it, even though RowInserter is itself an interface. Background I am relatively new to programming Go, but I have been developing software professionally in a variety of programming languages …
Continue reading “GoLang Strict Typing and Interface Slices”