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

When you create a struct with another embedded struct (possibly from other package):

   type Foo struct {
      somepackage.Bar
      URL string
   }
you don't want to depend on whether Bar already have URL. Your depth level has higher priority.

Even more, imagine in the future authors of `somepackage` decided to add URL to their struct and it suddendly started to break your code from being compiled.

Example in the OP article is a corner case where this behavior is creating ambiguity, indeed. Yet, it's documented and intentional.



Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

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

Search: