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: Default Arguments in Go #69535

Closed
1 of 4 tasks
omid-official opened this issue Sep 19, 2024 · 2 comments
Closed
1 of 4 tasks

Proposal: Default Arguments in Go #69535

omid-official opened this issue Sep 19, 2024 · 2 comments
Labels
LanguageChange Suggested changes to the Go language LanguageChangeReview Discussed by language change review committee Proposal
Milestone

Comments

@omid-official
Copy link

Go Programming Experience

Intermediate

Other Languages Experience

Python, PHP, JavaScript

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?

I think no

Does this affect error handling?

No

Is this about generics?

No

Proposal

Introduce default arguments to Go functions to simplify function calls when certain arguments have common or default values. This change will help developers avoid boilerplate code and make function signatures cleaner.

Language Spec Changes

The language spec would be updated to include syntax for default arguments in function definitions.

Informal Change

You could define a function with default values for some parameters, allowing you to call it without specifying those parameters each time.

Is this change backward compatible?

Yes

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

How does this change interact or overlap with existing features?
Default arguments would be an additional feature but would not conflict with existing Go language features. It will integrate naturally with existing function calls and parameter handling.

Is the goal of this change a performance improvement? No

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

It would make Go easier to learn and use for developers familiar with default arguments in other languages, reducing boilerplate code and improving code readability.

Cost Description

Implementation complexity and potential changes to the Go compiler and toolchain to support default arguments.

Changes to Go ToolChain

Tools that analyze, format, or modify code might need updates to support default arguments.

Performance Costs

What is the compile time cost? Minimal, as default arguments would be a syntactic change rather than a runtime feature. What is the run time cost? Minimal impact on runtime performance. The change primarily affects function call syntax and does not introduce significant runtime overhead.

Prototype

The implementation could involve modifying the Go parser and compiler to recognize default argument syntax and handle it appropriately during function calls. The default values would be substituted during function call resolution.

@omid-official omid-official added LanguageChange Suggested changes to the Go language LanguageChangeReview Discussed by language change review committee Proposal labels Sep 19, 2024
@gopherbot gopherbot added this to the Proposal milestone Sep 19, 2024
@seankhliao
Copy link
Member

see https://go.dev/doc/faq#overloading

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2024
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 LanguageChangeReview Discussed by language change review committee Proposal
Projects
None yet
Development

No branches or pull requests

4 participants