Using the Go Programming Language in Practice

Similar documents
Develop your Embedded Applications Faster: Comparing C and Golang. Marcin Pasinski Mender.io

Go on NetBSD (and pkgsrc!) A modern systems programming language 23 March Benny Siegert Google Switzerland; The NetBSD Foundation

The Awesomeness of Go. Igor Lankin DevFest Karlsruhe, Nov 2016

New Parallel Programming Languages for Optimization Research

Motivations History Principles Language Gommunity Success stories Conclusion. Let s Go! A brief introduction to Google s new language.

The Go Programming Language. Frank Roberts

A Plan 9 C Compiler for RISC-V

Go vs. Swift: The Languages of The Modern Tech Giants

Go Cheat Sheet. Operators. Go in a Nutshell. Declarations. Basic Syntax. Hello World. Functions. Comparison. Arithmetic. Credits

LDC: The LLVM-based D Compiler

WORKSHOP: from Zero to a Network Application with #golang

Introduzione a Go e RPC in Go


developed ~2007 by Robert Griesemer, Rob Pike, Ken Thompson open source

Go Language September 2016

Erlang and Go (CS262a, Berkeley Fall 2016) Philipp Moritz

Merge Sort Quicksort 9 Abstract Windowing Toolkit & Swing Abstract Windowing Toolkit (AWT) vs. Swing AWT GUI Components Layout Managers Swing GUI

Updating the Compiler?

Introduction to pthreads

Operating Systems (ECS 150) Spring 2011

Let s Go! Akim D le, Etienne Renault, Roland Levillain. June 8, TYLA Let s Go! June 8, / 58

Go Forth and Code. Jonathan Gertig. CSC 415: Programing Languages. Dr. Lyle

Jython. An introduction by Thinh Le

Introduction to Linux

Portland State University Maseeh College of Engineering and Computer Science. Proficiency Examination Process

CSE 124 Discussion (10/3) C/C++ Basics

You can also launch the instances on different machines by supplying IPv4 addresses and port numbers in the format :3410

PRINCIPLES OF OPERATING SYSTEMS

CCured. One-Slide Summary. Lecture Outline. Type-Safe Retrofitting of C Programs

go get my/vulnerabilities Green threads are not eco friendly threads

Go for Java Developers

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

OPERATING SYSTEM. Chapter 4: Threads

SWEN-250 Personal SE. Introduction to C

CUDA Development Using NVIDIA Nsight, Eclipse Edition. David Goodwin

Go Tutorial. To do. A brief, gentle intro to Go. Next Networking. q Today

Rheinisch-Westfälische Technische Hochschule Aachen. Lehrstuhl für Datenmanagement und -exploration Prof. Dr. T. Seidl. Proseminar.

EMBEDDED LINUX ON ARM9 Weekend Workshop

Software Project. Lecturers: Ran Caneti, Gideon Dror Teaching assistants: Nathan Manor, Ben Riva

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

Introduction p. 1 Why Linux? p. 2 Embedded Linux Today p. 3 Open Source and the GPL p. 3 Free Versus Freedom p. 4 Standards and Relevant Bodies p.

Show and Tell. 1. Plan 9 Things (brief) 2. An Extensible Compiler for Systems Programming. Russ Cox 1127 Show and Tell April 19, 2005

Use of the LLVM framework for the MSIL code generation

Yaffs Tuning. Charles Manning

Graphical Presentation of Data

CSE 303 Concepts and Tools for Software Development. Magdalena Balazinska Winter 2010 Lecture 27 Final Exam Revision

Chapter 1 INTRODUCTION SYS-ED/ COMPUTER EDUCATION TECHNIQUES, INC.

Reviewing gcc, make, gdb, and Linux Editors 1

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

Programming in C S c o t t S c h r e m m e r

Hardware OS & OS- Application interface

Multithreaded Programming

CS Programming In C

xtc Robert Grimm Making C Safely Extensible New York University

High Performance Computing and Programming, Lecture 3

ns-3 Training Session 4: Monday 3:30pm ns-3 Annual Meeting May 2014

CS631 - Advanced Programming in the UNIX Environment. UNIX development tools

Operating Systems 2 nd semester 2016/2017. Chapter 4: Threads

ComLinC User Manual. Kefei Lu

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

Quiz on Tuesday April 13. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 4. Java facts and questions. Things to try in Java

Special Topics: Programming Languages

Chapter 2 Operating-System Structures

Creating a system call in Linux. Tushar B. Kute,

ADMINISTRATIVE MANAGEMENT COLLEGE

Chapter 1 GETTING STARTED. SYS-ED/ Computer Education Techniques, Inc.

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview

Practical Programming Methodology

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

Welcome to CSE131b: Compiler Construction

BASICS OF THE RENESAS SYNERGY TM

Exercise Session 6 Computer Architecture and Systems Programming

Chapter 4: Threads. Chapter 4: Threads

Laboratorio di Tecnologie dell'informazione

The CS-220 Development Environment

OpenACC Course. Office Hour #2 Q&A

Lecture Topics. Administrivia

Lectures 5-6: Introduction to C

Slide Set 5. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Performance Evaluation of ISO C restrict on the Power Architecture

The ICE Language and Compiler: Manual and Tutorial. By: Fady Ghanim, Uzi Vishkin, and Rajeev Barua

Lecture 1: Overview of Java

EL2310 Scientific Programming

Chapter 2: Operating-System Structures

Outline Background Jaluna-1 Presentation Jaluna-2 Presentation Overview Use Cases Architecture Features Copyright Jaluna SA. All rights reserved

CHAPTER 2: SYSTEM STRUCTURES. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview

Chapter 4: Multithreaded

Lecture 3: Instruction Set Architecture

Continue: How do I learn C? C Primer Continued (Makefiles, debugging, and more ) Last Time: A Simple(st) C Program 1-hello-world.c!

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

Introducing LLDB for Linux on Arm and AArch64. Omair Javaid

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3

Concurrent Programming

Programming Studio #9 ECE 190

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

A tale of ELFs and DWARFs

Chapter 4: Threads. Operating System Concepts 9 th Edition

Chapter 4: Threads. Chapter 4: Threads

Transcription:

Using the Go Programming Language in Practice Erik Westrup & Fredrik Pettersson Department of Computer Science, Lund University Axis Communications, Sweden May 28, 2014 Supervisors: Jonas Skeppstedt <jonas.skeppstedt@cs.lth.se> (also Examiner) Mathias Bruce <mathias.bruce@axis.com> Robert Rosengren <robert.rosengren@axis.com>

Authors Erik Westrup <erik.westrup@gmail.com> M.Sc. in Computer Science & Engineering, Lund University 2009 From: Ljunghusen, Sweden $EDITOR=vim $BROWSER=firefox+pentadactyl colorscheme=solarized Fredrik Pettersson <fredrik.pettersson.89@gmail.com> M.Sc. in Computer Science & Engineering, Lund University 2009 From: Halmstad, Sweden $EDITOR=sublime2 $BROWSER=chromium colorscheme=solarized

Table of Contents Introduction Approach Discussion Conclusions

Introduction

Outline Introduction to Go Designed by: Ken Thompson, Rob Pike et al. at Google Appeared in 2009 Open source

Outline Introduction to Go Designed by: Ken Thompson, Rob Pike et al. at Google Appeared in 2009 Open source

Outline Introduction to Go Designed by: Ken Thompson, Rob Pike et al. at Google Appeared in 2009 Open source Meets large-scale dev. problems including: long build times uncontrolled dependencies hard to understand code

Outline Purpose & Goals Review of Go + tools Go for embedded programming? How to review a language?

Outline Problem Formulation

Outline Problem Formulation Go Easy to learn? Mature? Future?

Outline Problem Formulation Go Easy to learn? Mature? Future? Building & Compiling Easy? Fast? Avoid tools like Makefiles? Cross-compilation C-integration?

Outline Problem Formulation Go Easy to learn? Mature? Future? Development tools? Software Product & Development Qualities? Building & Compiling Easy? Fast? Avoid tools like Makefiles? Cross-compilation C-integration?

Approach

The Go Programming Language Language design goals

The Go Programming Language Language design goals Features Simple specification Easy to understand code C-like syntax Compiled & statically typed Type inference

The Go Programming Language Language design goals Features Simple specification Easy to understand code C-like syntax Compiled & statically typed Type inference OOP: interfaces, structs & composition Concurrency: goroutines & channels Garbage collection

The Go Programming Language Language design goals Features Simple specification Easy to understand code C-like syntax Compiled & statically typed Type inference OOP: interfaces, structs & composition Concurrency: goroutines & channels Garbage collection Lack of Features Type-orientation: inheritance Generics Exceptions Fat standard library Pointer arithmetic

The Go Programming Language Hello, world 1 package main 2 3 import " fmt " 4 5 func main ( ) { 6 fmt. P r i n t l n ( " Hello, World! " ) 7 }

The Go Programming Language Types 1 v a r i i n t 2 v a r s [ ] b o o l 3 v a r m map [ i n t ] s t r i n g 4 f := 3.14

The Go Programming Language Declaration order C, inside-out: t y p e d e f char ( ( f u n c _ c o l l e c t i o n [ 1 ] ) ) ( i n t ) ;

The Go Programming Language Declaration order C, inside-out: t y p e d e f char ( ( f u n c _ c o l l e c t i o n [ 1 ] ) ) ( i n t ) ; Go, left-to-right: type f u n c C o l l e c t i o n [ 1 ] ( func ( i n t ) s t r i n g )

The Go Programming Language Multiple return values & errors 1 func check ( i n p u t s t r i n g ) ( r e s u l t s t r i n g, e r r e r r o r ) { 2 e r r =... 3 r e s u l t =... 4 r e t u r n 5 }

The Go Programming Language Structs & Method receivers 1 type Object s t r u c t { 2 name s t r i n g 3 } 4 5 func ( o Object ) S t r i n g ( ) s t r i n g { 6 r e t u r n fmt. S p r i n t f ( " Object %s ", o. name ) 7 }

The Go Programming Language Interfaces 1 type S t r i n g e r i n t e r f a c e { 2 S t r i n g ( ) s t r i n g 3 }

The Go Programming Language Composition with struct-embedding 1 type B s t r u c t { 2 bdata i n t 3 } 4 5 type A s t r u c t { 6 adata i n t 7 B 8 } 9 10 func ( b B) o p e r a t e ( ) { 11 }

Concurrency goroutines Lightweight threads Multiplexed into OS threads go work ( )

Concurrency Channels For goroutine communication Declared for a given type Synchronized or asynchronized Replaces semaphores/mutexes 1 v a r c h a n n e l chan i n t 2 c h a n n e l < 8 // Send 3 i := < c h a n n e l // R e c e i v e

Developer tools Go tools $ go h e l p Go i s a t o o l f o r managing Go s o u r c e code. Usage : go command [ arguments ] The commands a r e : b u i l d c o m p i l e packages & d e p e n d e n c i e s fmt run gofmt on package s o u r c e s get download & i n s t a l l packages & d e p e n d e n c i e s t e s t t e s t packages......

Developer tools Building Easy to use Automated Smart dependency resolution The environment $ go b u i l d <package>

Developer tools gc vs gccgo

Developer tools gc vs gccgo gc (Go Compiler) Default compiler Ideas from Plan 9 compilers OSes: Linux, FreeBSD, OS X, Windows Architectures: i386, amd64, arm

Developer tools gc vs gccgo gc (Go Compiler) Default compiler Ideas from Plan 9 compilers OSes: Linux, FreeBSD, OS X, Windows Architectures: i386, amd64, arm gccgo Front-end for GCC OSes: Linux, BSD, OS X, Windows, IRIX, Solaris Architectures: i386, x86_64, amd64, arm, arm64, mips, alpha, m68k, powerpc, sparc

Developer tools Cross-compiling with gccgo Building x-gccgo As easy as building x-compiler for C

Developer tools Cross-compiling with gccgo Building x-gccgo As easy as building x-compiler for C Building x-compiler is very challenging

Developer tools Cross-compiling with gccgo Building x-gccgo As easy as building x-compiler for C Building x-compiler is very challenging Helper tools currently problematic Built a 4.9 GCC x-toolchain.

Developer tools Cross-compiling with gccgo Building x-gccgo As easy as building x-compiler for C Building x-compiler is very challenging Helper tools currently problematic Built a 4.9 GCC x-toolchain. Go + gccgo Unresolved issue

Developer tools C-Integration Tool: cgo Go-code: C-code & compiler directives in comments Can use C-symbols Can convert C Go types C-code: Can use Go-symbols

Developer tools C-Integration Tool: cgo Go-code: C-code & compiler directives in comments Can use C-symbols Can convert C Go types C-code: Can use Go-symbols Problems: Callbacks, pointers, macros etc.

Developer tools Debugging GDB works, bad goroutine & core dump support Uncertain GDB future Go-specific debugger?

Developer tools Other tools Many good tools exists: Built-in: Testing Documentation Code formatter Package manager Text editors & IDEs Convenient tools

Discussion

The Go Programming Language Design Goals Less is exponentially more Rob Pike

The Go Programming Language How did it turn out? U Well afterthought language d Flexible OOP U UGenerics: Necessary? Awesome concurrency model

Developer Tools Building U D Zero project startup cost U Less control & understandability D Better in the long run Warnings = Errors

Developer Tools gc vs gccgo

Developer Tools gc vs gccgo gc U Up-to-date Fast D Few architectures Only static linking

Developer Tools gc vs gccgo gc U Up-to-date Fast D Few architectures Only static linking U gccgo Supports many platforms D Slower U Dynamic linking D Different release schedule

Developer Tools Cross-Compilation D Uncertain Go + gccgo combination LLVM is the future?

Developer Tools C-Integration U Works well in simple cases Code in comments Locating errors D Wrapper-functions Slower builds

Developer Tools Other Tools U Simplifies development D No version support Package manager U D Testing & documentation State of debugging

Community & Future Community U Contributes to Go & tools U Friendly & helpful U Lead developers participate

Community & Future Future of Go U Stabilization/optimization of tools D Embedded programming: mild interest

Community & Future Future of Go U Stabilization/optimization of tools D Embedded programming: mild interest Google goes, Go goes? Competing languages?

Reviewing a Programming Language Worth Doing a Project?

Reviewing a Programming Language Worth Doing a Project? Yes! (if relevant & restricted) Reveals the true nature

Conclusions

Summary Summary U Easy to learn & adopt U Suitable for large-scale projects U Concurrency

Summary Summary Easy to learn & adopt U Suitable for large-scale projects Concurrency D Complicated C-integration U Cross-compilation with go + gccgo Reviewing languages larger project

Summary Summary Easy to learn & adopt U Suitable for large-scale projects Concurrency D Complicated C-integration U Cross-compilation with go + gccgo Reviewing languages larger project Go for Embedded? Wait a while

Summary Summary Easy to learn & adopt U Suitable for large-scale projects Concurrency D Complicated C-integration U Cross-compilation with go + gccgo Reviewing languages larger project Go for Embedded? Wait a while

Future Research Future Research Effectiveness of goroutines gc & gccgo optimization & compilation speed comparison Debugging Memory profiling + C-integration

Learn Go Have a couple of hours to spare? Learn Go! tour.golang.org

Learn Go Have a couple of hours to spare? Learn Go! tour.golang.org Download our thesis @ bit.ly/go-thesis