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

I'm not familiar with Go. Please correct me, but this reads like object oriented programming i.e. OOP for every kind of data?

Coming from C++, this kind of types with classes make sense. But also are a maintenance task with further issues, were often proper variable naming matters. Likely a good balance is the key.



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: