brainsteam.co.uk/brainsteam/content/posts/legacy/2018-01-27-how-i-became-a-g...

110 lines
12 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: How I became a gopher over christmas
author: James
type: post
date: 2018-01-27T10:09:34+00:00
url: /2018/01/27/how-i-became-a-gopher/
medium_post:
- 'O:11:"Medium_Post":11:{s:16:"author_image_url";s:69:"https://cdn-images-1.medium.com/fit/c/200/200/0*naYvMn9xdbL5qlkJ.jpeg";s:10:"author_url";s:30:"https://medium.com/@jamesravey";s:11:"byline_name";N;s:12:"byline_email";N;s:10:"cross_link";s:2:"no";s:2:"id";s:12:"452cd617afb4";s:21:"follower_notification";s:3:"yes";s:7:"license";s:19:"all-rights-reserved";s:14:"publication_id";s:2:"-1";s:6:"status";s:6:"public";s:3:"url";s:95:"https://medium.com/@jamesravey/how-i-became-a-gopher-and-learned-myself-an-angular-452cd617afb4";}'
categories:
- Work
tags:
- chatbots
- filament
- golang
---
Happy new year to one and all. It’s been a while since I posted and life continues onwards at a crazy pace. I meant to publish this post just after Christmas but have only found time to sit down and write now.
If anyone is wondering what’s with the crazy title – a gopher is someone who practices the Go programming language (just as those who write in Python refer to themselves as pythonistas. There’s an interesting list of labels that programmers self-assign [here][1] if you’re interested).
Over Christmas I decided I was going to have a break from working as a [CTO][2] and a [PhD student][3] in order to do something relaxing. That’s why I thought I’d teach myself a new programming language. I also taught myself how to use Angular.js too but I’ll probably write about that separately.
## Go Go Gadget… keyboard?
First on my list is the Go programming language. I decided that I would spend 2 weeks over xmas (in between playing with my nintendo switch and of course spending time with my lovely fiancee and our families) building something useful and practical in the language because if there’s one thing I can’t stand its trying to learn to use a programming language by writing yet another [todo list.][4]
<figure id="attachment_233" aria-describedby="caption-attachment-233" style="width: 221px" class="wp-caption alignright"><img loading="lazy" class="wp-image-233 size-medium" src="https://i2.wp.com/brainsteam.co.uk/wp-content/uploads/2018/01/Screenshot-from-2018-01-27-09-17-40.png?resize=221%2C300&#038;ssl=1" alt="" width="221" height="300" srcset="https://i2.wp.com/brainsteam.co.uk/wp-content/uploads/2018/01/Screenshot-from-2018-01-27-09-17-40.png?resize=221%2C300&ssl=1 221w, https://i2.wp.com/brainsteam.co.uk/wp-content/uploads/2018/01/Screenshot-from-2018-01-27-09-17-40.png?w=622&ssl=1 622w" sizes="(max-width: 221px) 100vw, 221px" data-recalc-dims="1" /><figcaption id="caption-attachment-233" class="wp-caption-text">Chatty Cathy &#8211; she&#8217;s still very much a work in progress</figcaption></figure>
At Filament, we are fast becoming one of the UK&#8217;s leading chat-bot providers, working with brands like T-Mobile and Hiscox insurance. We have an excellent team of chat-bot builders run by our very own Mr Chat-bot, [Rory][5] and supported by  a very stringent but also very manual QA process. I decided I was going to try and help the team work smarter by building a PoC chatbot testing framework.
The general gist of my tool, named Chatty Cathy, is that I can &#8220;record&#8221; a conversation with a bot, go make some changes to the intents and flows and then &#8220;playback&#8221; my conversation to make sure the bot still responds in the way I&#8217;d like.
## Why Go?
<figure id="attachment_234" aria-describedby="caption-attachment-234" style="width: 300px" class="wp-caption alignleft"><img loading="lazy" class="wp-image-234 size-medium" src="https://i1.wp.com/brainsteam.co.uk/wp-content/uploads/2018/01/Gopher-2400px.png?resize=300%2C168&#038;ssl=1" alt="" width="300" height="168" srcset="https://i1.wp.com/brainsteam.co.uk/wp-content/uploads/2018/01/Gopher-2400px.png?resize=300%2C168&ssl=1 300w, https://i1.wp.com/brainsteam.co.uk/wp-content/uploads/2018/01/Gopher-2400px.png?resize=768%2C430&ssl=1 768w, https://i1.wp.com/brainsteam.co.uk/wp-content/uploads/2018/01/Gopher-2400px.png?resize=1024%2C574&ssl=1 1024w, https://i1.wp.com/brainsteam.co.uk/wp-content/uploads/2018/01/Gopher-2400px.png?w=1320&ssl=1 1320w, https://i1.wp.com/brainsteam.co.uk/wp-content/uploads/2018/01/Gopher-2400px.png?w=1980&ssl=1 1980w" sizes="(max-width: 300px) 100vw, 300px" data-recalc-dims="1" /><figcaption id="caption-attachment-234" class="wp-caption-text">Gophers are pretty cool!</figcaption></figure>
If you hadn&#8217;t gathered, I&#8217;m in to performance-sensitive compute applications: AI, statistical modelling, machine learning, natural language processing. All of these things need a lot of juice. We&#8217;re also in the business of writing large-scale web applications that serve these kinds of machine learning models to huge numbers of users. I love python and node.js as much as the next man but most machine learning applications that have interfaces in those languages are written in something low level (C or C++) and bound to these higher level languages for ease of use. I know that Go is still higher level than C or something like Rust* but it outperforms all of the interpreted languages and Java in the [Benchmark Games][6] and is very easy to learn (see below). It is this trade-off relatively-high-performance-versus-ease-of-use that has me so excited.
*Incidentally I spent some time last year working in Rust and even though I loved it, found it very hard going  &#8211; I&#8217;ve been following [Julia Evans&#8217; Ruby Profiler][7] project and it&#8217;s got me excited about Rust again so maybe I&#8217;ll dive back in some day soon.
### Pros of Working with Go
<li style="list-style-type: none;">
<ul>
<li>
Go-lang is like a pared down, simplistic dialect of C. You could also think about it as a much simplified Java spin off.
</li>
<li>
The build tool is amazingly simple to use. Everything is done based on filenames and locations. No more over-engineered pom.xml or package.json files.
</li>
<li>
Like Python and node.js, Go has a huge number of &#8220;batteries included&#8221; modules and functions available as part of its standard library. Web applications and JSON are first class citizens in Go-lang and you can build an app that serves up serialized json in ~30 lines of code. (compare that to the 300 lines of code you need just to define your POJOs and your DTOs in Java and you can already see why this is so awesome).
</li>
<li>
Also like <a href="https://pypi.python.org/pypi">Python</a> and <a href="https://www.npmjs.com/">node.js</a> Go has a brilliant ecosystem. One of the perks of coming into existence in the golden age of the internet I guess. Go&#8217;s build tool can automatically grab other projects from git repositories without needing a centralised server like pip/npm/maven which in my eyes makes it even more awesome (no more <a href="https://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/">left pad chaos</a>).
</li>
<li>
Unit testing is also a core part of the language and build tool. Simply adding some files to your library with the suffex _tests.go  running <em>go test </em>is all you need.
</li>
<li>
Go&#8217;s goroutine interface for parallelism is a super exciting feature. Again, having been designed very recently in the age of multi-core processors, the language treats multi-core processing as a first class citizen. Compared to Python which is held back from multi-processing bliss by the<a href="https://wiki.python.org/moin/GlobalInterpreterLock"> GIL </a>and node.js which uses a<a href="https://medium.com/@stevennatera/multithreading-multiprocessing-and-the-nodejs-event-loop-5b2929bd450b"> single event loop.</a>
</li>
<li>
<strong>Biggest pro: learning curve</strong>. For someone who&#8217;s written in any kind of imperative programming language before and has some level of understanding around pointers and referencing, Go is SOOO easy to pick up. I reckon the java developers at our company could be effective in Go within a week or less. (If you&#8217;re reading Rob, Max, Alex, that&#8217;s a challenge). It truly is like Java without the bulls***!
</li>
</ul>
</li>
### Cons of working with Go
* I still find workspaces kind of a strange concept. Instead of checking out one git project and popping it in your $HOME/workspace directory (yes this is a hangover from years of Eclipse development when I was back at big blue), code is stored hierarchically based on where you got it from. For example my workspace looks a bit like this:
<pre>go
└── src
├── github.com
│ ├── author1
│ │ └── project1
│ │ ├── LICENSE.txt
│ │ ├── README.md
│ │ ├── somefile.go
│ │ ├── more.go
│ ├── author2
│ │ └── project2
│ │ ├── LICENSE.txt
│ │ ├── README.md
│ │ ├── somefile.go
│ │ ├── more.go</pre>
Basically, each project gets stored somewhere hierarchically in the tree and all dependencies of your project end up somewhere in here. This can make it a little bit confusing when you&#8217;re working on really large projects but then perhaps this is no more confusing than a python virtualenv or the node_modules directory of a mature node.js app and I&#8217;m being silly?
* Some of the libraries are still a little bit immature. I don&#8217;t mean to be disparaging in any way towards the authors of these open source libraries that are doing a fantastic job for absolutely zero payment. However, a lot of the java tooling we use at work has been in development for 2 (in some cases nearly 3) decades and a lot of the crazier use cases I want to try and do are supported out of the box.
* I&#8217;m still not a massive fan of the way that [struct tag][8] syntax works. Again, perhaps this is because I am a programming luddite but I definitely prefer Java Annotations and Python Decorators a lot more.
### Summary
Go is a really exciting language for me personally but also for many of us still plagued by nightmarish visions of java boilerplate in our sleep. It has a fantastic ecosystem and first-class support for parallel programming and building web services via a really nice set of REST server libraries and JSON serialization libraries that are already built in. There are a few small issues that probably still need addressing but I&#8217;m sure they will come out in the wash.
The most exciting thing for me is how well Go slots into the toolbox of any competent imperative language programmer (e.g. C, C++, Java, Python, Javascript, C#, PHP etc.). Whichever language you come from there are likely to be a few minor changes to get used to but the syntax and concepts are familiar enough that you can be up and running in no time at all!
Is Go ready to be used in prime-time production-ready systems? I definitely think so but if you don&#8217;t believe me, why don&#8217;t you ask [the Docker Foundation?][9]
[1]: https://gist.github.com/coolaj86/9256619
[2]: http://filament.uk.com/
[3]: https://www.wisc.warwick.ac.uk/people/student-profiles/2015-intake/james-ravenscroft/
[4]: https://github.com/search?l=JavaScript&q=todo&type=Repositories&utf8=%E2%9C%93
[5]: https://disruptionhub.com/whats-crappy-chatbots/
[6]: http://benchmarksgame.alioth.debian.org/u64q/compare.php?lang=go&lang2=node
[7]: https://jvns.ca/blog/2017/12/02/taking-a-sabbatical-to-work-on-ruby-profiling-tools/
[8]: https://golang.org/ref/spec#Tag
[9]: https://www.slideshare.net/jpetazzo/docker-and-go-why-did-we-decide-to-write-docker-in-go