Giter Site home page Giter Site logo

go-learning's Introduction

GoLang

Intro

  • Designed as a system language.
  • Can now be used as a general purpose language.
  • Automatic garbage collection, memory clearing etc.
  • Only ~25 keywords.
  • Cross platform.
  • Compiled language.
  • Strongly typed.
  • Supports type inference (can infer the variable type from declaration).
  • Case sensitive

Variables and Constants

Declaring and Initializing variables

  • Variables are statically types, a string remains a string for its lifetime
  • var is used for declaration at package level, they can also be grouped together
  • Go always initializes variable with zero value
  • reflect can be used to check types
  • Go can infer types from declaration
  • Type conversion is pretty much like python
  • Variables declared at package level are Global variables
  • := works only inside functions and only if we're initializing the variables at the same time we declare them.
  • It is necessary to use all the variables, it is not possible to declare variables without using it inside functions. If we declare a variable inside a function it is necessary to use it.
  • := is used to declare new variables whereas = is used to reassign values or simply assign values to a variable
  • Constants are immutable, declared with const, cannot use := with constants.
  • Environment variables are accessible with os package

Pointers

  • Go passes arguments by value, and not by reference.
  • When we create a variable, Go creates a space for it in the memory, when we pass this variable into a function, it makes a copy of this variable with same value in different memory space, the changes are thus made only to the copy of the variable.
  • & gives the memory address of a variable (the pointer value)
  • & references a pointer and * de-references a pointer
  • We can use pointers to pass value by reference

Conditionals

  • If accepts some statements also before the boolean expression
  • Any variables declared with if exist in only that if and else if blocks and are garbage collected after that
  • Even the switch statements can accept statement declaration just like the if statement.
  • The default statement in the switch can go anywhere.
  • The switch case has automatic breaks, it stops the execution after a case match
  • The fallthrough statement executes the next case also.
  • The case can help match multiple statements

go-learning's People

Contributors

amartya-dev avatar

Watchers

 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.