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

This isn't an OO thing at all. In C, to contrast with Go, a typedef is an alias. You can use objects (general sense) of the type `int` interchangeably with something like `myId` which is created through `typedef int myId`.

That is, this is perfectly acceptable C:

  int x = 10;
  myId id = x; // no problems
In Go the equivalent would be an error because it will not, automatically, convert from one type to another just because it happens to be structurally identical. This forces you to be explicit in your conversion. So even though the type happens to be an int, an arbitrary int or other types which are structurally ints cannot be accidentally converted to a myId unless you somehow include an explicit but unintended conversion.


Thank you for answer :)

This helped me! Especially because you started with typedef from C. Therefore I could relate. Others just downvote and don't explain.




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

Search: