Closed ktoso closed 4 years ago
WDYT, @lukasa - opinions on keeping init() public so there'd be 3 ways of making a context -- empty, init, TODO() or should we drop the empty? I kind of felt the empty makes it more explicit in the code which is helpful;
Go call it "background" explicitly which is useful since it explains "well, you're a background task, you clearly dont have a context so just make that background one" which is also useful.
I'd like to stick to 2 ways to create one if possible, open to opinions.
I think having a .empty
is good. Normally I’m opposed to that pattern over just having a zero-argument initializer, but in this case I actually think the reason I don’t like it is why it’s good. You should have to think about where you’re gonna get a context from, and explicitly ask for a new one if you don’t have one. I think background
is an even better name, but I’m not so worried about that right now.
You should have to think about where you’re gonna get a context from, and explicitly ask for a new one if you don’t have one.
Yeah exactly, this is to make this intentionally stand out and bit a bit ugly, and the TODO even being documenting why you're not doing the right thing etc.
I'm also liking background to be honest, but wonder if people would be ok with it. The goal is exactly that: to make it "weird and looks wrong" in normal apps - because they should not create those but keep passing along, so the background seems just weird enough to raise questions. The empty can still fly under the radar, but at least is explicit.
Let's ping some more folks: @tanner0101 @slashmo @adam-fowler @pokryfka @tachyonics
Options are IMO:
a)
.empty
TODO(_ reason: String)
b)
.background
TODO(_ reason: String)
Please see https://golang.org/pkg/context/ as well as the docs in this PR for rationale. Thanks for chiming in 👍
The goal is exactly that: to make it "weird and looks wrong" in normal apps - because they should not create those but keep passing along, so the background seems just weird enough to raise questions. @ktoso
Because of what you describe here, I prefer to go with .background
& .TODO
. .empty
, in my opinion, is too easy to overlook, but if one sees .background
they might be more inclined to think about why it's there.
I made TODO less annoying by not requiring a reason, static analysis or crashing may be good enough for many users.
Resolves #26 - Semantically helpfully named empty baggage factory functions
I went with:
.empty
and good docs when it should be usedTODO
inspired by https://golang.org/pkg/context/ which is quite useful I believe, and good for future linters and tooling potential