justforfunc #25: deeper program analysis with go/parser

preview_player
Показать описание
In the second episode of the program analysis series we use go/parser to find out what's the most common local variable name and the most common package variable name.

Get ready for visitor patterns, ASTs, and more!

Рекомендации по теме
Комментарии
Автор

I, for one, am happy that the new mic stand actually didn’t get rid of the keypresses. I would say they definitely add to the live coding feel of your videos.

oliverbutterfield
Автор

Great video Francesc! Interesting thing, those ASTs. You can even use `format.Node` to print formatted Go code. This basically means you can generate Go code programmatically by "simply" defining the AST values you just parsed.

etiennebruines
Автор

I think the reason for `v` having been the most used identifier and now not being the most used variable is that `v` is used as parameter in functions (e.g. `v interface{}`) which variable counting program does not consider.

Kreisquadratur
Автор

Hi,
v is a typical name of an function parameter. Since we didn't consider the declaration of these, the number is way lower.

JanErikKeller
Автор

Hey Francesc, thanks for the episode, what about an another one using AST to generate automatically an API documentation for example ?

sebastienfriess
Автор

I don't have all the libraries you have or something, but mine came out:
most common global variable names
5 kernel32
2 procGetConsoleMode
2 modified
2 cpuprofile
2 doc

AM-jxzf
Автор

You could check for the exported variables

luftigo
Автор

Francesc can you also do some episode on commonly used topics like design patterns in golang, big multi file projects in golang, etc. Thanks

paracha
Автор

Hey Francesc, how to read a build program instead of text file ?

romanceresnak
Автор

Hi!  I'm still an apprentice in Go.  There's something unspoken that makes me somewhat uneasy: you've shown with the int visitor that traversal actually _copies_ of the visitor that visit children, so, unless I'm missed something, this works because the visitor features only maps, which are reference types, so all the visitors are actually updating the same maps.  Likewise, I'm uneasy with the code in the repo where some methods change these maps yet they take the visitor by value, not by pointer.  Is this typical go coding style?

AkimDemaille
Автор

might you try a recursive analysis of embedded types ? just for fun =)

mhcbon
Автор

This is an interesting academic topic, but I don't think most Go developers would get much use out of it in their daily work.

dreamtheater_