Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid (and remove) constructors which does nothing and has confusing formatting #129

Open
gdiazlo opened this issue May 29, 2019 · 0 comments

Comments

@gdiazlo
Copy link
Contributor

gdiazlo commented May 29, 2019

We have a lot of constructors like:

package foo

func NewT(p1, p2, p3.....pN) *T {
    return &T{
           p1, 
           p2, 
           p3,
           ...,
          pN}
}

I think those constructors are useless and need to be removed. Only if the constructor does actually something, like calling make() or call other New() for its embedded types, should be preserved.

Also, on constructors, there is no need to repeat the parameters with huge names:

func New( myParameterTypedName TypedType, ....) T {
    return &T{
        myParameterTypedName: myParameterTypedName, 
        .....
    }

Could become

func New( p TypedType, ....) T {
    return &T{
        myParameterTypedName: p, 
        .....
    }

Last, I would love to avoid the form:

package foo

func NewT(
    p1, 
    p2, 
    p3,
    ...,
    pN) *T {
    return &T{
           p1, 
           p2, 
           p3,
           ...,
          pN}
}

It is confusing to see what is the struct and what is not. The point of that format is just to accommodate long parameter names which are never used outside the function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant