An Introduction to Programming in Go - v1

Types

int, uint, float32, float64, bool, string

Control Structures

if-else

for

switch

Arrays, Slices and Maps

Arrays - indexable, single type, fixed length

Slices - indexable, single type but length is allowed to change; use make function to craete a slice; appendcopy;

Maps - unordered, key-value pairs; initialize before use; make; delete;

Functions

named return type

multiple returned values

variadic parameters

closure - create functions inside function

recursion

defer - scheduled a function call to be run after the function completes; often used for resources releasing;

panic - indicates a programmer error

recover - handle a runtime panic

Pointers

pointers reference a location in memory where a value is stored rather than the value itself

pointer is represented using the * character followed by the type of the stored value

* is also used to "dereference" pointer variables

use & operator to find the address of a variable

new - take a type as an argument, allocates enough memory to fit a value of that type, returns a pointer to it

Structs and Interfaces

struct - a type which contains named fileds; create methods for structs

interface - not like struct contains fields, in interface we define "method sets"

Concurrency

goroutine - use keyword go followed by a function invocation to create a goroutine; the first goroutine is implicit and is the main function itself;

channel - it provides a way for two goroutines to communicate with one another and synchronize their executions

channel directions - specify a direction on a channel type thus restricting it either sending or receiving

select - works like switch but for channels; often used to implement a timeout;

time.after

buffered channel - specifiy capacity

packages

testing

1 package math
2
3 import "testing"
4
5 func TestAverage(t *testing.T) {
6
7 ...
8
9 }

Core Packages

strings - a large number of functions working with strings

input/output - io package consists of a few functions, but mostly interfaces used in other packages; two main interfaces are Reader and Writer.

files & folders - os package

errors - errors package;  error.New("...")

containers & sort

  • container/list - implement a doubly-linked list
  • sort - contains functions for sorting arbitrary data; sort.Interface requires 3 methods: Len, Less, Swap, any type defined these 3 methods can be sorted.

hashes & cryptography - non-cryptographic hash functions in hash/adler32, crc32, crc64, fnv; cryptographic hash functions in crypto/sha1, crypto/md5, etc.

servers - net, net/http, net/rpc, etc

parsing command line args - flag package

synchronization primitives - Go provides more traditional multithreading routines in sync and sync/atomic packages

时间: 2024-10-06 02:16:00

An Introduction to Programming in Go - v1的相关文章

SIT102 Introduction to Programming Working with Arrays

SIT102 Introduction to ProgrammingPass Task 6.1: Working with ArraysOverviewIn this task you will create a simple program which will create an array with a user specified size. Thisarray will then be populated with values, printed out to the console,

[Introduction to programming in Java 笔记] 1.3.7 Converting to binary 十进制到二进制的转换

public class Binary { public static void main(String[] args) { // Print binary representation of N. int N = Integer.parseInt(args[0]); int v = 1; while(v <= N/2) v = 2*v; // Now v is the largest power of 2 <= N. int n = N; // current excess while (v

[Introduction to programming in Java 笔记] 1.3.9 Factoring integers 素因子分解

素数 A prime is an integer greater than one whose only positive divisors are one and itself.整数的素因子分解是乘积等于此素数的集合.例如:3757208 = 2*2*2*7*13*13*397 public class Factors { public static void main(String[] args) { // Print the prime factors of N. long N = Lon

Objective-C Programming (2nd Edition)

Book Description Want to write iOS apps or desktop Mac applications? This introduction to programming and the Objective-C language is your first step on the journey from someone who uses apps to someone who writes them. Based on Big Nerd Ranch's popu

Github 的一个免费编程书籍列表

Index Ada Agda Alef Android APL Arduino ASP.NET MVC Assembly Language Non-X86 AutoHotkey Autotools Awk Bash Basic BETA C C# C++ Chapel Cilk Clojure COBOL CoffeeScript ColdFusion Cool Coq D Dart DB2 Delphi / Pascal DTrace Elasticsearch Emacs Erlang F#

计算机类免费电子书共享

列表最早来自stackoverflow上的一个问题:List of freely available programming books 现在在github上进行维护:free-programming-books List of Free Programming Books This list initially was a clone of stackoverflow - List of freely available programming books by George Stocker.

Github上的1000多本免费电子书重磅来袭!

这个GIthub库的免费电子书资源绝对值得你拥有,赶紧收藏吧! 以前 StackOverFlow 也给出了一个免费电子书列表,现在在Github上可以看到时刻保持更新的列表了. 瞥一眼下面的书籍分类目录,你就能知道这个免费电子书库的含金量了吧.记得一定要看几本,千万别下载了大量书籍而束之高阁! 行动重于空想! Github地址:     https://github.com/vhf/free-programming-books/blob/master/free-programming-books

Android 学习资料分享(2015 版)

我是如何自学Android,资料分享(2015 版) Tikitoo2015.02.11 10:21 1713 字 3932 次阅读 自己学了两三个月的Android,最近花了一周左右的时间写了个App--Diigoer(已开源),又花了一两周时间找工作,收到了两个Offer,也算是对自己学习的一种认可吧:我刚开始学习总结的--<我是如何自学Android,资料分享>,如果是初学Android 的话,不应该错过的,而今天这篇分享好这篇文章,相对于第一次写的会有所提升,所以建议先把上一篇看了,再

370 门免费编程与计算机科学在线课程

简评:这篇文章为大家整理出 370 门精选的免费高质量编程计算机科学类的课程(涵盖程序语言.人工智能.深度学习与机器学习等热门话题).这370 门课程是从 Class Central数据库里面的 7000 门课程挑选出来的,每个课程的 Rating(评价)也是由该网站上获取下来的平均值. 370 门课程里面根据难易程度被分为: 入门 中级 进阶 所收录的大部分教程都已经更新完毕了,你可以按照自己的节奏(Self Paced)随时观看学习,有小部分教程还在持续更新至中,当然了,它们全都是免费的!