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: fmt: add ReadLine() string #54620

Closed
earthboundkid opened this issue Aug 23, 2022 · 4 comments
Closed

proposal: fmt: add ReadLine() string #54620

earthboundkid opened this issue Aug 23, 2022 · 4 comments

Comments

@earthboundkid
Copy link
Contributor

Every few months, someone will post on Reddit that they're trying to make an intro to CS-style input prompt and they're confused why their code using fmt.Scan* doesn't work (inevitably because the input has a space and they're ignoring errors). I think that just for the use case of education, there should be something in fmt that does the thing that they want.

package fmt

// ReadLine attempts to read one line from os.Stdin. If it encounters an error, it returns "". 
// Advanced users may prefer to use a Scan function or bufio.Scanner.
func ReadLine() string
@gopherbot gopherbot added this to the Proposal milestone Aug 23, 2022
@seankhliao
Copy link
Member

This doesn't belong in the fmt package, which is for "formatted I/O".

As you've observed, the correct place is bufio, and it already exists.

https://go.dev/doc/faq#x_in_std

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Aug 23, 2022
@earthboundkid
Copy link
Contributor Author

I disagree. fmt.Scan already exists and is an attractive nuisance to learners. I don't think my proposal has to be accepted by the Go team, but I also don't think it should be preemptively closed. My point isn't that this would be a useful function for professional programmers. My point is that today many new users are frustrated because their simple, intro-to-CS-style programs don't work.

Here are some typical posts:

You can find more by searching site:https://reddit.com/r/golang fmt.scan. There needs to be something very simple that novice can find without knowing anything about Go or IO. Obviously, they could and probably should be using bufio.Scanner already, but they aren't finding it today.

@seankhliao
Copy link
Member

It looks like the forums are doing their job of educating users.

without knowing anything about Go or IO.

Is not a design goal for the standard library.


Indeed adding Scan* was a mistake too: #12275 (comment)

@earthboundkid
Copy link
Contributor Author

New proposal: Deprecate Scan* functions.

@golang golang locked and limited conversation to collaborators Aug 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants