2.1 KiB
2.1 KiB
Why do you need to use comments sometimes?
- To combine different expressions together
- To provide explanations or generating automatic documentation for your code CORRECT
- To make the code look nice and beautiful
Which of the following code is correct?
package main
/ main function is an entry point /
func main() {
fmt.Println("Hi")
}
- CORRECT
package main
// main function is an entry point /*
func main() {
fmt.Println(/* this will print Hi! */ "Hi")
}
package main
/*
main function is an entry point
It allows Go to find where to start executing an executable program.
*/
func main() {
fmt.Println(// "this will print Hi!")
}
/
is not a comment. It should be//
.- Multiline comments can be put almost anywhere. However, when a comment starts with
/*
, it also needs to end with*/
. Here, Go doesn't interpret/* ... */
, it just skips it. And, when Go sees//
as the first two characters in a code, it skips the whole line.//
prevents Go to interpret the rest of the code line. That's why this code doesn't work. Go can't interpret this part because of the comment:"this will print Hi!")
How should you name your code so that Go can generate documentation from your code automatically?
- By commenting the each line of the code; then it will generate the documentation from whatever it sees
- By starting the comments using the name of the declared names CORRECT
- By using multi-line comments
- This won't help. Sorry.
- It doesn't matter whether you type your comments using single-line comments or multi-line comments.
Which tool do you need to use from the command-line to print the documentation?
- go build
- go run
- go doctor
- go doc
What's the difference between godoc
and go doc
?
go doc
is the real tool behindgodoc
godoc
is the real tool behindgo doc
CORRECTgo
tool is the real tool behindgo doc
go
tool is the real tool behindgodoc
- That's right. go doc tool uses godoc tool behind the scenes. go doc is just a simplified version of the godoc tool.