So, I'm new to Go, but I wanted to make a cli app that plays go fish with
another client over a network. While I was testing the main loop that takes
in the commands, I noticed that the program wouldn't exit when I entered
the exit command. Here is my code before I found the issue.
var text string //Instantiating the variable that would hold the command in
a scope where the loop can check it
for text != "exit\n" {
fmt.Println("Enter command")
text, err := reader.ReadString('\n') //This is where I realized the
error was. I create another text variable that is in the scope of the loop.
}
I know this was a beginner mistake, and looking back at it, I feel stupid,
but it got me thinking. Go gives a compiler error if you declare a variable
and don't use it. In this instance I did use the outer scope variable text,
but I never gave it a value in my code. Now, I don't know if there are
warnings already in place that will tell you this. If there aren't,
however, I think there should be at least a compiler warning. I was told to
post something here before I open an issue. So really this is just me
asking if a compiler warning for this would be a good idea, or is this just
a beginner mistake that no one runs into if they know what they're doing.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.