Tuesday, December 10, 2019

Getting Started with Go

Advantages of Go

1. Code runs fast.
2. Garbage Collection.
3. Simpler Objects.
4. Concurrency is efficient.

Software Translation
- Machine language:CPU instructions represented in binary
- Assembly language:CPU instructions with mnemonics
-> Easier to read
-> Equivalent to machine language.
- High-level language:Commonly used language(C,C++,Java,Python,Go,etc.)
-> Much easier to use.
All language must be translated into the machine language of processor.

Compiled Vs Interpreted

Compilation:
-translate instructioins once before running the code
-> C,C++,Java(partially)
-> Translation occurs every execution
-> Requires an interpreter
Efficiency vs Easy-of-use
-compiled code is fast
-Interpreters make coding easier
->Manage memory automatically
-> Infer variable types
-Go is a good compromise

Garbase Collection
- Automatic memory management
-> Where should memory be allocated?
-> when can memory be deallocated?

-Manual memory management is hard:
-> deallocate too early,false memory accesses.
-> deallocate too late, wasted memory.

-Go includes garbage collection
-> Typically only done by interpreters

OOP
-organize your code through encapsulation
-group together data and functions which are related
-user-defined type which is specific to an application

-Performance limits:
-Moore's law used to help performance.
-> Number of transistors doubles every 18 months.
-More transistors used to lead to higher clock frequencies
-Poer/temperature constraints limit clock frequencies now.

-Parallelism:
-Number of cores still increases over time.
-Multiple tasks may be performed at the same time on different cores.
-Difficulties with parallelism
-> When do tasks start/stop?
-> What if one task needs data from another task?
-> Do task conflict in memory?

-Concurrency is the management of multiple tasks at the same time.
-Key requirement for large systems
-Concurent programming enables parallelism
-> mangement of task execution
-> communication between tasks
-> syncronization between tasks

Concurency in Go
-Goroutines:->concurrent tasks
-Channels:->to communicate between tasks
-Select:-> to enable task synchronization

Directory hierarchy:
src->contain source code files
pkg->contains packages libraries
bin->contains executables

but not forced.

Go Tools
go build - compile the program
- create and executable
- .ext...et.
go doc - print documentation for package.
go fmt - formats source code files.
go get - download packages and install them
go run - compiles .go files and run the executable
go test - runs tests using files ending in _test.go

SOLID-Design-Principles

SOLID-Design-Principles The SOLID principles are fundamental to designing effective, maintainable, object-oriented systems. Whether you...