Hacker Newsnew | past | comments | ask | show | jobs | submit | django1993's commentslogin

A startup that keeps eating more and more money like a blackhole without emitting a single penny of profit.


I would also recommend reading Computer Systems: A Programmer's Perspective, 3rd Edition.


Indeed! It's my favorite technical book, several of the chapters have information I've yet to find laid out in comparable detail anywhere online.

The book was written for a CS course (15-213) at Carnegie Mellon University, course materials here (supplement, but no replacement for the book): https://www.cs.cmu.edu/~213/


+1 for OSTEP


The name of the blog is 'writepay', which should give a hint.


Maybe because structs have some fields private and some public. To add a method outside the package would be to make those private fields visible in the method outside the package which then allows such methods to manipulate the struct and that will break the abstraction provided by it.


> ... would be to make those private fields visible in the method outside the package.

Since you write the implementation of the method inside your struct's package, you have the right to manipulate private data there as you would do with any function. I don't understand the problem.


I think the problem they wanted to avoid is incompatibility (Go cares much about compatibility, see Go 1’s Promise of Compatibility[1]). Private fields mean to external packages “This is non of your business. The field can change or be removed at any time without notice.”.

If external packages could add methods to a struct, thus turning private fields into effectively-public fields, the whole struct (all its fields) potentially becomes public. How do you maintain a package if your defined API (public fields/methods) is ignored and instead everything is made available to external packages? To keep compatibility, you could never refactor the package, instead you have to keep all private fields to not break external packages that use them.

[1] https://golang.org/doc/go1compat


You could just let the external methods only access public variables. That's exactly what Java let's you do when you extend another class. I agree that private members should stay private.

I wish I could add methods from outside of my package. I currently run into cyclical dependency issues when I try and define something like...

func (g Game) GetPlayers() []Player { ... }

func (p Player) GetGame() Game { ... }

While having Game and Player in separate packages. It's not the end of the world having them in the same package, but the amount of methods does pile up...


There is no need to bring private fields too. Just keep the same visibility rules. The new method would be written inside a user package which would have access only to the public members of the type being dispatched on. That mean that you could only define methods for external structs that make use of their public API.


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

Search: