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

proposal: Go 2: watch variable changes #68165

Closed
2 of 4 tasks
xingzhao0401 opened this issue Jun 25, 2024 · 3 comments
Closed
2 of 4 tasks

proposal: Go 2: watch variable changes #68165

xingzhao0401 opened this issue Jun 25, 2024 · 3 comments
Labels
LanguageChange Suggested changes to the Go language Proposal v2 A language change or incompatible library change
Milestone

Comments

@xingzhao0401
Copy link

Go Programming Experience

Intermediate

Other Languages Experience

c/c++

Related Idea

  • Has this idea, or one like it, been proposed before?
  • Does this affect error handling?
  • Is this about generics?
  • Is this change backward compatible? Breaking the Go 1 compatibility guarantee is a large cost and requires a large benefit

Has this idea, or one like it, been proposed before?

No

Does this affect error handling?

No

Is this about generics?

No

Proposal

Recently debugging a logic more complex data processing related code,the large amount of data and complex structure make it difficult to debug breakpoints
If possible,propose to add a new feature:
Add a new keyword 'watch'(or '@','#','$'...), when the variable value specified by 'watch' changes, a code segment is automatically executed,work with the breakpoints or 'runtime.Stack' to locate specific code locations where particular data appears.
This can facilitate debugging of some logically complex code, or list outliers in advance when writing code, and find problems in time during writing.
for example:

type Data struct{
	Age int
}
func F1(d *Data){
	d.Age = -1
}
func F2(d *Data){
	d.Age = 201
}
func aaa () error {
	data := Data{}
	watch data.Age {
		if data.Age < 0 {
		    fmt.Println(stack())
		    return errors.New(fmt.Sprint("unexpected value",data.Age))
		}
		if data.Age == 201 {
		    fmt.Println(stack())
		}
		....
	}
	data.Age = 2
	......
	data.F1(&data)
	......
	data.F2(&data)
	......
	return nil
}

for frequent data changes, this new feature may only be suitable for code development、BUG debugging and other scenarios;
but it seems to handle errors pretty well, although I like 'if err != nil' very much
for example:

func bbb() (interface{}, error){
	var err error
	watch err {
		if err != nil {
			fmt.Println(err)
			return nil,err
		}
	}

	err = func1()
        ...
	err = func2()
	...

	return 111,err
}

Language Spec Changes

No response

Informal Change

No response

Is this change backward compatible?

Yes

Orthogonality: How does this change interact or overlap with existing features?

No response

Would this change make Go easier or harder to learn, and why?

No response

Cost Description

No response

Changes to Go ToolChain

No response

Performance Costs

No response

Prototype

No response

@xingzhao0401 xingzhao0401 added LanguageChange Suggested changes to the Go language Proposal v2 A language change or incompatible library change labels Jun 25, 2024
@gopherbot gopherbot added this to the Proposal milestone Jun 25, 2024
@gabyhelp
Copy link

Similar Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@dominikh
Copy link
Member

This seems like functionality that belongs in a debugger, not the language. In fact, Delve already supports watchpoints.

@xingzhao0401
Copy link
Author

This seems like functionality that belongs in a debugger, not the language. In fact, Delve already supports watchpoints.

Thinks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LanguageChange Suggested changes to the Go language Proposal v2 A language change or incompatible library change
Projects
None yet
Development

No branches or pull requests

4 participants