Après la présentation de #Flutter, Julien nous révèle toute la puissance de #Go, encore un autre langage de programmation créé par Google.
After the #Flutter presentation, Julien reveals all the power of #Go, yet another programming language created by Google.
4. History
PRESENTATION
12
X
• Designed at Google in 2007
• Publicly announced in November 2009, version 1.0 was released in
March 2012
• Version 1.12 released on February 2019
• Version 2.0 in discussion
5. Creators
PRESENTATION
12
X
• Robert Griesemer (Java HotSpot virtual machine, V8 Js engine)
• Rob Pike (wrote the first window system for Unix, worked on UTF-8)
• Ken Thompson (implemented the original Unix operating system,
invented the B programming language, worked on UTF-8)
6. Why
PRESENTATION
12
X
• Computing landscape today is almost unrelated to the environment in
which the languages being used, mostly C++, Java, and Python, had
been created: multicore processors, networked systems, massive
computation clusters, …
• Scale has changed: today’s server programs comprise tens of millions
of lines of code, are worked on by hundreds or even thousands of
programmers, and are updated literally every day
• Build times, even on large compilation clusters, have stretched to
many minutes, even hours
9. GUIDINGPRINCIPLES
11
X
• Go must work at scale, for large teams of programmers working
on them, for programs with large numbers of dependencies
• Go must be familiar, roughly C-like. Google needs to get
programmers productive quickly in Go, means that the
language cannot be too radical
• Go must be modern. It should have features like concurrency
so that programs can make efficient use of multi core machines.
It should have built-in networking and web server libraries so
that it aids modern development
Go must solve these problems
10. GUIDINGPRINCIPLES
11
X
Software engineering is what happens to programming when you add
time and other programmers.
— Russ Cox
• Software programming: program you write for yourself
• Software engineering: product that many people will
work on over time
Engineers will come and go, teams will grow and shrink,
requirements will change, features will be added and bugs fixed.
11. GUIDINGPRINCIPLES
Simplicity
• "I can’t understand this
code”
• You’re scared to make a
change because you’re
worried it’ll break another
part of the program
• A part you don’t
understand and don’t
know how to fix
11
X
Simplicity is prerequisite for
reliability.
— Edsger W. Dijkstra
12. GUIDINGPRINCIPLES
11
X
There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the other
way is to make it so complicated that there are no obvious deficiencies.
The first method is far more difficult.
— C. A. R. Hoare
Complexity turns reliable software in unreliable software.
Complexity is what kills software projects.
Therefore simplicity is the highest goal of Go.
Whatever programs we write, we should be able to agree
that they are simple.
13. GUIDINGPRINCIPLES
Readability
We should strive for
readability
Readability is important
because all software is
written by humans to be read
by other humans.
Code is read many more
times than it is written. A
piece of code will, over its
lifetime, be read hundreds,
thousands of times.
11
X
Readability is essential for
maintainability.
— Mark Reinhold
Programs must be written for people
to read, and only incidentally for
machines to execute.
— Hal Abelson and Gerald Sussman
14. GUIDINGPRINCIPLES
11
X
The most important skill for a programmer is the ability to effectively
communicate ideas.
— Gastón Jorquera
If you can’t understand what a program is doing, how can
you hope to maintain it?
A piece of software that more than one person will
contribute to, or that will be used by people over a long
enough time that requirements or features changes, then
your goal must be for your program to be maintainable.
15. GUIDINGPRINCIPLES
11
X
The first step towards writing maintainable code is making
sure the code is readable.
Use the bloody brackets for fuck’s sake!
16. GUIDINGPRINCIPLES
Productivity
How much time do you
spend doing useful work
versus waiting for your tools,
or hopelessly lost in a foreign
code-base?
11
X
Design is the art of arranging code
to work today, and be changeable
forever.
— Sandi Metz
17. GUIDINGPRINCIPLES
11
X
Go was designed while waiting for a C++ program to compile.
— Go developer humour
Fast compilation is a key feature of Go.
Compilations which take minutes in other languages, take
seconds in Go
Go programmers realise that code is written to be read and
so place the act of reading code above the act of writing it.
• Tooling enforces that all code be formatted in a specific
style
18. GUIDINGPRINCIPLES
11
X
Go programmers don’t spend days debugging inscrutable
compile errors. They don’t waste days with complicated
build scripts or deploying code to production. And most
importantly they don’t spend their time trying to understand
what their coworker wrote.
Productivity is what the Go team mean when they say the
language must scale.
22. Statically typed
FEATURES
12
X
• Static typing and run-time efficiency (like C++ or Java)
• Non-strict typing (type inference)
// Initialised with 0 value
var str string
// Type inference
var i = 42
// Short syntax
isJeanAFanboy := true
24. Built in support for concurrency
FEATURES
12
X
Goroutines
• Lightweight thread of execution
• Go runtime multiplexes those goroutines over operating
system threads
• Multiple goroutines can run concurrently on a single
OS thread
Concurrency is about dealing with lots of things at once. Parallelism
is about doing lots of things at once.
26. Peculiar object-oriented model
FEATURES
12
X
• Composition only
• Structs types with methods
Interface system
• Enable loosely coupled systems
• Simply defined as set of functions
• Any type which implements those functions implicitly
implements the interface
27. No exceptions, handle errors yourself
FEATURES
12
X
• Forces developers to handle basic errors (no more
TODO we should handle this, probably)
• Classic go code:
beer, err := grabBeer('IPA')
if err != nil {
logger.warn('no more beer')
return err
}
// Use the beer
28. Great built-in libraries
FEATURES
12
X
• net/http: Provides HTTP client and server
implementations
• database/sql: For interaction with SQL databases
• encoding/json: JSON is treated as a first class
member of the standard language
• html/templates: HTML templating library
• io/utils: Implements I/O utility functions
• Testing: Automated testing
29. Good tooling
FEATURES
12
X
• GoFMT: automatically formats and indents your code
• Go run: compiles your code and runs it
• Godoc: equivalent of javadoc
31. Lack of generics
WEAKNESSES
14
X
• Would complexifies the language
• Increases execution or compilation time
• Often mis-used or over-used (needless abstraction)
• Useful to avoid code duplication
• Avoid hacks with the Interface (“Any”) type
Pros
Cons
In discussion for go 2
32. Tedious error handling
WEAKNESSES
14
X
In discussion for go 2
• Lot of repetition
• No typed error in standard library
err := doSomething()
if err != nil {
// handle the error here
}
func doSomething() error {
err := someMethod()
if err != nil {
return err
}
err = someOther()
if err != nil {
return err
}
someOtherMethod()
}
34. GOPATH
WEAKNESSES
14
X
• Dependencies management was not part of the language before
v1.11
• Third-Party libs were available, the main one being dep
• Dep was used by a large number of people, but Go main
maintainers decided to go with a completely new implementation
they unveiled out of the blue (not cool.)
Dependency management
Before v1.11 you had to place all your go projects in the same
repository that was the same one used to checkout libs from
GitHub
35. Not very good for functional programming
WEAKNESSES
14
X
• No clone function
• Pointers and references
• Lacks immutability for all but a few (native) types
• Arrays and slices shares the same memory space
38. CONCLUSION
12
X
• "Gets the job done” type of language
• Easy to learn
• Fun despite its limited C-like syntax
• Focuses on readability and maintainability
• Excels in concurrency and speed
• Has a lot of room for growth and improvement