2 ms·
Doesn't this come off a bit as overkill? Especially adding the comparison interfaces. In F# you'd do something like: type TypeId = TypeId of int with
by MichaelGG 13y ago
Doesn't this come off a bit as overkill? Especially adding the comparison interfaces. In F# you'd do something like:
type TypeId = TypeId of int
with
static member Gold = TypeId 1
Custom is now just "TypeId 123". Otherwise, TypeId.Gold. (This is assuming you don't want to specify the cases directly as union cases).
You can also abstract this to a general phantom type like "type Id<'a> = Id of int". Now functions can ask for an Id<'a> for arbitrary types. Sort of like a poor version of the units-of-measurement.
This article's kind of boilerplate OO stuff seems like it's out of control. Over the past week, I've been using open source clients in .NET to connect to social media services. And a common thread is to write oh-so-much code and provide tons of types just to get a simple job done.
One Twitter client lib requires 7 binaries. Types are split across around 50 namespaces. And of course, every type has its own file.