Skip to content

Commit accbea5

Browse files
committed
Move code to /concepts
1 parent b7d5553 commit accbea5

12 files changed

+52
-28
lines changed

README.md

+1-8
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,4 @@ With that in mind, Golang is a language with fewer abstractions when comparing t
3333

3434
I believe to get a good understanding, you can follow this order:
3535

36-
- [Constants & variables](https://github.com/mfbmina/data-structures-algorithms-go/blob/main/constants_and_variables.go)
37-
- [Stdin & stdout](https://github.com/mfbmina/data-structures-algorithms-go/blob/main/stdin_stdout.go)
38-
- [Arrays](https://github.com/mfbmina/data-structures-algorithms-go/blob/main/array.go)
39-
- [Conditional statements](https://github.com/mfbmina/data-structures-algorithms-go/blob/main/conditional_statements.go)
40-
- [Loops](https://github.com/mfbmina/data-structures-algorithms-go/blob/main/loops.go)
41-
- [Pointers](https://github.com/mfbmina/data-structures-algorithms-go/blob/main/pointers.go)
42-
- [Structs](https://github.com/mfbmina/data-structures-algorithms-go/blob/main/structs.go)
43-
- [Functions](https://github.com/mfbmina/data-structures-algorithms-go/blob/main/functions.go)
36+
- [Concepts](https://github.com/mfbmina/data-structures-algorithms-go/blob/main/concepts)

concepts/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Golang basic concepts
2+
3+
These are the basics of Golang
4+
5+
I believe to get a good understanding, you can follow this order:
6+
7+
- [Constants & variables](https://github.com/mfbmina/data-structures-algorithms-go/blob/main/concepts/constants_and_variables.go)
8+
- [Stdin & stdout](https://github.com/mfbmina/data-structures-algorithms-go/blob/main/concepts/stdin_stdout.go)
9+
- [Arrays](https://github.com/mfbmina/data-structures-algorithms-go/blob/main/concepts/array.go)
10+
- [Conditional statements](https://github.com/mfbmina/data-structures-algorithms-go/blob/main/concepts/conditional_statements.go)
11+
- [Loops](https://github.com/mfbmina/data-structures-algorithms-go/blob/main/concepts/loops.go)
12+
- [Pointers](https://github.com/mfbmina/data-structures-algorithms-go/blob/main/concepts/pointers.go)
13+
- [Structs](https://github.com/mfbmina/data-structures-algorithms-go/blob/main/concepts/structs.go)
14+
- [Functions](https://github.com/mfbmina/data-structures-algorithms-go/blob/main/concepts/functions.go)

array.go renamed to concepts/array.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package concepts
22

33
import "fmt"
44

@@ -13,7 +13,7 @@ import "fmt"
1313
// - SIZE: how many elements that array will store.
1414
// - TYPE: any of default types in Go or structs that you've created.
1515
// - DEFAULT_VALUES: this is optional but it is used when you want to create an array with default values on it.
16-
func main() {
16+
func Arrays() {
1717
var words [2]string // declaring an array called words with 2 elements.
1818
words[0] = "Hello" // assign the word "Hello" to the first element into the array
1919
words[1] = "World" // assign the word "World" to the second element into the array

conditional_statements.go renamed to concepts/conditional_statements.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package concepts
22

33
import "fmt"
44

@@ -20,7 +20,7 @@ import "fmt"
2020
// - `!X`: `!` is the operator `NOT`. It negates the value of the expression. If the expression is already false, it becomes true. `!false == true`.
2121
//
2222
// In Golang we have two ways of doing conditional statements: `if/else` and `switch/case`.
23-
func main() {
23+
func ConditionalStatements() {
2424
var age int
2525
var country string
2626
fmt.Println("How old are you?")

constants_and_variables.go renamed to concepts/constants_and_variables.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package concepts
22

33
import "fmt"
44

@@ -34,7 +34,7 @@ import "fmt"
3434

3535
const hello = "Hello, World." // Defining a constant
3636

37-
func main() {
37+
func ConstantsAndVariables() {
3838
var number int // Declaring an integer variable
3939
number = 10 // Assign 10 to this variable
4040
fmt.Println("Number =", number) // Printing number to the screen

functions.go renamed to concepts/functions.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package concepts
22

33
import "fmt"
44

@@ -20,7 +20,7 @@ import "fmt"
2020
//
2121
// To run a Go code, we always define a function called main, which will be executed when you call:
2222
// $ go run file.go
23-
func main() {
23+
func Functions() {
2424
// This is how a function can be called.
2525
hi()
2626

loops.go renamed to concepts/loops.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package concepts
22

33
import "fmt"
44

@@ -9,7 +9,7 @@ import "fmt"
99
// 1. While loops (which sometimes can be infinite loops)
1010
// 2. For loops
1111
// 3. Range loops
12-
func main() {
12+
func Loops() {
1313
array := []int{1, 2, 3, 4, 5}
1414

1515
// While loops are used to do some actions while the condition is true.

pointers.go renamed to concepts/pointers.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package concepts
22

33
import "fmt"
44

@@ -8,12 +8,11 @@ import "fmt"
88
// The type *T is a pointer to a T value. Its zero value is nil.
99
// Unlike C, Go has no pointer arithmetic.
1010

11-
type Rectangle struct {
11+
type Square struct {
1212
lenght int
13-
width int
1413
}
1514

16-
func main() {
15+
func Pointers() {
1716
// Defining a pointer p.
1817
var p *int
1918
i := 42
@@ -30,11 +29,11 @@ func main() {
3029
*p = 21
3130
fmt.Println("New value at i through p", *p)
3231

33-
r := Rectangle{1, 2}
32+
r := Square{1}
3433
// Defining a pointer for r
3534
r_pointer := &r
3635

3736
// If you have a pointer for a struct, you can call its attributes in the same way if it was not a pointer.
38-
area := r_pointer.lenght * r_pointer.width
37+
area := r_pointer.lenght * r_pointer.lenght
3938
fmt.Println("rectangle area's:", area)
4039
}

stdin_stdout.go renamed to concepts/stdin_stdout.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package main
1+
package concepts
22

33
import "fmt"
44

55
// Sometimes we need to get or send information from the users.
66
// In basic programs like ours, we do that by reading information from the terminal and printing it back there.
77
// This is what we call "reading from the `stdin`" and "printing to the `stdout`"
8-
func main() {
8+
func StdinAndStdout() {
99
var name string
1010

1111
// We are printing a question to the stdout

structs.go renamed to concepts/structs.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package concepts
22

33
import "fmt"
44

@@ -17,7 +17,7 @@ type Rectangle struct {
1717
width int
1818
}
1919

20-
func main() {
20+
func Structs() {
2121
var rectangle_1 Rectangle // Declaring a struct without any default value.
2222
fmt.Println(rectangle_1)
2323

data-structures-algorithms-go

2.08 MB
Binary file not shown.

main.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import "github.com/mfbmina/data-structures-algorithms-go/concepts"
4+
5+
func main() {
6+
// conceptsExamples()
7+
}
8+
9+
func conceptsExamples() {
10+
concepts.ConstantsAndVariables()
11+
concepts.StdinAndStdout()
12+
concepts.Arrays()
13+
concepts.ConditionalStatements()
14+
concepts.Loops()
15+
concepts.Pointers()
16+
concepts.Structs()
17+
concepts.Functions()
18+
}

0 commit comments

Comments
 (0)