Skip to content

Commit

Permalink
Breaking in subroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelpragier committed Dec 11, 2019
1 parent ee01ac6 commit a7756d4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Go Basics Straight to the point
### All the basics concentrated and explained in two source code files

Topics
- Variables
- Constants
- Comments
- Basic Types
- Structs
- Flow Control
- Style
- Basic date/time handling
- Anonym Routine / Closure
- Package
- Basic Text Disk I/O
23 changes: 22 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ func init() {
println("check stdout! this routine runs first. Boolean global variable is now ", globalVariable)
}

func main() {
// variablesAndSimpleTypes demonstrates all the possible ways to declare and initialize
// variables and constants of simple ( not struct ) types
func variablesAndSimpleTypes() {
const strConst = "string constant"

const (
Expand Down Expand Up @@ -80,7 +82,14 @@ func main() {
fmt.Printf("runeA is type %T and value %c\n", runeA, runeA)

fmt.Printf("runeB is type %T and value %c\n", runeB, runeB)
}

func deferredRoutine() {
fmt.Println("this is a deferred routine. Was scheduled by GO compiler to run after the last synchronous instruction end")
fmt.Println("it's not the same as OOP destructor, but it's often used the same way of, to close/dispose allocated resources")
}

func closureRoutines() {
// Anonymous functions are allowed in go, and you can attrib their bodies to a variable or execute directly when declaring
closure := func(msg string) { fmt.Println(msg) }

Expand All @@ -91,7 +100,19 @@ func main() {
intResult := func() int { return 42 }()

fmt.Printf("This closure returned %d\n", intResult)
}

func packagedRoutine() {
// Now we're using our own package
mypack.ExportedRoutine()
}

func main() {
variablesAndSimpleTypes()

defer deferredRoutine()

closureRoutines()

packagedRoutine()
}

0 comments on commit a7756d4

Please sign in to comment.