Lexical Scanning in Go - Rob Pike

  Рет қаралды 139,155

GoogleFOSSSydney

GoogleFOSSSydney

Күн бұрын

Lexical Scanning in Go, a talk by Rob Pike at Google Technology User Group given on Tuesday, 30 August 2011.
The slides: rspace.googlecode.com/hg/slide...

Пікірлер: 67
@RayPereda68
@RayPereda68 6 жыл бұрын
This is an exquisite example of clean code. Lexical analysis code is often hairy but as Rob shows doesn't have to be. Go first class functions and slices really shine here.
@lukes5461
@lukes5461 10 жыл бұрын
My favourite line: “So we should write our own [lexer], because it's easy, right? Anybody can write code-especially programmers.” (11:45)
@russellchido
@russellchido 5 жыл бұрын
@@skepticmoderate5790 lmao bf doesn't even require lexing. Each character is a token. This is the worse qualification to talk about parsing.
@kamilziemian995
@kamilziemian995 2 ай бұрын
@@russellchidoCan you explain this in more details?
@kalekold
@kalekold 5 жыл бұрын
This is now my ideal way of writing a lexer in Go. It's such an elegant solution.
@atanasdenkov2433
@atanasdenkov2433 2 жыл бұрын
Beautiful lecture, beautiful language, beautiful programming style.
@seltsamerzeitgenosse9797
@seltsamerzeitgenosse9797 3 жыл бұрын
09:26 "We could use a tool. Lex is a pretty famous one. Initially written by Mike Lesk and then redone when he was an intern by someone called Eric Schmidt." ... who at the time of this talk was his Boss (and the CEO of Google)
@rettberg5688
@rettberg5688 8 жыл бұрын
Is anybody familiar with the work of Michael Jackson? (sees a lot of hands) Good (goes right into talking about some obscure CS researcher.) This man is the pinnacle of nerd. I'm pretty sure the audience thought you were about to make a joke about thriller.
@AndyHerbert
@AndyHerbert 7 жыл бұрын
Jackson structured programming is hardly obscure.
@needlessoptions
@needlessoptions 6 жыл бұрын
Andy Herbet Nerd
@skepticmoderate5790
@skepticmoderate5790 5 жыл бұрын
Fairly certain it was a joke.
@ideaparkcc
@ideaparkcc 3 жыл бұрын
Go 的成功证明你就是个傻逼,事实证明了你真是个傻逼。
@bokwoon
@bokwoon 3 жыл бұрын
It was a joke and I'm so sad no one laughed! I sure did when I heard him offhandedly quip "as you know, Michael Jackson developed Jackson Structured Programming".
@olaifaoluwadarasimiibikunl7820
@olaifaoluwadarasimiibikunl7820 Ай бұрын
Wow! Awesome talk. Can't wait to try this out. Thanks Rob.
@joshring8563
@joshring8563 11 ай бұрын
Really appreciate how this talk made state machines more accessible to normal humans :)
@blizzy78
@blizzy78 4 жыл бұрын
Very insightful, thanks Rob!
@naikrovek
@naikrovek 5 жыл бұрын
I like how Dave Chaney (now something of a Golang celebrity) is in the audience asking questions. Looks like him, anyway.
@ishwargowda
@ishwargowda Жыл бұрын
That was beautiful!!
@bokwoon
@bokwoon 3 жыл бұрын
So instead of the state machine being implemented as a state variable + a switch statement, it is implemented as functions returning other functions. If state A transitions to state B, it is encoded as function A returning function B.
@vonschlesien
@vonschlesien 12 жыл бұрын
@henriquedante Unicode is actually not a problem - Go as a language natively supports utf8 as its character encoding for the string type. For example, around 23:00-24:00, where you see "switch r = l.next() {...", r is the next rune in the output - i.e. the next unicode code point assembled through utf8 decoding. If you want to accept only upper case, just call the relevant test function from package unicode on the value of r :-)
@jnevercast
@jnevercast 6 жыл бұрын
Master of Goroutines, still can't schedule :p
@DamienPollet
@DamienPollet 11 жыл бұрын
I think we did something like that as an exercise, except each state function would directly call its successors using tail-recursion. That would have been in OCaml, IIRC…
@henriquedante
@henriquedante 12 жыл бұрын
@vonschlesien You're right I didn't think the test functions would be so efficient as they are
@ilcorion
@ilcorion 7 жыл бұрын
Is there any "Parsing in GO", describing the next step -- using the channel of items in order to build syntax tree?
@Adisaboss
@Adisaboss 7 жыл бұрын
The parser code is there: golang.org/src/text/template/parse/parse.go I did not find any course on the topic either, though
@shakerlakes
@shakerlakes 4 жыл бұрын
I love the slam against Perl at 4:32. 😉
@user-xj4gy4in3c
@user-xj4gy4in3c 5 жыл бұрын
This is so amazing talk. thx
@shakerlakes
@shakerlakes 4 жыл бұрын
He's a very good speaker. I do enjoy his talks. Even if you're not interested in the topic, you'll become interested in the topic. You come away with insights that you didn't even know you were missing before watching the talk.
@EugeneCrosser
@EugeneCrosser 12 жыл бұрын
@jimmyrcom I see. Honestly, in this particular case it's just a matter of personal preference, the for-loop is "elegant enough" too.
@DavidFarrellEastBay
@DavidFarrellEastBay 11 жыл бұрын
@chuanchuanLeo, did you finish your C implementation? Is it available for viewing online? Please let me know if you'd like any assistance.
@salvezza2710
@salvezza2710 8 жыл бұрын
guys, where can I find go parser for parsing sql files ? because, I found only a single statement parser and one located in influxdb, but it's not what I need.
@zgmg9263
@zgmg9263 5 жыл бұрын
This is amazing
@saptarsihalder7850
@saptarsihalder7850 3 жыл бұрын
what is wrong with rob pike. this guy's idea is so simple yet its like a next level powerful idea...I am just amazed by how he did the lexing...
@DavidFarrellEastBay
@DavidFarrellEastBay 12 жыл бұрын
I wrote a lexer and parser API in Go, inspired by this presentation: github.com/iNamik/lexer.go github.com/iNamik/parser.go
@peterarnt
@peterarnt 7 жыл бұрын
Anyone know where the slides moved to? Link above does not work (i.e. linky-no-worky)
@peterarnt
@peterarnt 7 жыл бұрын
This appears to work: talks.golang.org/2011/lex.slide#1
@salkdjfasldkfjsdlk
@salkdjfasldkfjsdlk 9 жыл бұрын
Great Golang talk as always. I really wish people would stop using the word trivial.
@Adisaboss
@Adisaboss 7 жыл бұрын
Reminds me the horrible days of Math courses: "We'll skip this demonstration, it's trivial." "IT IS? Gosh I'm lost..." I couldn't agree with you more
@Naeddyr
@Naeddyr 12 жыл бұрын
So let's lex a left meta. So let's lex a left meta. So let's lex a left meta. I love the way he says that.
@amiraelsayedhassan8538
@amiraelsayedhassan8538 Жыл бұрын
Anyone else think he'll start singing Smooth Criminal by Michael Jackson instead?
@EugeneCrosser
@EugeneCrosser 12 жыл бұрын
I wonder if Go has tail call optimization. You might implement the construct described in minutes 14-15 as a tail call instead of a for-loop.
@JackMott
@JackMott 4 жыл бұрын
it doesn't, even 8 years later.
@mahamedbelkheir2749
@mahamedbelkheir2749 3 жыл бұрын
@@JackMott it does actually, but you have to do it manually with GOTO, it's one of the only valid usecases for goto, explicit tail call funcs
@Ch051
@Ch051 11 жыл бұрын
Why does lex() return a reference to the lexer, and not just the item channel? Is this because the lexer would get garbage collected otherwise?
@Mike-iz9kh
@Mike-iz9kh 4 жыл бұрын
You have to call the "run()" method on the lexer you get back before you would get anything from the channel. I suppose that could be kicked off inside the same lex() function, but that's not how it was shown in the talk.
@stovechan7873
@stovechan7873 8 жыл бұрын
51:06 They wanted him to stay, be he had to Go. Should he stay or should he go? He decided to Go.
@AbhinandanNM
@AbhinandanNM 8 жыл бұрын
Went over my head
@PriyankJainpj
@PriyankJainpj 7 жыл бұрын
I am interested if you are still interested in helping me out?
@dn5426
@dn5426 2 жыл бұрын
wait, is that dave cheney...?
@henriquedante
@henriquedante 12 жыл бұрын
Main objection point is that you can't write this way if you're parsing unicode patterns. For example, what would be the accept() string for accepting upper case, lower case, etc. letters ? Nevertheless, the final scanner was extremelly clean and it must have been really fun to write.
@bokwoon
@bokwoon 3 жыл бұрын
You can simply modify the accept() to take in a boolean function instead of a string. That would allow accept() to take in the unicode.IsLetter() and unicode.IsLower() functions as arguments, which are unicode aware.
@user-ju1qd9ek2m
@user-ju1qd9ek2m Жыл бұрын
very clear talk and the lexical scanning in golang at 2022 is very different
11 жыл бұрын
RP just must do everything right, right? ;-)
@johnnm3207
@johnnm3207 2 жыл бұрын
Why did he say the work of Michael Jackson and I immediately thought of Billie Jean
@aperson4051
@aperson4051 6 ай бұрын
I'm only 20 mins in, but I'm failing to see the "beauty" in this approach. The logic is spread out over codebase. Code should be optimized for (human) reads. A single switch statement where state is kept track of reads way easier.
@aperson4051
@aperson4051 6 ай бұрын
I have a feeling this is another case of, when a new paradigm starts to take off (the actor model) everyone wants to write everything in it, and it all seems beautiful until we actually work with it and begin to learn why this new idea is not always appropriate for every task.
Concurrency is not Parallelism by Rob Pike
31:22
gnbitcom
Рет қаралды 119 М.
Cuddle, A go AppEngine Demo - Andrew Gerrand
59:14
GoogleFOSSSydney
Рет қаралды 10 М.
Dynamic #gadgets for math genius! #maths
00:29
FLIP FLOP Hacks
Рет қаралды 19 МЛН
Why You Should Always Help Others ❤️
00:40
Alan Chikin Chow
Рет қаралды 12 МЛН
ПООСТЕРЕГИСЬ🙊🙊🙊
00:39
Chapitosiki
Рет қаралды 21 МЛН
How I prepare to meet the brothers Mbappé.. 🙈 @KylianMbappe
00:17
Celine Dept
Рет қаралды 58 МЛН
Gopherfest 2015 | Go Proverbs with Rob Pike
22:29
The Go Programming Language
Рет қаралды 239 М.
Google I/O 2012 - Meet the Go Team
1:00:29
Google for Developers
Рет қаралды 88 М.
dotGo 2015 - Rob Pike - Simplicity is Complicated
23:12
dotconferences
Рет қаралды 151 М.
OSCON 2010:  Rob Pike, "Public Static Void"
12:31
O'Reilly
Рет қаралды 112 М.
GopherFest 2015: Rob Pike on the move from C to Go in the toolchain
32:53
GopherCon 2016: Rob Pike - The Design of the Go Assembler
23:57
Gopher Academy
Рет қаралды 95 М.
Another Go at Language Design
1:15:44
Stanford
Рет қаралды 28 М.
Master Go Programming With These Concurrency Patterns (in 40 minutes)
46:15
Google I/O 2012 - Go Concurrency Patterns
51:27
Google for Developers
Рет қаралды 795 М.
Main filter..
0:15
CikoYt
Рет қаралды 610 М.
Apple, как вас уделал Тюменский бренд CaseGuru? Конец удивил #caseguru #кейсгуру #наушники
0:54
CaseGuru / Наушники / Пылесосы / Смарт-часы /
Рет қаралды 4,6 МЛН
5 НЕЛЕГАЛЬНЫХ гаджетов, за которые вас посадят
0:59
Кибер Андерсон
Рет қаралды 1,2 МЛН
iphone fold ? #spongebob #spongebobsquarepants
0:15
Si pamer 😏
Рет қаралды 687 М.