Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Pull forward the declaration of the RouterConfig in main() #554

Merged
merged 2 commits into from
Apr 14, 2015

Conversation

dpw
Copy link
Contributor

@dpw dpw commented Apr 13, 2015

This eliminates a few variables, and the naming awkardness where we
have corresponding but distinct flag and router config variables.

flag.StringVar(&httpAddr, "httpaddr", fmt.Sprintf(":%d", weave.HTTPPort), "address to bind HTTP interface to (disabled if blank, absolute path indicates unix domain socket)")
flag.IntVar(&config.ConnLimit, "connlimit", 30, "connection limit (0 for unlimited)")
flag.IntVar(&config.BufSz, "bufsz", 8, "capture buffer size in MB")
flag.StringVar(&httpAddr, "httpaddr", fmt.Sprintf(":%d", weave.HTTPPort), "address to bind HTTP interface to (disabled if blank, , absolute path indicates unix domain socket)")

This comment was marked as abuse.

This comment was marked as abuse.

This eliminates a few variables, and the naming awkardness where we
have corresponding but distinct flag and router config variables.
@dpw
Copy link
Contributor Author

dpw commented Apr 13, 2015

Comma gone again.

(I notice that this page currently shows "rade commented on an outdated diff", confirming my suspicion that github can sometimes track PR comments across rebases.)

@rade
Copy link
Member

rade commented Apr 13, 2015

The treatment of BufSz is rather suspect. It would fail a type check in a type system that supported units, i.e. the type of RouterConfig.BufSz is "bytes", yet we read a "MBytes" value into it (and fix it up later). So I reckon we should leave the intermediate var in place for that one.

Overall I find this change makes the code less regular and makes it harder to figure out what the router config contains, since it gets created bit by bit. Is that outweighed by the 11 lines saved?

@dpw
Copy link
Contributor Author

dpw commented Apr 13, 2015

The treatment of BufSz is rather suspect. It would fail a type check in a type system that supported units, i.e. the type of RouterConfig.BufSz is "bytes", yet we read a "MBytes" value into it (and fix it up later). So I reckon we should leave the intermediate var in place for that one.

Go is rather far from having such a type system.

Overall I find this change makes the code less regular and makes it harder to figure out what the router config contains, since it gets created bit by bit. Is that outweighed by the 11 lines saved?

The elimination of mess such as name vs ourName and password vs pwSlice is worth it on its own. And 11 lines is 11 lines.

@rade
Copy link
Member

rade commented Apr 13, 2015

Go is rather far from having such a type system.

Right, but my point stands. There is a bad smell to setting a field value to something that is invalid and then mutating it to be valid.

The elimination of mess such as name vs ourName and password vs pwSlice is worth it on its own.

I don't actually consider that to be messy.

@dpw
Copy link
Contributor Author

dpw commented Apr 13, 2015

Go is rather far from having such a type system.

Right, but my point stands. There is a bad smell to setting a field value to something that is invalid and then mutating it to be valid.

Reintroduced with a clearer name.

@rade
Copy link
Member

rade commented Apr 13, 2015

Reintroduced with a clearer name.

Cheers. As for the overall change. I am still not convinced. Perhaps ask for a 3rd opinion?

@dpw
Copy link
Contributor Author

dpw commented Apr 13, 2015

Perhaps ask for a 3rd opinion?

@bboreham, will you arbitrate?

@bboreham
Copy link
Contributor

I like this change. Considering the way that RouterConfig gets used inside router.go, I might pull Name and NickName out and make the remaining RouterConfig a member of Router, saving another 12 lines.

rade added a commit that referenced this pull request Apr 14, 2015
Pull forward the declaration of the RouterConfig in main()
@rade rade merged commit 9b29d2e into weaveworks:master Apr 14, 2015
@dpw
Copy link
Contributor Author

dpw commented Apr 14, 2015

Considering the way that RouterConfig gets used inside router.go, I might pull Name and NickName out and make the remaining RouterConfig a member of Router, saving another 12 lines.

I did think about this, and as you mention the wrinkle is Name andNickName. I anticipated resistance to moving them out of RouterConfig to separate NewRouter parameters on the basis that it would revealing implementation details.

It would be really nice if we could introduce a RouterCommon that had the common parts of Router and RouterConfig, and make it an anonymous field of both. But this uglifies the corresponding struct literals, because anonymous fields are not magical there.

@rade rade modified the milestone: 0.10.0 Apr 18, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants