Hacker News new | ask | show | jobs
by Sakos 867 days ago
The countless bugs I've had to deal with and all the time I've lost fixing these bugs caused by people who forgot to validate data in a certain place or didn't realize they had to do so proves to me that the overhead of calling a get on a wrapper type is totally worth it.

I value the hours wasted on diagnosing a bug far more than the extra keystrokes and couple of seconds required to avoid it in the first place.

1 comments

No, you’ve achieved an illusion of that as now your spending hours wasted on discovering where a developer forgot to call NewUsername and instead called Username{“broken”}. I cant see the value in this abstraction in Go.
They can’t because value is not exported. They must use the NewUsername function, which forces the validation.

In my opinion, this pattern breaks when the validation must return an error and everything becomes very verbose.

Oh, thats true about it being unexported. I hadn’t considered that.