mdlayher / vsock

Package vsock provides access to Linux VM sockets (AF_VSOCK) for communication between a hypervisor and its virtual machines. MIT Licensed.
MIT License
336 stars 65 forks source link

Simplify working with code #39

Closed wade-welles closed 4 years ago

wade-welles commented 4 years ago

Maybe you know this or not but when you have a single attribute object, if you take out the name of the attribute it becomes easier to interact with and makes the code quite a bit more expressive.

For Example:

type Listener struct {  
      *listener           
 }      

You can see I removed the "l" name to the listener attribute, but its because it makes the rest of the code capable of being simpler to interact with and a bit less redundant.

func (listener *Listener) Accept() (net.Conn, error) {
      c, err := listener.Accept()  
      if err != nil {     
          return nil, self.opError(opAccept, err)
      }                   

       return c, nil       
   }         

So as you can see here, now I can just do listner.Accept() and it works just the same as before, this is opposed to your version where it is l.l.Accept(), or if you used the full variable name it would have been listener.l.Accept().

It is not a massive difference but this type of simplicity can be used throughout the codebase and make everything a bit easier to use.

If you are interested in making this change I can issue a pull request as I'm rebuilding the library, adding more functionality, including memory FD for faster connections.

You are a great coder, love reading your work, and you have done a lot of useful projects for me. Like your fibre library made it easy for me to build my own modem and get rid of my proprietary fiber optic modem :D Thanks

mdlayher commented 4 years ago

Thanks for reaching out and I'm glad you enjoy my work.

Embedding adds a lot of cognitive overhead at the cost of saving a few keystrokes. It suddenly becomes possible for methods to be promoted to the top-level type, possibly exposing internal details as public API. In Go, we often prefer to keep things simple, even at the cost of a few extra keystrokes.

In conclusion, I am not interested in making this particular change. If you have other improvements you'd like to make, please do open an issue before starting work so we can make sure it lines up with the goals of the project. Thanks for your time.