From 0f5d40b9031032fa431657fa6c00c7ee0f1b7649 Mon Sep 17 00:00:00 2001 From: Maciej Kaczkowski Date: Sun, 11 Feb 2024 13:14:04 +0100 Subject: [PATCH] chapter 2 done --- .../README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 learning_go/2_generic_types_and_declarations/README.md diff --git a/learning_go/2_generic_types_and_declarations/README.md b/learning_go/2_generic_types_and_declarations/README.md new file mode 100644 index 0000000..d52cd6c --- /dev/null +++ b/learning_go/2_generic_types_and_declarations/README.md @@ -0,0 +1,19 @@ +# 2_generic_types_and_declarations + +* 5 types of literals in Go: + * integer + * floating-point + * rune + * string + * complex + +* differences between `var` and `:=`: + * `var` - declares a variable, but does not initialize it + * `:=` - declares and initializes a variable +* more subtle: `:=` should (and can) only be used inside function body, while `var` also works on package-level (though, it's rare to declare variable like this - declarations list should then be used) +* sometimes `:=` shouldn't be used inside function body (e.g. when you want to declare a variable with the same name as a package-level variable) to make your intention clear +* `const` - declares a constant, which must be initialized at the time of declaration +* `namingConvention`: + * `PascalCase` - for exported names (visible outside of package) + * `camelCase` - for internal names (visible only inside package) + * no `snake_case` in Go as in Python