github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2014/droidcon.slide (about)

     1  Go on Android
     2  A preview
     3  
     4  DroidCon
     5  20 Sep 2014
     6  
     7  David Crawshaw
     8  Google
     9  @davidcrawshaw
    10  
    11  * A brief introduction to Go
    12  
    13  * What is Go
    14  
    15  Go is a general purpose programming language.
    16  
    17  Born out of frustration with C++ and Java:
    18  - Slow builds
    19  - Too much complexity
    20  
    21  Go is fast and simple.
    22  
    23  More at: [[https://talks.golang.org/2012/splash.article]]
    24  
    25  * Five years later
    26  
    27  Go is not driven by a platform.
    28  Sinks or swims on its own merits.
    29  
    30  .image droidcon/gopherswim.jpg
    31  
    32  Many users, e.g.
    33  SoundCloud, Docker, Secret, The New York Times
    34  
    35  "The cloud programming language."
    36  
    37  * Beyond Cloud
    38  
    39  Go has found other uses.
    40  
    41  Popular on embedded linux systems.
    42  PayPal's Beacon hardware is powered by Go.
    43  
    44  Large-scale data analysis.
    45  
    46  For many of us, it replaces python/perl/ruby.
    47  
    48  Where else can we use Go?
    49  What about phones and tablets?
    50  
    51  * Go on Android
    52  
    53  Android UI programming needs lots of Java APIs.
    54  My first experiment was using these from Go.
    55  
    56  It did not work.
    57  Using Java APIs in Go is writing Java using Go syntax.
    58  
    59  "You can write FORTRAN in any language"
    60  
    61  So does it ever make sense to use Go on Android?
    62  Yes, for portability.
    63  
    64  * Portability
    65  
    66  Lots of apps are written for more than just Android.
    67  Some apps start elsewhere and never make it to Android.
    68  
    69  :-(
    70  
    71  Today, developers solve platform portability with C++.
    72  We can do better.
    73  
    74  * Two ways to use Go
    75  
    76  1. Write libraries in Go, use them from Java apps. Or Objective-C/Swift apps.
    77  
    78  2. Write apps entirely in Go, restricted to a set of common APIs across platforms.
    79  
    80  .image droidcon/gopherswrench.jpg
    81  
    82  * Go libraries for apps
    83  
    84  * Cross language interfaces
    85  
    86  Java is a silo.
    87  
    88  To use another language, you need JNI.
    89  JNI is tricky, buggy, painful.
    90  It keeps Java programmers away from many good things.
    91  
    92  So, no JNI.
    93  
    94  Instead, we have a tool for that: `gobind`
    95  It generates Java interfaces for you.
    96  
    97  [[http://golang.org/s/gobind]]
    98  
    99  * gobind basics
   100  
   101  	package hi
   102  
   103  	import "fmt"
   104  
   105  	func Hello(name string) {
   106  		fmt.Println("Hello, %s!\n", name)
   107  	}
   108  
   109  Use `gobind` on package `hi` to generate Go helper code and a Java interface:
   110  
   111  
   112  	package go;
   113  
   114  	public abstract class Hi {
   115  		public static final void Hello(String name) { .. }
   116  	}
   117  
   118  Invoke from Java:
   119  
   120  	Hi.Hello("DroidCon")
   121  
   122  * gobind features
   123  
   124  Today, gobind supports many basic Go types, structs, and callbacks.
   125  
   126  When finished, `gobind` will support *all* Go types.
   127  
   128  Go's simplicity makes language bindings simple.
   129  For C++, SWIG has many hard-to-use features.
   130  
   131  With Go we get configuration-free language bindings.
   132  SWIG without the .swig files.
   133  
   134  * All-Go apps
   135  
   136  * NDK-style interfaces
   137  
   138  Go will have common libraries:
   139  
   140  - Touch events
   141  - OpenGL
   142  - Basic app management
   143  
   144  In general: if it works on the NDK and iOS, it works in Go.
   145  
   146  * Games
   147  
   148  The primary target for pure Go apps is games.
   149  
   150  Better control over over allocation means fewer
   151  garbage collector problems.
   152  
   153  Unlikely language for high-budget 3D engines.
   154  But lots of games can be written in Go.
   155  
   156  But we are building a 2D sprite package.
   157  
   158  * Status: 2014
   159  
   160  Android OS support will be built into the Go runtime in the December 1.4 release.
   161  
   162  First version available from the `go.mobile` subrepository of
   163  
   164  - `gobind`
   165  - OpenGL ES 2 bindings
   166  - touch events package
   167  - limited android build integration
   168  
   169  Sprite library will be in early testing.
   170  
   171  Setup will still be a little trickier than I want, but it will work.
   172  
   173  * Demo
   174  
   175  * Roadmap: mid-2015
   176  
   177  The plan is iOS support will be in the Go runtime July 1.5 release.
   178  
   179  The same OpenGL bindings and touch events package will work. The `gobind` tool will generate Objective-C/Swift bindings.
   180  
   181  Sprite will be ready for 2D games.
   182  
   183  * Questions
   184  
   185  * Backup slides
   186  
   187  * Go compared to Java
   188  
   189  - pointers
   190  - generate less garbage
   191  
   192  	type Point struct {
   193  		X float64
   194  		Y float64
   195  	}
   196  
   197  	type Points []Point
   198  
   199  - `map[int]int` is efficient like `android.os.SparseIntArray`
   200  - `map[int]float32` is efficient like `android.os.?`
   201  - focus on functions, simplicity
   202  - native binaries
   203  
   204  More at: [[https://talks.golang.org/2014/go4java.slide]]