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

Yeah, you can, but then you need to expose those fields for a whole bunch of similar types. If I took that approach, I'd use generated code to reduce the repetition, and still in the same boat -- I'm either generating the functions for each type, or generating the getters/setters for each type.

Rust is the same I think, where you'd need to have methods that explicitly implement the trait (interface in Go). However, Rust has a built-in code generation tool (macros), and you can decorate your structs to have it automatically implement some traits for you. That's the equivalent of adding one more entry to your Go generated code loop, except that it's right next to the struct.

If Go did support field methods (which it looks like they may one day), that might be the tipping point for me for disabling a bunch of generated code. Not sure if there's other things getting in my way, because I gave up once I noticed I couldn't do that.



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

Search: