8000 Eliminate dot imports by awh · Pull Request #2002 · weaveworks/weave · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jun 20, 2024. It is now read-only.

Eliminate dot imports #2002

Closed
wants to merge 1 commit into from
Closed

Eliminate dot imports #2002

wants to merge 1 commit into from

Conversation

awh
Copy link
Contributor
@awh awh commented Feb 25, 2016

They're bad, m'kay?

cc @peterbourgon

@awh awh added this to the 1.5.0 milestone Feb 25, 2016
@rade
Copy link
Member
rade commented Feb 25, 2016

Why not a few strategically placed

var Log = common.Log

instead?

@peterbourgon
Copy link
Contributor

Why pollute the global namespace with a variable and introduce an additional layer of indirection just to save a few keystrokes?

@rade
Copy link
Member
rade commented Feb 25, 2016

those keystrokes you are saving are adding noise for the reader, i.e. it's not about writing less but reading less.

@peterbourgon
Copy link
Contributor

They don't add noise, rather explicitness. The goal is to minimize ambiguity, not quantity of characters, and common.Log is strictly less ambiguous than Log.

@rade
Copy link
Member
rade commented Feb 25, 2016

Log is not ambiguous. Otherwise it wouldn't compile :)

@rade
Copy link
Member
rade commented Feb 25, 2016

overall, may I ask what problem we are trying to solve here?

@peterbourgon
Copy link
Contributor

Except for this one case, do not use import . in your programs. It makes the programs much harder to read because it is unclear whether a name like Quux is a top-level identifier in the current package or in an imported package.

https://github.com/golang/go/wiki/CodeReviewComments#import-dot

@rade
Copy link
Member
rade commented Feb 25, 2016

And has anybody actually run into this problem when reading the weave code?

@peterbourgon
Copy link
Contributor

I have.

@rade
Copy link
Member
rade commented Feb 25, 2016

So you read the weave code, came across a statement like

Log.Println("Our name is", router.Ourself)

and wondered "Where does Log come from?". Then what happened?

@bboreham
Copy link
Contributor

common is a poor name.

log.Log.Infof is more explanatory, but stutters a bit. We could repeat all the entry points in a weave/log package, to avoid that.

For those bits of code that are really libraries, it might be better to pass in a logger reference on startup, then the caller has control.

@bboreham bboreham modified the milestones: 1.5.1, 1.5.0 Mar 1, 2016
@awh awh force-pushed the eliminate-dot-imports branch from 64b48aa to 28ff34e Compare March 2, 2016 10:29
@awh
Copy link
Contributor Author
awh commented Mar 2, 2016

I wanted to force the issue of refactoring common by making its use glaringly obvious - can the consequent improvements go in separate PRs?

@awh awh force-pushed the eliminate-dot-imports branch 2 times, most recently from d77d633 to 0d6d148 Compare March 8, 2016 13:20
@awh
Copy link
Contributor Author
awh commented Mar 8, 2016

@bboreham is there a reason we can't just merge this now? It's a strict refactoring...

@bboreham
Copy link
Contributor
bboreham commented Mar 8, 2016

Because it makes the code strictly more ugly.

@rade
Copy link
Member
rade commented Mar 8, 2016

it makes the code strictly more ugly

I was hoping that #2002 (comment) might be an acceptable compromise.

@awh
Copy link
Contributor Author
awh commented Mar 8, 2016

Because it makes the code strictly more ugly.

#2002 (comment)

My point being that it makes it more ugly on purpose. Further refactorings become easier once everything is fully qualified.

@awh awh force-pushed the eliminate-dot-imports branch from 0d6d148 to e0305b4 Compare March 16, 2016 15:56
@rade rade modified the milestones: n/a, 1.5.1 Mar 20, 2016
@rade
Copy link
Member
rade commented Mar 20, 2016

I have eliminated the bulk of dot imports.

The remainder will be removed with #2074.

-> closing.

@rade rade closed this Mar 20, 2016
@awh awh deleted the eliminate-dot-imports branch March 21, 2016 10:38
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.

4 participants
0