justforfunc #25: deeper program analysis with go/parser

Поделиться
HTML-код
  • Опубликовано: 24 дек 2024

Комментарии • 29

  • @oliverbutterfield9844
    @oliverbutterfield9844 7 лет назад +2

    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.

  • @AM-jx3zf
    @AM-jx3zf 4 года назад

    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

  • @JanErikKeller
    @JanErikKeller 7 лет назад +2

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

    • @JustForFunc
      @JustForFunc  7 лет назад +2

      +Jan Erik Keller so I modified the code ... and v now appears *only* on the 4th position :)

    • @JustForFunc
      @JustForFunc  7 лет назад

      +Jan Erik Keller actually, I updated the numbers and wrote a blog post on it
      “Understanding Go programs with go/parser” @francesc medium.com/@francesc/understanding-go-programs-with-go-parser-c4e88a6edb87

    • @JanErikKeller
      @JanErikKeller 7 лет назад

      Cool :)

  • @sebastienfriess
    @sebastienfriess 7 лет назад +4

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

    • @JustForFunc
      @JustForFunc  7 лет назад

      +Sébastien FRIESS oh that's kinda cool ... tell me more

    • @alex0059ify
      @alex0059ify 7 лет назад

      we did similar thing to generate an openapi spec from comments in go code, it works pretty well but still in a early stage

    • @sebastienfriess
      @sebastienfriess 7 лет назад

      If you use idiomatique Go HTTP API, on could use AST to generate the routes documentation, HTTP verbs, used structs as DTO, etc ?

  • @etiennebruines467
    @etiennebruines467 7 лет назад +1

    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.

    • @JustForFunc
      @JustForFunc  7 лет назад

      +Etienne Bruines yup, I had a quick section on go/printer that I ended up dropping

  • @luftigo
    @luftigo 6 лет назад

    You could check for the exported variables

  • @Kreisquadratur
    @Kreisquadratur 7 лет назад +5

    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.

    • @JustForFunc
      @JustForFunc  7 лет назад +1

      +Uwe Dauernheim that's a very good guess, but there's only one way to know ... writing the code 😎

  • @paracha3
    @paracha3 7 лет назад +1

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

  • @dearozero3631
    @dearozero3631 6 лет назад

    Please do a video on go/types!

  • @AkimDemaille
    @AkimDemaille 7 лет назад

    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?

    • @JustForFunc
      @JustForFunc  7 лет назад

      +Akim Demaille this is idiomatic Go, yes
      you could define a struct with a map inside and define the method on it's pointer but there's really no need to do so

  • @romanceresnak1834
    @romanceresnak1834 5 лет назад

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

  • @Kreisquadratur
    @Kreisquadratur 7 лет назад +6

    Thanks Francesc, great learning episode as usual. A tip: goast.yuroyoro.net is an AST visualizer website. if one simply wants to inspect the random source snippet.

  • @mhcbon4606
    @mhcbon4606 7 лет назад

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

  • @randomjoe2522
    @randomjoe2522 6 лет назад

    Good explanation, thanks a lot!

  • @dansplain2393
    @dansplain2393 3 года назад

    “Nobody walks in LA” except ast.Walk

  • @dreamtheater_92
    @dreamtheater_92 7 лет назад +1

    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.

    • @JustForFunc
      @JustForFunc  7 лет назад

      +Mark Richman parsing is only academic? you might be interested in my new company haha
      sourced.tech

    • @Kreisquadratur
      @Kreisquadratur 7 лет назад +1

      +Mark Richman We wrote a `go-corp-linter` which does company specific linting of rules we want to enforced for our developers. So quite useful I would say.

    • @dreamtheater_92
      @dreamtheater_92 7 лет назад +1

      Uwe Dauernheim I didn’t say it wasn’t useful. It’s just not useful to the majority of Go developers.