dotGo 2015 - Rob Pike - Simplicity is Complicated

dotconferences
2 Dec 201523:11

Summary

TLDRIn this talk, the speaker explores the success of the Go programming language, attributing it to its simplicity compared to other complex languages. They discuss the concept of language relativity and its impact on programming, emphasizing the importance of readability and maintainability over language features. The speaker highlights Go's design philosophy, which focuses on long-term maintenance and large-scale programming, and how it balances expressiveness with simplicity. They also touch on the complexities hidden behind Go's simple interface, such as garbage collection, goroutines, constants, interfaces, and packages, illustrating how these contribute to Go's ease of use and popularity.

Takeaways

  • 😀 The speaker humorously translates 'Bonjour Madame de Monsieur' into 'Hello my waffles', setting a light-hearted tone for the discussion on the Go programming language.
  • 🌟 Go's success is attributed to its simplicity, which contrasts with the complexity and feature bloat seen in other programming languages.
  • 🔍 The speaker criticizes the trend of languages borrowing features from one another, leading to a convergence that could limit diverse problem-solving approaches.
  • 🎯 Go's design philosophy prioritizes readability and maintainability over adding features for the sake of expressiveness or novelty.
  • đŸ› ïž The language's creators, including Ken Thompson and Robert Griesemer, insisted on a consensus for including features, ensuring they were both necessary and appropriate.
  • đŸš« Go deliberately avoids adding features that do not enhance the language's core goals, such as long-term maintenance and infrastructure software development.
  • 💡 The speaker emphasizes that simplicity in programming languages is about hiding complexity behind a simple interface, making the language easy to use without sacrificing power.
  • 🔗 Go's features like garbage collection, goroutines, and interfaces are examples of simplicity on the surface hiding complex implementations.
  • 📩 Packages in Go are a model of simplicity, abstracting away the complexities of cross-compiling and linking while providing a straightforward import system.
  • 🌐 The design of Go reflects a commitment to solving real-world problems at scale, particularly in the context of cloud and server infrastructure.

Q & A

  • What is the main reason behind Go's success according to the speaker?

    -The speaker believes the main reason behind Go's success is its simplicity compared to other languages. This simplicity is not just a superficial feature but a core design principle that makes Go stand out.

  • What does the speaker think about the trend of languages adding features from other languages?

    -The speaker is concerned that many languages are converging into a similar model by borrowing features from one another, which could lead to a homogenization of thought in programming and less interesting solutions.

  • What is the Sapir-Whorf hypothesis as mentioned in the script?

    -The Sapir-Whorf hypothesis, also known as linguistic relativity, suggests that the language one speaks influences the way one thinks. The speaker uses this concept to argue that different programming languages should encourage different ways of thinking.

  • Why did the creators of Go decide to fix the language after Go 1?

    -The creators of Go decided to fix the language after Go 1 to prevent it from becoming bloated and to maintain its simplicity. They believed that adding more features would not improve the language but would make it less distinct.

  • What was the guiding principle behind selecting features for Go?

    -The guiding principle behind selecting features for Go was readability. The creators wanted a language that was easy to read and understand, which would lead to more reliable and maintainable code.

  • How does the speaker view the trade-off between language expressiveness and simplicity?

    -The speaker believes there is a fundamental trade-off between making a language fun to write in and making it easier to work on and maintain. Go chose the latter, focusing on long-term maintainability and readability.

  • What does the speaker mean when he says 'simplicity is the art of hiding complexity'?

    -The speaker means that while the surface-level features and usage of Go are simple, a lot of complex design, implementation, and refinement has gone into making it feel that way. The complexity is hidden from the user.

  • Why did the Go team decide against adding built-in map and filter functions?

    -The Go team decided against adding built-in map and filter functions because they might be more computationally expensive than a simple for loop and could lead to less efficient code by encouraging their use.

  • How does the speaker describe the concurrency model in Go?

    -The speaker describes the concurrency model in Go as one of the simplest available, using go routines, channels, and select to handle concurrency in a straightforward manner.

  • What is the speaker's view on constants in Go?

    -The speaker views constants in Go as a favorite feature, appreciating how they are treated just like numbers despite the language being strictly typed, which simplifies code without sacrificing type safety.

  • Why did the design of Go's package system take a long time for the creators?

    -Designing Go's package system was challenging because it interacts with various aspects like scoping, naming, information hiding, isolation, linking, compiling, and cross-compiling, making it a complex system to get right.

Outlines

00:00

🌐 The Simplicity of Go

The speaker begins by humorously translating 'Bonjour Madame de Monsieur' into 'hello my waffles' to illustrate the simplicity that makes Go successful. They argue that Go's success is not due to superficial factors like tooling or language features, but rather its simplicity compared to other languages. The speaker reflects on a Microsoft conference where they observed a trend of languages borrowing features from one another, leading to a convergence that could potentially limit diverse problem-solving approaches. They express concern about this trend, advocating for maintaining different languages to foster varied ways of thinking and problem-solving.

05:00

🔍 The Importance of Readability

The speaker emphasizes that Go's design philosophy prioritizes readability over feature richness. They argue that languages with too many features can complicate programming, as developers spend time considering which features to use and later must retrace their thought processes. This complexity hinders code understanding and maintenance. The speaker advocates for simplicity, suggesting that readable code equates to reliable code, facilitating easier comprehension, extension, and debugging. They contrast Go's approach with other languages that add features for expressiveness or fun, which can lead to less efficient solutions and more verbose code.

10:01

🛠 Balancing Expressiveness and Simplicity

The speaker discusses the challenge of balancing expressiveness with simplicity in language design. They use the example of APL, a language where programs are concise but hard to read, to illustrate the risks of prioritizing expressiveness over readability. The speaker suggests that features should be added judiciously to a language, ensuring they are orthogonal and do not introduce unnecessary complexity. They also touch on the idea that simplicity can be achieved by hiding complexity behind straightforward interfaces, as seen in Go's design.

15:01

🔄 The Complexity Behind Go's Features

The speaker delves into the complexity hidden behind Go's simple features, such as garbage collection, goroutines, constants, interfaces, and packages. They explain that while these features have simple interfaces for the programmer, their implementation is intricate and requires careful design. For instance, Go's garbage collection has no user interface but involves complex mechanisms. Similarly, goroutines, constants, interfaces, and packages are simple to use but involve complex rules and interactions. The speaker argues that this careful balancing of simplicity and complexity is what makes Go both powerful and easy to use.

20:02

🌟 Simplicity as a Design Goal

In the final paragraph, the speaker reiterates that simplicity is a complex goal to achieve in language design. They use the 'hello world' server example to show how Go enables writing concise, production-ready code that is also truly concurrent and efficient. The speaker concludes by emphasizing that while simplicity is hard to design and implement, it results in clarity and ease of use, which are central to Go's success. They express a preference for the simplicity and expressiveness of Go over more complex alternatives.

Mindmap

Keywords

💡Simplicity

Simplicity in the context of the video refers to the design philosophy of the Go programming language, which emphasizes ease of use and minimalism. The speaker argues that Go's success is due to its simplicity compared to other complex programming languages. Simplicity here means having a clear, understandable, and straightforward syntax and feature set, which allows developers to focus on solving problems without getting bogged down by the language's intricacies. For instance, the speaker mentions that Go's garbage collection and concurrency model are designed to be simple to use, hiding the complexity behind the scenes.

💡Gofer

The term 'gofer' is humorously used in the video as a play on words with 'gopher,' which is the mascot of the Go programming language. It's used in the script's opening as a light-hearted jab at language translation, where 'Bonjour Madame de Monsieur or assume a, gofer' is humorously translated as 'Hello my waffles.' This sets a tone of approachability and friendliness towards the language and its community.

💡Language Relativity

Language relativity, also known as the Sapir-Whorf hypothesis, is mentioned to discuss how different programming languages can influence the way programmers think and solve problems. The video suggests that as various programming languages borrow features from one another, they risk becoming too similar, which could lead to a homogenization of thought in programming. This concept is used to highlight the importance of having diverse programming languages, each with its unique way of approaching problem-solving.

💡Bloat

Bloat in the video refers to the trend of programming languages becoming increasingly complex by continuously adding new features. The speaker criticizes this trend as it leads to languages becoming more complicated without necessarily improving their core utility. This bloat can make languages harder to learn, maintain, and use effectively, contrasting with Go's approach of maintaining a small, fixed set of features to keep the language simple and focused.

💡Readability

Readability is a central theme in the video, emphasizing the importance of writing code that is easy to understand. The speaker argues that a programming language should prioritize readability because it leads to more reliable and maintainable code. Go's design philosophy includes features that enhance readability, such as a clean syntax and a straightforward approach to error handling. The video suggests that readability is the most important feature of a programming language because it affects code maintenance, extendibility, and the ease of debugging.

💡Concurrency

Concurrency in the video is discussed as a fundamental feature of the Go programming language, which allows for the simultaneous execution of multiple tasks. The speaker praises Go's concurrency model as one of the simplest available, achieved through the use of goroutines, channels, and the select statement. This simplicity is exemplified by the ease with which one can start a goroutine with just three keystrokes, showcasing Go's commitment to simplicity in enabling complex programming paradigms.

💡Garbage Collection

Garbage collection is highlighted as a feature of Go that simplifies memory management for developers. The speaker points out that Go's garbage collection has a minimal user interface, with no need for developers to manually manage memory, thus hiding a complex implementation behind a simple concept. This allows developers to focus on writing code without worrying about memory leaks or the efficiency of memory usage, which would be a concern in languages without automatic garbage collection.

💡Constants

Constants in Go are discussed as an example of a feature that feels simple to use but involves complex design decisions. The video explains how Go treats constants as just numbers, which simplifies code by allowing the use of numeric literals without specifying types. This decision, while seemingly straightforward, involves complex rules and considerations under the hood, such as type promotion and precision, to ensure that constants work seamlessly across different contexts.

💡Interfaces

Interfaces in Go are described as a powerful feature that provides a simple way to define contracts for sets of methods. The video notes that interfaces are used extensively in Go to enable a component-oriented architecture, allowing for flexible and reusable code. Despite their simplicity in use, interfaces add a layer of complexity to the language's design, as they must be carefully integrated with Go's type system and runtime behavior. However, their utility in promoting readable and maintainable code makes them a valuable feature.

💡Packages

Packages in the video are presented as a fundamental organizational unit in Go, which simplifies code management, distribution, and reuse. The speaker discusses the design challenges of packages, which must consider various factors like scoping, naming, and cross-compilation. Despite these complexities, packages in Go provide a simple and effective way to import and use code from other libraries, as demonstrated by the ease with which the 'import' keyword is used in the script's example code.

Highlights

Go language's success is attributed to its simplicity compared to other languages.

Simplicity is a complicated subject with many ways to think about it.

Many programming languages are becoming similar by adding features from one another.

Language relativity suggests that language influences thought, which is applicable to programming languages.

Having different programming languages allows for different ways of thinking and solving problems.

Go avoids feature bloat and strives for distinctiveness among programming languages.

Go's designers agreed on features that were not just additions, but the right ones to include.

Readability is the most important feature of a programming language, leading to reliability.

Go's simplicity is a result of careful design to hide complexity.

Garbage collection in Go has a simple interface but is extremely complex under the hood.

Concurrency in Go is one of the simplest models available, exemplified by goroutines.

Constants in Go are numbers, a simple idea with complex implications.

Interfaces in Go are simple sets of methods but have complex rules behind them.

Packages in Go seem simple but involve intricate design considerations.

Go's simplicity is not just about fewer features but about the right selection of features.

The design of Go focuses on long-term maintenance, especially in large-scale programming.

Go's simplicity is a result of months of design and refinement by its creators.

Go's ethos is represented by simple, expressive elements like the gopher image.

The success of Go is evidenced by its large community and adoption.

Transcripts

play00:16

Bonjour Madame de Monsieur or assume a

play00:19

gofer which if I translate I keep

play00:24

laughing of course those who speak

play00:26

French understand that the translation

play00:28

of that is hello my waffles I just

play00:31

learned that this weekend obviously go

play00:34

is successful if you look at this room

play00:35

look at what's going on here yeah and a

play00:38

lot of people have asked why go is

play00:39

successful or I've asked me why go is

play00:42

successful and a lot of people have

play00:44

answers that involve tooling or the

play00:46

language or things about it but I think

play00:48

those are all sort of superficial

play00:49

reasons I think the real reason is

play00:52

simplicity go is simple at least

play00:55

compared to a lot of other languages

play00:57

that are running around at the moment

play00:58

and simplicity is actually a complicated

play01:01

subject and there are many ways to think

play01:03

about it last year about May I think I

play01:07

went to a conference hosted by Microsoft

play01:09

called line got mixed and I saw a number

play01:12

of actually quite interesting talks many

play01:14

of which were the leaders of a

play01:16

particular language talking about a new

play01:18

version that was coming out like

play01:19

JavaScript PHP c-sharp and so on and I

play01:23

really was struck by one thing about

play01:24

these talks and these languages which is

play01:26

most of the talks consisted of features

play01:30

being added by taking something from

play01:32

another language and adding it to this

play01:33

one so you know Java scripts getting

play01:35

classes and that kind of thing and I

play01:37

realized that what's happening is all of

play01:39

these languages are turning into the

play01:41

same language there's a concept called

play01:43

language relativity in linguistics which

play01:45

is also colloquially called the

play01:47

sapir-whorf hypothesis although neither

play01:50

sup you're nor Worf quite agreed with it

play01:53

and the idea is basically that language

play01:55

influences thought and the sort of

play01:57

cartoon version is you know if you speak

play01:59

French you're you're more amorous and

play02:03

it's pretty obviously controversial

play02:05

there's some evidence that there may be

play02:06

some truth but not very much but I think

play02:09

it's really obvious if you think about

play02:10

it that computer languages this very

play02:14

much applies if you're in a logic

play02:15

programming language you write a very

play02:17

different kind of program you think a

play02:18

different way

play02:20

if you're using an object-oriented

play02:21

programming language or concurrent one

play02:23

it's very much like disciplines in

play02:24

mathematics you don't solve calculus

play02:26

using linear algebra even though they

play02:28

have some structural comparisons and so

play02:32

I'm worried about this trend in the

play02:34

languages because they all converge to

play02:35

the same language we're all going to be

play02:37

thinking the same way and that would

play02:38

make life very very uninteresting you

play02:40

want to have different languages for

play02:42

different problems you want to have

play02:44

different domains we solve by different

play02:45

ways of thinking and different notations

play02:47

in other words you kind of want a tool

play02:49

that's optimized for each particular way

play02:51

you're working now these tosit line dot

play02:54

next were about things like Java eight

play02:56

equi script six which has been a long

play02:58

time coming

play02:58

c-sharp C+ was 14 and there few others

play03:01

that didn't quite fit this mold but

play03:02

let's just talk about the ones that do

play03:04

as I said these languages are evolving

play03:07

by adding features that means they're

play03:09

becoming more complicated their

play03:11

complexity is growing while they are

play03:13

simultaneously becoming more similar to

play03:15

one another that's a very strange

play03:17

situation for a field to be in I would

play03:20

summarize that is bloat without

play03:22

distinction go however as I hope you

play03:25

appreciate isn't like that goes a

play03:27

different language in this respect it

play03:30

doesn't try to be like these other

play03:31

languages because it's not taking

play03:34

features it doesn't try to compete by

play03:37

saying oh if they have that feature we

play03:38

better have it or people will be

play03:40

unwilling to use their language in fact

play03:42

as of goal 1 which is what three years

play03:44

old now the language is fixed you know

play03:47

you may have noticed that the features

play03:48

that have gone in since then are

play03:49

absolutely tiny there's really been no

play03:51

significant change to the language since

play03:53

since go one and that was the point of

play03:55

go one however many newcomers to go

play03:58

start by asking can we add this feature

play04:00

of the language can we make error

play04:01

handling different can we change the way

play04:03

arrays work or something like that but

play04:06

the language is fixed those things don't

play04:08

get to go in but it's not just that the

play04:10

language is fixed it's because adding

play04:12

features will not really make go better

play04:14

and why is that true it would just make

play04:17

it bigger but it would make it less

play04:19

different and both of those are worse in

play04:21

my opinion but obviously you need

play04:24

features you can't have a programming

play04:26

language without some features in it but

play04:28

which ones

play04:29

well obviously the right ones and so we

play04:31

picked the right ones how did we pick

play04:33

the right ones well

play04:34

one way is that the original language

play04:36

was designed by Ken Thompson Robert

play04:38

Greer and myself and we all have very

play04:39

different backgrounds Ken and I had

play04:41

worked together at Bell Labs quite a bit

play04:43

but we also had done very different

play04:44

things and you know Ken is the God so

play04:48

when we came to talk about what was

play04:50

going into the language we insisted that

play04:52

all three of us not only agreed with the

play04:55

feature going in but agreed that it was

play04:56

the right feature to go in and with our

play04:58

different backgrounds and our different

play05:00

perspectives that dramatically narrowed

play05:02

the number of things that went into go

play05:05

but you still have to pick what to put

play05:07

in and our overriding thing for doing

play05:10

this was readability and here's how we

play05:13

think about this if a language has too

play05:14

many features or even more than you know

play05:17

you might need you spend time

play05:20

programming thinking about which

play05:21

features to use if there's really a lot

play05:24

of features you may look at the line of

play05:26

code write it one way who I could do

play05:27

something different I could use this

play05:28

feature I use that feature you might

play05:30

even spend you know half an hour playing

play05:32

with a few lines of code to find all the

play05:34

right ways you could use different

play05:35

features to make the code work a certain

play05:37

way and it's kind of a waste of time to

play05:39

do that but worse when you come back to

play05:41

the program later you have to recreate

play05:43

that thought process you not only have

play05:45

to understand this complicated program

play05:47

programming language doing whatever it's

play05:49

doing you have to understand why the

play05:52

programmer who might be you decided that

play05:54

this was the way to approach the problem

play05:56

from the feature set available and that

play05:59

is just I think bad engineering the

play06:02

summary summarization of this is the

play06:04

code is harder to understand simply

play06:07

because it is using a more complex

play06:09

language you want to have just one way

play06:11

or at least fewer simpler easier to

play06:13

understand ways so in other words

play06:15

features add complexity we want

play06:17

simplicity features hurt readability we

play06:19

really want readability and readability

play06:21

is by my opinion the most important

play06:24

feature of a programming language

play06:26

because readable means reliable if you

play06:29

can read the code and know what it means

play06:31

then you can it's easier to understand

play06:33

it's easier to work on it's easier to

play06:35

extend it's easier to fix when it breaks

play06:37

it's easier to understand why it's

play06:38

broken these are all good things

play06:40

and that is why readability is so

play06:42

important if the language is complicated

play06:44

on the other hand you have to understand

play06:46

more 2-under

play06:47

stand even where to start working on the

play06:49

program and you have to understand more

play06:51

complicated model in which the program

play06:53

is being written these cost time and

play06:55

make the language harder to use but

play06:59

there's a trade-off obviously making

play07:01

more features in a language gives you

play07:02

more fun things to play with and so

play07:04

there's a fundamental trade-off ingo

play07:06

that we've made in a different direction

play07:08

from most other languages and the

play07:10

trade-off is what do you want a language

play07:12

is more fun to write in or easier to

play07:14

work on and maintain and for the most

play07:17

part the decisions in go about what went

play07:19

in were about long term maintenance and

play07:21

in particularly in the context of

play07:23

large-scale programming although that's

play07:24

a little off the topic today now the

play07:28

thing is you put features in to make

play07:29

languages expressive you obviously want

play07:31

to not have to type you know hexadecimal

play07:33

numbers which would be a very low

play07:36

feature way to write code but obviously

play07:37

very hard to use just be careful because

play07:39

you make something too concise it can

play07:41

become just unreadable this example here

play07:44

is a real working program in a dialect

play07:47

of APL called dialogue and an implements

play07:49

Conway's Game of Life and I think you

play07:52

could argue that even if you're an

play07:53

expert APL programmer it's not very

play07:55

readable APL is famous for being easy to

play07:57

write and hard to read but and I think

play07:59

it's very we have to be very careful we

play08:01

don't write software like this in a

play08:03

modern distributed multi programmer you

play08:06

know open source world but there's a

play08:09

more important point I think well maybe

play08:10

maybe an equally important point which

play08:12

is when you have features that add

play08:14

expressiveness they typically add

play08:16

expense for instance a lot of people

play08:19

have asked for things like map and

play08:20

filter to be built in to go and we said

play08:22

no one of the reasons we've said no is

play08:24

that if you if you have things like map

play08:27

and filter they're going to use them

play08:28

that's why they're there but they may be

play08:30

more expensive than a simple for loop

play08:32

and when the features are there to make

play08:35

life easier and more expressive they

play08:37

tend to generate more expensive in terms

play08:40

of computer time solutions the problems

play08:42

that have much simpler solutions so

play08:44

they're also they may help the

play08:46

programmer although not always but

play08:48

they'll almost always hurt the computer

play08:49

unless the implementation is extremely

play08:51

smart and believe me the implementation

play08:53

of APL is extremely smart so that

play08:54

actually is a modestly efficient

play08:56

implementation of the game of life but

play08:59

you wouldn't you could do much much

play09:01

better

play09:01

if you wrote a simpler program but

play09:04

you've got to be careful because if you

play09:04

make everything too expansive explain

play09:06

everything in detail you get a very

play09:07

verbose language I won't name any but

play09:09

you know the ones I'm thinking of where

play09:11

it just seems like you're writing too

play09:13

much to say a simple thing so you have

play09:15

to balance this look so what we did was

play09:18

we tried to make the right selection

play09:20

building on the ideas that we're

play09:22

familiar so that a programmer with a

play09:24

background in procedural programming

play09:26

like with C or Java or even you know

play09:29

Fortran say could read a go program and

play09:32

get a pretty good idea right out of the

play09:33

box what was happening and not be

play09:36

confused by strange notation so you have

play09:39

to balance you have to be concise but be

play09:40

expressive make sure that the program is

play09:43

easy to read you have to pick the right

play09:45

fit set of features in other words not

play09:46

just features for features sake way I

play09:48

like to think of this is to think of the

play09:50

entire world of programming is a vector

play09:52

space of very high dimension and what

play09:55

you want to do is define the basis set

play09:57

that covers that vector space so that

play10:00

you can write the programs you want by

play10:02

combining the appropriate orthogonal

play10:05

because that's what basis it is

play10:07

orthogonal set of features and what

play10:10

happens when you add features for

play10:11

expressiveness or for fun is it tends to

play10:14

add more non basis vectors into that

play10:17

space and so there become many paths to

play10:19

get to a particular solution so that's

play10:21

when we say features are orthogonal

play10:23

that's what we mean we mean that they

play10:25

cover this space but we also mean they

play10:26

interact really well so if you take

play10:29

feature a and feature B and you write a

play10:30

program that uses them they work exactly

play10:32

the way you expect feature a and feature

play10:34

B to work they're not as some weird

play10:36

diagonal that causes all kinds of

play10:37

complications you have to worry about

play10:39

again I won't mention which language I'm

play10:41

thinking of so you have to keep all of

play10:44

this in mind when you're designing a

play10:45

language and also think about what the

play10:46

goal is what are you actually trying to

play10:48

achieve what is the problem domain that

play10:50

this language being done for well in gos

play10:52

case we were trying to write code for

play10:53

Google because that's what we do andgo

play10:56

is software that least the parts that we

play10:57

work on are mostly infrastructure server

play11:00

infrastructure what we now call cloud

play11:02

software but used to just be called

play11:03

servers and to do this you have to find

play11:07

enough pieces to build the software and

play11:09

so the fundamental components we started

play11:11

with were ideas like concrete data types

play11:13

you know integer

play11:14

structures floating-point numbers

play11:15

functions and methods interfaces

play11:17

packages concurrency and then the sort

play11:21

of guiding engineering principle of

play11:22

having a really good fast implementation

play11:24

with the abilities of really good

play11:26

tooling and with that sort of all with

play11:29

all those guidelines which is a fairly

play11:30

complicated set of considerations the

play11:33

pieces sort of fell into place and

play11:34

actually ended up being kind of simple

play11:36

in practice and in fact simplicity can

play11:39

be expressive this is a very simple

play11:41

drawing when Rene drew this a while back

play11:44

and yeah he's expressive right

play11:47

he's not really a gofer and I'm not

play11:49

talking about the Magritte version of

play11:50

Scecina buzzing gopher I mean he's just

play11:53

the representation of a gopher very much

play11:56

like like shreaves talked earlier with

play11:58

the horse right and so this for me is

play12:00

what is part of like the ethos of go

play12:02

here's this really simple drawing that

play12:05

represents what go is like we could put

play12:07

more features on we make it more like a

play12:08

gopher we could give them lots more

play12:09

detail and we get something like this

play12:11

right but mostly what we've added is

play12:13

ugliness and hair we haven't actually

play12:16

made embed it right its complexity

play12:19

without clarity so but I want to make a

play12:24

really important point here which is

play12:25

I've said go is simple but it's not it's

play12:28

very complicated I know I worked on it

play12:30

it's one of those complicated things

play12:31

they've ever worked on and yet it feels

play12:33

simple and I think that's a really

play12:35

important idea and it feels simple

play12:38

because these pieces fit together

play12:39

orthogonal and that requires a lot of

play12:41

design a lot of thinking a lot of

play12:43

refinement and implementation and

play12:45

re-implementation and to put it very

play12:47

bluntly simplicity at least in this

play12:49

context is the art of hiding complexity

play12:52

so let me talk about a few simple things

play12:54

and go and why they're really

play12:55

complicated garbage collection

play12:58

goroutines constants interface and

play13:00

packages each of these things is very

play13:02

simple and very complicated but at the

play13:05

same time there's a lot of other

play13:06

subjects I could pick but let's quickly

play13:07

go through these garbage collection is

play13:10

probably the best example of simplicity

play13:12

hiding complexity what is the programmer

play13:15

interface for garbage collection

play13:17

there isn't one can't get simpler than

play13:20

that the empty set is as simple as it

play13:22

gets right and yet look how hard it is

play13:25

to implement all that incredible code to

play13:27

do

play13:28

with stack maps and you know the copying

play13:30

the stacks on when you need to grow them

play13:32

and tracking all the references down

play13:34

pausing it running in parallel with thee

play13:36

with the mutator it's a tremendously

play13:38

complicated problem that fortunately I

play13:39

didn't have to work on we have some

play13:41

really good people in the NGO team who

play13:42

did but I think it's amazing to consider

play13:45

how much code is there for something

play13:48

that has absolutely no user interface

play13:49

there isn't even a free function in go

play13:52

there's nothing but garbage collection

play13:54

to manage memory and it's remarkable to

play13:56

point out that it isn't even in the spec

play13:59

the goal language does not define it is

play14:02

garbage collected in the specification

play14:03

the only mention is in the introduction

play14:05

it was a throwaway property of a feature

play14:07

of language that's how small and

play14:09

therefore how simple the spec is I mean

play14:12

the garbage collection is and you how

play14:13

complicated it is behind the scenes and

play14:15

it also makes code simpler because you

play14:18

don't have to think about who owns the

play14:19

data who's going to free it how to

play14:21

manage it for you you can think about

play14:23

implementation details and efficiency

play14:25

but for just straightforward go

play14:27

programming garbage collection hides

play14:28

everything it's fantastic and one of the

play14:32

things that people love about Go is the

play14:33

concurrency I think it's arguably one of

play14:36

the simplest concurrency models

play14:37

available in a programming language not

play14:38

that they're that many but there are

play14:40

some others there's several components

play14:42

to it go routines channels and select

play14:43

and I'm going to talk about go routines

play14:45

for a minute you start a go routine with

play14:48

the go keyword you say go space geo

play14:51

space and then the function call so

play14:53

three keystrokes you can't make it much

play14:55

shorter than that yeah I can imagine one

play14:58

or two changes I can take but three

play15:01

keystrokes and you just started a sub

play15:03

process in the general mathematical term

play15:05

and so it's like garbage collection

play15:08

because it's extremely simple UI there's

play15:10

nothing in the UI about the size of the

play15:12

stack or a thread ID or managing

play15:16

goroutines show them down things like

play15:18

that there's there's no completion

play15:20

status there's no type a lot of people

play15:23

ask for these things that in fact some

play15:24

other languages or thread packages

play15:28

provide the equivalent functionality of

play15:29

some of those things but we didn't put

play15:31

them in we wanted to go key word to be

play15:34

so simple that had the minimum possible

play15:36

UI here's a function call run it

play15:39

alongside my other

play15:40

three keystrokes and that's part of this

play15:43

minimal design and in crashes talk

play15:45

earlier today he talked about one of the

play15:47

reasons I think you can appreciate now

play15:49

why for instance our no ID on a

play15:50

goroutine internally of course you have

play15:53

a lot of complexity managing this

play15:55

managing the relationship between the

play15:57

goroutine implementation the runtime

play15:58

stack and the garbage collector for

play16:00

example credibly complicated behind the

play16:02

scenes stuff but three keystrokes

play16:06

constants this is one of my favorite

play16:08

things about go that most people don't

play16:10

even think about and they don't think

play16:11

about it because it's incredibly simple

play16:13

when we decided that go ahead to be

play16:15

strictly typed that meant that numeric

play16:17

types could not be interchange freely

play16:20

that was a very common source of bugs in

play16:22

C and C++ you are not allowed and go to

play16:24

takin it and put it into a float 64 or

play16:27

anything like that but that can be very

play16:30

clumsy you don't want have to say float

play16:31

64 zero every time you want to use a

play16:33

floating point zero so we had this idea

play16:36

which is one of those I think relatively

play16:38

novel ideas which is that we made

play16:40

constant just be numbers they're just

play16:43

numbers even though the language is

play16:45

strictly typed and this means you get to

play16:47

throw around things like 1e9 dividing

play16:49

into a time dot second which has a

play16:51

strict type and to get this to work was

play16:54

really art is one of the hardest things

play16:55

in designing language not in

play16:57

implementing it so much but designing it

play16:58

we had to worry about what infinite

play17:00

presented in precision integers means

play17:02

what infinite precision floating point

play17:04

means what happens to the promotion

play17:06

rules if you divide an integer two

play17:08

versus divide a floating point 2 and you

play17:11

get corner cases like this crazy shift

play17:13

which I can't run but what do you think

play17:16

the answer is to this what does this

play17:19

program print it's got a 2.0 and a 2.0

play17:21

shift is 0 and asking the type of both

play17:24

of them you have to think don't you this

play17:27

is a place where the complexity comes up

play17:28

you get it you actually get a float 64

play17:31

in an int and that's not a good thing

play17:34

it's just a consequence of the rules

play17:36

that we've ventually converged on to

play17:38

make constants work quick but for the

play17:40

most part you never see these kind of

play17:41

works when you're using constants they

play17:43

just feel like numbers and it's

play17:45

fantastic so I'm not totally satisfied

play17:47

but I think it was a really good example

play17:48

again of simplicity hiding complexity

play17:51

and I wrote a blog post

play17:54

on blog Doug golang.org / Constance that

play17:56

talks about this stuff in much more

play17:58

detail interfaces one of those favorite

play18:02

features for myself and I think for a

play18:04

lot of programmers a very simple idea

play18:06

all there is is a set of methods people

play18:09

ask for data as well all the time not

play18:11

going to get it it's just it's just

play18:12

functions very simple you also need a

play18:15

variable of type interface you can

play18:18

program with these things but even here

play18:20

you get some funny things happening

play18:21

because you for instance can assign OS

play18:23

dusted into a reader no problem

play18:25

you can assign OS dusted into an empty

play18:27

interface no problem but if you have to

play18:29

narrow the interface you have to do a

play18:32

dynamic type check which we call the

play18:34

type assertion and one of the things

play18:35

that's not well-known about go is that

play18:37

was not in the original design we

play18:39

realized a few months into it that we

play18:41

needed type assertions to make the

play18:42

program work right the addition of

play18:44

effectively dynamic typing into a

play18:46

statically programming language was a

play18:48

complicated thing that we had to deal

play18:50

with and make it work and it's I'm not

play18:53

totally thrilled with how it worked out

play18:55

but I think it's pretty good and it does

play18:57

in the end do its job but for the most

play19:02

part what you have again is a very

play19:03

simple idea an interfaces a set of

play19:05

methods and with it again are quite

play19:08

complicated set of rules behind them

play19:09

that mostly just do what you want but it

play19:12

was hard in fact interfaces are probably

play19:16

goes most distinctive and powerful

play19:17

feature I think concurrency is talked

play19:19

about a little more but you don't write

play19:21

as much concurrency in a typical program

play19:23

as you as you use interfaces interfaces

play19:25

have a profound effect on the library

play19:27

they've enabled the very structure of go

play19:29

programs to be the way they are with it

play19:31

I think the most component oriented

play19:32

architecture of any programming language

play19:34

I've used and so the in fact I think can

play19:37

safely say they are simple to use even

play19:40

though they add complexity they're worth

play19:43

it

play19:43

and finally packages packages are one of

play19:48

the hardest things we had to deal with

play19:49

and design the language it doesn't seem

play19:51

like there's anything there what do you

play19:52

have you have packaged big there's the

play19:53

name of the package you have import

play19:55

stringing the client what's there it

play19:59

took us months to figure this out

play20:00

because it interacts with things like

play20:02

scoping naming information hiding

play20:05

isolation linking compiling

play20:07

cross-compiling and getting all those

play20:10

details right took a very very long time

play20:13

and but on the other hand you guys never

play20:16

think about this stuff right they just

play20:18

work somebody earlier today said import

play20:20

was this favorite keyword that's great I

play20:22

love it and all that complexity which is

play20:25

fantastically intricate when you start

play20:27

talking about working across multiple

play20:29

language implementations of you know

play20:32

four different architectures and

play20:33

different operating systems it's all

play20:34

hidden behind this simple package idea

play20:37

that has basically two concepts and that

play20:40

includes things like go get which is a

play20:41

fantastic enabler for open source based

play20:44

on the fact that the import string is

play20:47

literally that a string with no semantic

play20:49

meaning within the language so again

play20:52

very hard to implement very complicate

play20:54

under the covers extremely simple to use

play20:56

and I think after garbage collection

play20:58

packages are actually the most the best

play21:01

example of simplicity hiding complexity

play21:04

let me show you here's a simple example

play21:07

it's just the sort of standard hello

play21:10

world server it's written with some

play21:12

Japanese in it because why not but you I

play21:15

think and recognized as confident go

play21:17

programmers very quickly what that

play21:19

program does I don't need to run it it

play21:20

does run it does what you think very

play21:22

simple right there's hardly anything

play21:23

there just a few lines of code starts a

play21:26

server runs it okay here's what's going

play21:28

on inside this program first of all most

play21:31

visibly it's doing unicode utf-8 working

play21:35

flawlessly it's supporting some magic

play21:37

packages and they're being used from

play21:39

flog net HTTP the HTTP being one of the

play21:42

most awesome packages there's an F

play21:45

printf directly to a network connection

play21:46

which is interesting and unusual there's

play21:50

a function being promoted method that

play21:52

with the handle func in there which is a

play21:55

bit of a mind blow to people new to go

play21:56

was mind blow to me when it was pointed

play21:59

out to me by Russ that we could do that

play22:00

it's also truly concurrent the server

play22:02

won't block as long as it enough

play22:04

resources on the server hardware you can

play22:06

have zillions of people talking to this

play22:08

service simultaneously which is to say

play22:11

it's production ready there it is a

play22:13

production or any web server in just a

play22:15

few lines of code it doesn't get much

play22:16

simpler than that right so in summary

play22:21

simplicity is complicated but the

play22:23

clarity is worth the fight I don't want

play22:25

to hang out with the gofer on the right

play22:27

I want to hang out with the guy in the

play22:28

left he's much more expressive and fun

play22:32

and much less hairy

play22:34

so in conclusion simplicity is very hard

play22:38

to design it's very complicated to build

play22:41

it sounds strange to say that but it's

play22:43

true making things simple is hard work

play22:46

but if you get it right you get

play22:48

something that's very easy to use and I

play22:50

think the success of go and the fact

play22:52

that you're all here listening to me

play22:54

proves that there's something there

play22:56

thank you

Rate This
★
★
★
★
★

5.0 / 5 (0 votes)

Étiquettes Connexes
Simplicity in CodingGo LanguageProgramming PhilosophyLanguage DesignConcurrencyGarbage CollectionSoftware EngineeringCode ReadabilityLanguage FeaturesEngineering Principles
Besoin d'un résumé en anglais ?