Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Sometimes you just want to JSON-encode a []struct{<ad hoc stuff>} or something like that, so it’s entirely reasonable to use a func-local named type rather than repeating the anonymous struct.

And to gp: if your func local type ends up observable and even testable, of course it shouldn’t be func local. Otherwise you’re describing testing implementation rather than behavior, indicating you’re writing bad tests.



"Otherwise you’re describing testing implementation rather than behavior, indicating you’re writing bad tests."

Yeah, people have been threatening me for decades with the claim that if I write tests to test internals I'll have to refactor like crazy someday. I'm still waiting for someday to come. Meanwhile, it has caught a lot of bugs.

I'm open to the possibility that there's something different about the way I write code that causes me to not have this problem. Stay tuned to my blog over the next couple of months if that intrigues you. In the meantime, as reality fails to correspond to theory, I go with reality.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: