O GoConqr está de visual novo! Conte para nós o que você achou.

Flashcards

Functions

Filipi Melo Learning Go Book Inglês 30 flashcards

Flashcards do conjunto (30)

  1. 1Function declaration in GoUse the `func` keyword followed by the function name, input parameters with types, and return type.
  2. 2When is the `return` keyword required in a Go function?When the function returns a value or needs to exit early.
  3. 3How do you declare a function with no input parameters in Go?Use empty parentheses `()`.
  4. 4What should you do if a Go function has no return value?Leave the return type empty.
  5. 5Easier way to declare multiple parameters of the same type in Go?Specify the type once for all parameters.
  6. 6Can Go functions have named or optional parameters?No, Go does not support named or optional parameters.
  7. 7How can you simulate named parameters in Go?By defining a struct with fields for the desired parameters.
  8. 8What might be indicated by a function with too many parameters?It often indicates an overly complex function.
  9. 9What are variadic parameters in Go?Parameters indicated by `...` before the type, allowing multiple arguments.
  10. 10Where must variadic parameters appear in a Go function's parameter list?They must be the last parameter.
  11. 11How do you treat a variadic parameter as a slice in Go?You can use it like any other slice within the function.
  12. 12How do you supply a slice to a function expecting variadic parameters?Append `...` to the slice variable or literal.
  13. 13What happens if you omit `...` when passing a slice to a variadic function?It causes a compile-time error.
  14. 14How are multiple return values declared in a Go function?List the return types in parentheses, separated by commas.
  15. 15What is the convention for the last return value in a Go function with multiple returns?It is typically an error value, which should be `nil` if no error occurred.
  16. 16How do you handle unused return values in Go?Assign them to `_` to ignore them.
  17. 17Can you leave return values unassigned in Go?Yes, but only by omitting the assignment, which may reduce clarity.
  18. 18What are named return values in Go?Variables predeclared within the function to hold return values.
  19. 19What happens to named return values in Go upon function initialization?They are initialized to their zero values.
  20. 20Can you partially name return values in Go?Yes, you can use `_` for unnamed return values.
  21. 21What should you be cautious of when using named return values in Go?Accidentally shadowing the named return values within the function.
  22. 22Why should you avoid using blank returns in Go?They obscure data flow and make the code harder to understand.
  23. 23What does it mean that functions are values in Go?Functions can be assigned to variables and treated like any other value.
  24. 24What is the default value of a function variable in Go?`nil`, and running a `nil` function causes a panic.
  25. 25How do you define a function type in Go?Use the `type` keyword followed by the function signature.
  26. 26What are anonymous functions in Go?Functions without names, defined using the `func` keyword, that can be assigned to variables.
  27. 27When are anonymous functions useful in Go?For `defer` statements and launching goroutines.
  28. 28What are closures in Go?Functions declared inside other functions that can access and modify outer variables.
  29. 29What is the purpose of the `defer` keyword in Go?To schedule cleanup code that runs after a function completes.
  30. 30What does "Go is call by value" mean?Go copies variable values when passing them to functions, preventing the original variables from being modified.

Informações

Descrição
Book Learning Go (CH5: Functions) FlashCards sobre Functions, criado por Filipi Melo em 08-08-2024.
Criado por
Filipi Melo
Visualizações
1
Avaliação

Mais sobre Go Programming

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?