-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
proposal: spec: support ... TODO statement #35386
Comments
Would it be possible to provide an example, sorry? |
type R struct {}
func (r *R) Read(p []byte) (n int, err error) { ... } |
You'd have to make sure 'go vet' allowed it and 'cmd/vet' didn't, which is weird. |
Not sure I follow. The point is to make |
If I admire the desire for a way to block out stuff for now, but I don't want that to preclude me testing other parts of the code. |
One way to look at We already do this in array literals; e.g., in Generalizing this idea, Furthermore, var m map[string]float64
m = make(...) // make a map of m's type See also #34515.
With this general interpretation, It could allow us to compile/type-check incomplete pseudo code as it might be used in a presentation. It would also be quite useful when rapidly developing a new piece of code (where I currently stub out missing pieces with I'm not convinced this is a good idea yet, but it seems as if it could be reasonably generalized, it's relatively simple, and has interesting use cases. It seems intriguing, especially if the use cases read naturally and almost explain themselves. Q: Would |
@griesemer yesterday I started a blog post about the meaning of _ and ... in Go, and how we should think about them in proposed language changes. You have just scooped most of the post, and better than me. :) Want to do _ next? One additional piece is an observation from Rog that _ is an identifier and ... isn’t, which has implications for what proposals involve syntax changes. Another observation is that ... clearly means “do what I mean”/“fill this in for me” for array lengths, but less obviously so for variadic function signatures or call sites. |
If the compiler could not fill in an obvious statement, I’d expect compilation to fail, not a runtime panic. |
I also develop by running go test as I wrote. But go test can return multiple failures at once: I can watch my tests start to pass, while also getting a vet failure. |
If |
@bradfitz What's the advantage of using You propose that |
That's basically it. This came out of a conversation about how Go uses |
While the idea is intriguing, I think that |
This use of It also doesn't feel especially in tune with a language that doesn't allow you to have an unused variable. If it is a good idea to have something like this, I'd prefer a builtin like @griesemer as far as |
Kotlin has a TODO() function in its standard library so that would be another option, though I'm not sure what package to put it in. To be honest though I can't see what's wrong with |
Wandering off into semantics, I don't think it's exactly "fill in the logical thing". It's more like just "fill it in". If there's no logical thing to fill in, a Schelling point also works. That said, I'm also in the "just use |
Well, the same way Kotlin has it, we can probably just add a library function That said, I do like the @griesemer proposal though about "..." being equivalent to "fill the dots" for the compiler
because typing that stuff in obvious places is not fun. (sorry, my 2¢ to repaint the bike shed) |
This is interesting thing, todo() looks great. |
I'll retract this proposal. It was mostly there for completeness. I've labeled all these issues with the |
From a discussion with @griesemer and @ianlancetaylor, who have different opinions on this:
We could make Go support a
...
statement that compiles but fails at runtime, as if you wrote, say,panic("TODO")
.Like https://docs.perl6.org/routine/....html
So sample code in space-constrained slides can say
func (m *Method) Foo() { ... }
and be valid, but mostly so work-in-progress code during development compiles with...
, instead of having to writepanic("TODO")
.cmd/vet
could perhaps fail if any exist in your program, to limit its spread (and prevent it from getting checked in).It'd be a terminating statement.
In Perl6/Raku, it has to be the only statement in a block it seems.
The text was updated successfully, but these errors were encountered: