Skip to content

Commit dce6fd5

Browse files
committed
Review finished chapters & Update Go version
1 parent e8b3c44 commit dce6fd5

File tree

7 files changed

+35
-34
lines changed

7 files changed

+35
-34
lines changed

01-Setup-And-Hello-World/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/maevadevs/Go-Learning/01-Setup-And-Hello-World
22

3-
go 1.22.1
3+
go 1.22.2

01-Setup-And-Hello-World/readme.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ Command | Action
143143

144144
```tree
145145
Go-Module-Name
146-
|- go.mod
147-
|- makefile
148-
|- readme.md
149-
|- bin/
150-
|- src/
151-
| |- main.go
152-
|- tests/
146+
|-- go.mod
147+
|-- makefile
148+
|-- readme.md
149+
|-- bin/
150+
|-- src/
151+
| |-- main.go
152+
|-- tests/
153153
```
154154

155155
### Go Module
@@ -162,7 +162,7 @@ Go-Module-Name
162162
go mod init unique/module/path
163163
```
164164

165-
- It declares:
165+
- It declares
166166
- The name of the module and its path
167167
- Minimum supported Go version
168168
- Any additional module dependencies
@@ -175,7 +175,7 @@ go mod init unique/module/path
175175
```sh
176176
module unique/module/path
177177

178-
go 1.22.1
178+
go 1.22.2
179179
```
180180

181181
### `main.go`
@@ -203,7 +203,7 @@ func main() {
203203
#### Import Declaration
204204

205205
- Allows to import external packages that are referenced in the file
206-
- **Go imports only whole packages**
206+
- **Go imports only whole packages**
207207
- We cannot limit the import to specific functions or other elements
208208
- `fmt` is from the standard library so it is already available
209209

@@ -304,7 +304,7 @@ func main() { // ...no automatic semicolon insertion here
304304

305305
- It is possible for code to be syntactically valid yet likely incorrect
306306
- `go vet` can detect these errors
307-
- Run in it a directory with `.go` files to scan for common coding mistakes
307+
- Run it in a directory with `.go` files to scan for common coding mistakes
308308

309309
```go
310310
package main
@@ -465,13 +465,13 @@ Command|Description
465465

466466
## Staying Up-To-Date
467467

468-
- Updating Go environment does not affect previously-compiled programs
468+
- **Updating Go environment does not affect previously-compiled programs**
469469
- Go compiles to standalone native binary
470470
- There is no dependency on any VMs
471471
- The version of Go does not affect the runtime of the compiled program
472472
- For Windows, `chocolatey` can be used to install and update Go
473473
- For Mac, `brew` can be used to install and update Go
474-
- Otherwise, follow the installer's option be removing and re-installing
474+
- Otherwise, follow the installer's option for removing and re-installing
475475
- For Linux
476476
- Move the current installaton in a backup location
477477
- Download and unpack the new installation

02-Types-And-Declarations/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/maevadevs/Go-Learning/Types-And-Declarations
22

3-
go 1.22.1
3+
go 1.22.2

02-Types-And-Declarations/readme.md

+16-14
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
4343
- Write programs in a way that makes intentions clear
4444
- Some particular approaches produce clearer codes
4545
- Built-in types in Go and how to declare them
46-
- Go does things differently
47-
- Subtle differences with other languages
46+
- Go does things differently: Subtle differences from other languages
4847
- **NOTE: All declared variables in Go must be used**
4948

5049
## Predeclared Types
@@ -58,15 +57,15 @@
5857

5958
## Zero Values
6059

61-
- Declared variables with no initial values are assigned default Zero Values
60+
- **Declared variables with no initial values are assigned default *Zero Values***
6261
- Explicit *Zero Value*
6362
- Makes code clearer
6463
- Removes sources of bugs
6564
- [More details on the docs page](https://go.dev/ref/spec#The_zero_value)
6665

6766
## Literals
6867

69-
- Explicitly specified number, character, or string
68+
- **Explicitly specified number, character, or string**
7069
- 4 common kinds of literals
7170
- Integer literal
7271
- Float Literal
@@ -123,7 +122,7 @@ func main() {
123122
### Float Literal
124123

125124
- Sequence of numbers with decimal point to indicate the fractional portion
126-
- Can also have an exponent `e` or `E` with positive of negative number
125+
- Can also have an exponent `e` or `E` with positive or negative number
127126
- Can also be written in hexadecimal
128127
- E.g. `0x12.34p5`
129128
- `p` indicates the exponent
@@ -225,6 +224,7 @@ func main() {
225224
- **In these cases, using *Raw String Literal* is more appropriate**
226225
- Delimited with backticks <code>``</code>
227226
- **Can contain any character except backticks**
227+
- If <code>\`</code> is required, try using <code>\`raw string\` + "`"</code> instead
228228
- No escape character can be applied
229229
- All characters are included as-is
230230

@@ -242,15 +242,15 @@ func main() {
242242
var greetings string = "Hello World!"
243243
// Using Escapes
244244
var greetingsLong string = "Greetings and \n\"Salutations\"!"
245-
var goPath string = "https:\\\\go.dev"
245+
var sysPath string = "C:\\\\Windows\\System32"
246246
// Using Raw String Literal
247247
var greetingsRaw string = `Greetings and
248248
"Salutations"!`
249249
var goPathRaw string = `https://go.dev`
250250

251251
fmt.Println("greetings =", greetings)
252252
fmt.Println("greetingsLong =", greetingsLong)
253-
fmt.Println("goPath =", goPath)
253+
fmt.Println("sysPath =", sysPath)
254254
fmt.Println("greetingsRaw =", greetingsRaw)
255255
fmt.Println("goPathRaw =", goPathRaw)
256256
}
@@ -501,7 +501,8 @@ func main() {
501501
## Strings and Runes
502502

503503
- String is a built-in data type
504-
- Supports Unicode - We can put any unicode characters in strings
504+
- Supports Unicode
505+
- We can put any unicode characters in strings
505506
- Zero-Value is `""`
506507
- Default Type is `string`
507508
- **Strings are immutable**
@@ -616,7 +617,7 @@ var x = 100
616617

617618
### Declaration Only With `var`
618619

619-
- We can declare only without assigning an initial value
620+
- We can declare only, without assigning an initial value
620621
- The type is required
621622
- Assigns the *Zero-Value* of the type as the default value
622623

@@ -666,7 +667,7 @@ var (
666667
### Walrus Shortcut `:=`
667668

668669
- `:=` can replace `var` declaration with type inference
669-
- It is preferred over `var`
670+
- `:=` is preferred over `var`
670671

671672
```go
672673
// Equivalent statements
@@ -704,10 +705,11 @@ name, age, isAdult := "Johnny", 26, true
704705
- `:=` is the most common inside functions
705706
- Use declaration lists when declaring multiple variables
706707
- Avoid `:=` when:
708+
- Declaring Package-level variables
707709
- Initializing to zero-value
708710
- Assigning an untyped constant
709711
- Variable type cannot/should not be deduced from the assigned value
710-
- Prefer `var x byte = 20` over `x := byte(20)`
712+
- Prefer `var x byte = 20` over `x := byte(20)`
711713
- **Sometimes, `:=` creates a new variable than using an existing one (*Shadowing*)**
712714
- In those cases, it is better to use `var`
713715
- **NOTE: Only use the *Multiple declaration and assignment* style when assigning multiple values from a function return**
@@ -792,7 +794,7 @@ const total = x + y
792794
- **Untyped Constant** is the same as literal
793795
- Has no type on its own
794796
- Has default type when type cannot be inferred
795-
- **Typed Constant** can be assigned directly only to a *"variable"* of the same type
797+
- **Typed Constant** can be assigned directly only a *"variable"* of the same type
796798
- **Usage depends on the intent**
797799
- Constants to be used with multiple numeric types => *Keep untyped*
798800
- Untyped Constants give more flexibility
@@ -818,7 +820,7 @@ var i64 int64 = tconst
818820

819821
## Unused Variables
820822

821-
- **Every *local* declared variables/constants must be used/read at least once**
823+
- **Every *locally* declared variables/constants must be used/read at least once**
822824
- It is a compile-time error if a declared variable is not used
823825
- As long as the variable is read once
824826
- Go will not catch the unused `x = 30`
@@ -837,7 +839,7 @@ func main() {
837839
```
838840

839841
- **NOTE: This rule does not apply to *constants* and *package-level variables***
840-
- It is better to avoid package-level variables*
842+
- It is better to avoid *package-level variables*
841843
- Constants in Go are calculated at compile-time (cannot have side-effects)
842844
- Can be eliminated if unused: They are excluded from the compiled binary
843845

02-Types-And-Declarations/src/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ func main() {
8080
var greetings string = "Hello World!"
8181
// Using Escapes
8282
var greetingsLong string = "Greetings and \n\"Salutations\"!"
83-
var goPath string = "https:\\\\go.dev"
83+
var sysPath string = "C:\\\\Windows\\System32"
8484
// Using Raw String Literal
8585
var greetingsRaw string = `Greetings and
8686
"Salutations"!`
8787
var goPathRaw string = `https://go.dev`
8888

8989
fmt.Println("greetings =", greetings)
9090
fmt.Println("greetingsLong =", greetingsLong)
91-
fmt.Println("goPath =", goPath)
91+
fmt.Println("sysPath =", sysPath)
9292
fmt.Println("greetingsRaw =", greetingsRaw)
9393
fmt.Println("goPathRaw =", goPathRaw)
9494

go.work

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
go 1.22.1
1+
go 1.22.2
22

33
use (
44
./01-Setup-And-Hello-World

updatego.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/bin/bash
22

33
######################################################################################
4-
# SCRIPT: Allow to quickly update go version in go.work and go.mod to system's #
5-
# AUTHOR: github.com/maevadevs #
4+
# SCRIPT: Allow to quickly update go version in go.work and go.mod to system #
65
# CALL SIGN: bash updatego.sh #
76
# CALL EXAMPLE: bash updatego.sh #
87
######################################################################################

0 commit comments

Comments
 (0)