Programming in Go(lang)

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
Advertisements

Programming Languages and Paradigms
Names and Bindings.
Principles of Object-Oriented Software Development The language Java.
Names and Bindings Introduction Names Variables The concept of binding Chapter 5-a.
C++ for Java Programmers Chapter 1 Basic Philosophical Differences.
+ Java vs. Javascript Jessi Style. + Java Compiled Can stand on its own Written once, run anywhere Two-stage debugging Java is an Object Oriented Programming.
Programming Languages and Paradigms Object-Oriented Programming.
Dale Roberts Procedural Programming using Java Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
University of Houston-Clear Lake Proprietary© 1997 Evolution of Programming Languages Basic cycle of improvement –Experience software difficulties –Theory.
Applied Computing Technology Laboratory QuickStart C# Learning to Program in C# Amy Roberge & John Linehan November 7, 2005.
C# EMILEE KING. HISTORY OF C# In the late 1990’s Microsoft recognized the need to be able to develop applications that can run on multiple operating system.
Introduction to Java Java Translation Program Structure
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
RUBY by Ryan Chase.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
C Part 1 Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens A History Lesson Development of language by Dennis Ritchie at Bell.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
FASTFAST All rights reserved © MEP Make programming fun again.
SCP1103 Basic C Programming SEM1 2010/2011 Arithmetic Expressions Week 5.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
A Single Intermediate Language That Supports Multiple Implemtntation of Exceptions Delvin Defoe Washington University in Saint Louis Department of Computer.
 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
Object Lifetime and Pointers
Arithmetic Expressions
Data Types In Text: Chapter 6.
JAVA MULTIPLE CHOICE QUESTION.
Names and Attributes Names are a key programming language feature
Types for Programs and Proofs
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Programming with ANSI C ++
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Learn Go Fast With Riley.
Java Primer 1: Types, Classes and Operators
FUNCTIONS In C++.
Representation, Syntax, Paradigms, Types
Review: Two Programming Paradigms
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
New trends in parallel computing
Java Review: Reference Types
Templates.
Functional Programming with Java
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
Parallel Programming in Contemporary Programming Languages (Part 2)
JavaScript an introduction.
Java Programming Language
Introduction to Python
MSIS 655 Advanced Business Applications Programming
More About Data Types & Functions
Representation, Syntax, Paradigms, Types
Sridhar Narayan Java Basics Sridhar Narayan
Go.
Representation, Syntax, Paradigms, Types
Python Primer 1: Types and Operators
6 Methods: A Deeper Look.
Focus of the Course Object-Oriented Software Development
(Computer fundamental Lab)
Representation, Syntax, Paradigms, Types
Object Oriented Programming in java
Java Programming Language
Operator Overloading; String and Array Objects
Java Basics Data Types in Java.
Chap 1. Getting Started Objectives
Chap 4. Programming Fundamentals
SPL – PS1 Introduction to C++.
SPL – PS3 C++ Classes.
Presentation transcript:

Programming in Go(lang) 20-Nov-17

Go An open-source programming language created by Google Hello World: Resolves common criticisms of other languages while maintaining positive characteristics Created out of founder’s dislike of C++ Compiled, concurrent, and imperative Does not require tooling, but has sufficient support Readable with few keywords or reputation (like other object-oriented languages) Support networking and multiprocessing Hello World: package main import "fmt" func main() { fmt.Println("Hello, World") }

Language Design Similar to the design of C with improved brevity and simplicity Syntax and environment adopts patterns common in dynamic languages Concise variable declaration and initialization with type inference x := 0 versus var x int = 0; Fast compilation times, remote package management (go get) and online documentation (similar to Oracle docs) Other notable design features / relevant approaches Built-in concurrency primitives achieve light-weight processes (goroutines) and channels (select statement) Interface system (vs virtual inheritance) and type embedding (vs non-virtual inheritance) Toolchain produces statically linked native binaries without external dependencies

Syntax Combined declaration/initialization operator allows programmer to write without specifying types of variables i := 3  versus  int i = 3;    s := "some words” versus  const char *s = "some words” Semicolons are implicit at the end of a line Functions may return multiple values Returning a result, err pair indicates an error to its caller Literal syntaxes for initializing struct parameters by name, and for initializing maps and slices Go's range expressions allow concise iteration over arrays, slices, strings, maps and channels (versus a three statement for loop) for i, num := range nums { if num == 3 { fmt.Println("index:", i) }

Types Strong, Static, Inferred, Structural Built-in types like C++, Java Built-in operators and keywords (rather than functions) provide concatenation, comparison, and UTF-8 encoding / decoding Record types be defined with the struct keyword For each type T and each non-negative integer constant n, there is an array Type denoted [n]T Arrays of differing lengths are of different types Dynamic Arrays available as "slices", denoted []T for some type T Length & capacity specify when new memory needs to be allocated to expand the array Several slices may share their underlying memory letters := []string{"a", "b", "c", "d"}

More Types Pointers available for all types, and the pointer-to-T type is denoted *T Address-taking and indirection use the & and *operators as in C or happen implicitly through method calls / attribute access syntax There is no pointer arithmetic, except via the special unsafe.Pointer type Type system is nominal: the type keyword can be used to define a new named type, which is distinct from other named types that have the same layout Some conversions between types are pre-defined Adding a new type may define additional conversions, but conversions between named types must always be invoked explicitly For example func Float64bits(f float64) uint64 { return *(*uint64)(unsafe.Pointer(&f)) }

Concurrency with GoRoutines Built-in facilities and library support for concurrent programs  CPU parallelism and asynchrony  The primary concurrency construct is  goroutine Function call prefixed with go keyword starts a function in new goroutine Current implementations multiplex a Go process's goroutines onto a smaller set of operating system threads operating systems threads  Similar to the scheduling performed in Erlang func main() { t := make(chan bool) go timeout(t) ch := make(chan string) go readword(ch) select { … } }

Developer Criticism Lacks compile-time generics Results in code duplication Metaprogramming cannot be statically checked Standard library cannot offer generic algorithms Lack of language extensibility makes certain tasks more verbose Lacks operator overloading (Java) Type system lacks Hindley-Milner typing Inhibits safety and/or expressiveness Pauses and overhead of garbage collection Limit Go’s use in systems programming compared to languages with manual memory management Mitigates: Designers argue these trade-offs are important to Go’s success, and explain some particular decisions at length

Practical Use Cases The Really Good: Network and Web Servers Network applications live and die by concurrency Go's native concurrency features: (goroutines and channels) Networking, distributed functions, or services (APIs, Web Servers, minimal frameworks for Web Apps) Items are either a part of language (goroutines for threadlike behavior) or available in the standard library http package. ”Batteries included" philosophy like Python Stand-alone command-line apps or scripts Stand-alone executables with no external dependencies Versus Python which requires a copy of the interpreter on the target machine Can talk to underlying system, external C libraries, native system calls Caution: Desktop/GUI-based apps & System-Level Programming

The End