Coder Social home page Coder Social logo

golang-basic's Introduction

Learning golang

  1. Statically typed language where all variables have assigned types. You can set types explicitly or implicitly
  • Explicit
var aInteger int = 42
var aString string = "some text"
  • Implicit
anInteger := 42
aString := "This is Go!"
  1. Like C, Go supports the use of pointers, variables that store the address of another value var p *int var v int = 42

  2. The struct type in Go is a data structure, similar to C's struct and Java's classes. They encapsulate both data and methods, but unlike Java, Go doesn't have an inheritance model. You don't have concepts like super or sub-structs. Each structure is independent, with its own fields for data management and optionally its own methods

Notes ..* Go has runtime that's statically linked into each compiled application. Along with any external packages that are declared and imported in the application source code. The runtime operates in its own background threads, So like other managed languages such as Java & C#, memory is managed completely in the background. And you don't have to explicitly allocate or deallocate memory.

The new() function

  • Allocates but does not initialize memory
  • Results in zeroed storage but returns a memory address

The make() function

  • Allocates and initilizes memory
  • Allocates non-zeroed storage and returns a memory address

Use make() to allocate and initialize memory

m := make(map[string]int)
m["key"] = 42
fmt.Println(m)
desc cmd
run file go run .go
format gofmt -w .go
build (build a executable) go build .go

golang-basic's People

Contributors

alvinyuen avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.