Code Review: Elixir Lexer

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

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

  • @stephenreaves3205
    @stephenreaves3205 Год назад +149

    Shy: *writes beautiful tail-call recursion*
    Prime: "WHERES THE LOOP?!"

  • @madlep
    @madlep Год назад +129

    It’s pretty good, idiomatic elixir.
    Elixir culture is just generally big on docs. The @moduledoc and @doc attributes get compiled into the code, and are there to use in REPL etc to figure out how to use modules/functions without having to Google all the time. It’s pretty useful.
    The “markdown” bit in the function comments are actually inline doc tests - the “iex> …” is code to execute. The lines after are saying what the expected output is. These are picked up and run automatically when unit tests run. Again, encouraging docs, and also pretty handy. You wouldn’t write all the unit tests there, but more to show example usage - and have the examples actually be verified as working, and not some out of date mess.
    defp = private function, as opposed to def, which is public
    Prepending to a build singly linked list is to efficiently build up data when list nodes are immutable - prepend is O(1). Append is O(n) (cause you have to copy the whole thing). This pattern comes up all the time in immutable functional languages.
    read_identifier doesn’t prepend, because of an optimisation trick you can do in Erlang/Elixir where you build an “improper list” (aka iodata) of bytes, strings, lists in any combination. Then IO.iodata_to_binary flattens that improper list into a binary string. Only works for building binaries, and not actual lists.
    Agree with doing match on character as a case match in a single function, but that’s personal preference, and either way works.
    My default is different function heads for different logic, different case match calls to just handle different data.

  • @tensorflaw
    @tensorflaw Год назад +86

    "why is it so weird"- it's a functional language. They all look like this

    • @GuitarWithBrett
      @GuitarWithBrett 10 месяцев назад +5

      It’s really not weird like other functional languages , Erlang is sort of its own thing in many ways then elixir makes syntax more “ruby-ish”. Elixir is more about managing the BEAM VM as That’s what the language was built for , not to be functional for functional sake like say Haskell for research

    • @jatlineur
      @jatlineur 3 месяца назад

      for oop user, i agree with you, so weird.

  • @jessejayphotography
    @jessejayphotography Год назад +31

    This is a great example of how Elixir can be shockingly easy to understand with just some basic functional paradigms, pattern matching, and special Erlang first class binary syntax.

  • @wojciechorzechowski2211
    @wojciechorzechowski2211 7 месяцев назад +13

    I work in Elixir professionally. I haven't been happier since!

  • @whisperscribe
    @whisperscribe Год назад +74

    I bet if you called José (Creator of Elixir) to a chat, he would gladly accept it (He also streams)

    • @andredasilva6807
      @andredasilva6807 Год назад

      do you know where? i just got into elixir

    • @whisperscribe
      @whisperscribe Год назад

      @@andredasilva6807 he is on twitch, www.twitch.tv/josevalim
      There is a cool guy that teaches elixir on yt aswell www.youtube.com/@elixirmentor

    • @Redyf
      @Redyf Год назад

      ​@@andredasilva6807search fir José valim socials, maybe you will be able to find it. I want to get into elixir too, looks like a fun language to learn

  • @Deemo_codes
    @Deemo_codes 10 месяцев назад +9

    Elixir tends to be quite assertive in its function clauses. You see a "when is_whitespace(c)" and that clause will only ever fire on whitespace. So you then don't have to have anything in the function body that deals with other cases.
    The defp declares a private function so they can only be used internally within this module. It looked like every function was private apart from init. So init is your entry point into this module.
    It's really nicely written hats off to shy_ryan

    • @Deemo_codes
      @Deemo_codes 10 месяцев назад +3

      Also the compiler will complain if you put a function with the same name anywhere else in the file other than with its buddies

  • @DiluculoOrtus
    @DiluculoOrtus 10 месяцев назад +6

    The clause approach imo is why elixir doesn't need to be statically typed. It is basically whitelisting what kind of data and values and data structures will be handled by the module.
    If the data passed into the module does not meet the whitelist criteria, or if it is of a nature that causes the module to turn it into something that does not meet the criteria then you get a match error, you know where it happened and with the debugging tools you can easily get a trace of what happened.

  • @BboyKeny
    @BboyKeny Год назад +7

    Technically computer programs are proofs. Therefore computer scientists just skip every other step and force a proof through trail and error. Although with Denotational Semantics you can proof a program on paper, so I think it's possible for programmers to become more like mathematicians in terms of thinking.

  • @puspo-in
    @puspo-in Год назад +12

    finally, the primeagen write elixir!

  • @leetaeryeo5269
    @leetaeryeo5269 Год назад +5

    Things have calmed down for me now, so I really need to get back to working on my Visual COBOL branch of this. It’s been fun to write and to watch these reviews.

  • @aghileslounis
    @aghileslounis Год назад +6

    Real types are coming to Elixir core language, they are not just a superset like some other languages, and they are SOUNDED

  • @bicunisa
    @bicunisa Год назад +4

    Pattern match with several functions is a good thing (tm).

  • @nomoredarts8918
    @nomoredarts8918 Год назад +4

    Every time he says like, toggle like button. Then see at the end if you like the video or not 😂

  • @avwie132
    @avwie132 27 дней назад

    It’s pretty amazing that you feel confident enough to review code in a language you know nothing about.

  • @dromedda6810
    @dromedda6810 Год назад +1

    the lord himself as the wallpaper is the best thing i've seen is some time

  • @salim444
    @salim444 Год назад +8

    can someone point me to the clojure clip they're talking about

    • @nickboyadjian367
      @nickboyadjian367 Год назад +5

      I want to see it too haha

    • @ath0006
      @ath0006 Год назад +2

      Me too!

    • @salim444
      @salim444 Год назад

      here is the vod. www.twitch.tv/theprimeagen/v/1844433659?sr=a&t=5042s

    • @thomvandenhil4717
      @thomvandenhil4717 Год назад

      ruclips.net/video/SGBuBSXdtLY/видео.html

  • @jimhrelb2135
    @jimhrelb2135 Год назад +2

    love the tpope in the background

  • @typecraft_dev
    @typecraft_dev Год назад +9

    lexer? barely even know 'er

  • @thetylde
    @thetylde 11 месяцев назад

    Is there any repo link? 👀

  • @ujjal147
    @ujjal147 Год назад

    cond >> multiple function heads usually in Elixir

  • @CodeTalker23
    @CodeTalker23 Год назад +7

    cmon where F# lexer?

    • @serdookr
      @serdookr Год назад +6

      I mean to be fair it would be almost identical to the ocaml one

    • @leetaeryeo5269
      @leetaeryeo5269 Год назад +1

      There’s one in the repo, but idk if he’s covered it or plans to

  • @muhammadsulthanmazaya2388
    @muhammadsulthanmazaya2388 Год назад +8

    BLAZINGLY FAST, FIRST!

  • @ankk98
    @ankk98 11 месяцев назад

    This is harder to understand than I thought.

  • @quarteratom
    @quarteratom 10 месяцев назад +4

    This is nice. Only would have been better with Erlang syntax.

  • @GuitarWithBrett
    @GuitarWithBrett 3 месяца назад

    This is painful

  • @fullhalfadder
    @fullhalfadder Месяц назад

    Why are they reviewing code they’re not familiar with?

  • @marcusrehn6915
    @marcusrehn6915 11 месяцев назад +2

    Elexer

  • @connormc711
    @connormc711 8 месяцев назад

    The hate in this video is unreal from tj

  • @sunclausewitz2707
    @sunclausewitz2707 Год назад +1

    Why does it need to be so cryptic and Perl like.

    • @sullivan3503
      @sullivan3503 Год назад +18

      This isn't really that cryptic if you've used any other functional languages. The only really weird thing here is the binary string.

    • @blacktipe9922
      @blacktipe9922 Год назад +1

      then u better dont look at erlang haha

    • @JeremyAndersonBoise
      @JeremyAndersonBoise Год назад

      @@sullivan3503 Totally agree with you here. I understood it fine, and I haven't looked at Elixir in years.

  • @MaxCoplan
    @MaxCoplan Год назад

    ALexir

  • @DMSBrian24
    @DMSBrian24 Год назад +2

    What the fuck is going on

    • @DMSBrian24
      @DMSBrian24 Год назад

      Thanks, I hate this

    • @quarteratom
      @quarteratom 10 месяцев назад +1

      They are reviewing how beautiful code can be.

  • @sacredgeometry
    @sacredgeometry Год назад +8

    I just thew up a little looking at that code.

    • @franciscoflamenco
      @franciscoflamenco Год назад +1

      it's beautiful code and you just have bad taste.

    • @rationalityfirst
      @rationalityfirst Год назад +9

      weak minded

    • @sacredgeometry
      @sacredgeometry Год назад

      ​@@rationalityfirst It's called taste. It's unfortunate that you cant buy it otherwise you could use those pennies you earn shaking your ass down the docks to afford yourself some perspective.

    • @jessejayphotography
      @jessejayphotography Год назад +14

      With some basic understanding of functional programming, pattern matching, and Elixir style the code is shockingly understandable to even an intermediate Elixir programmer.

    • @SimonBuchanNz
      @SimonBuchanNz Год назад +4

      I've seen a functional language before so there's not much weird here other than the specific literal syntax.

  • @32gigs96
    @32gigs96 Год назад +2

    Imagine carrying the entire BEAM vm on ur back for a lexer. Elixir should not be used outside of distributed systems

    • @BrunoArrais1
      @BrunoArrais1 Год назад +19

      It's a exercise my man, take it easy

    • @fenkraken
      @fenkraken Год назад +12

      Imagine doing that for JVM. Oh wait, people do that?..
      Actually it would be so much better if people stopped doing that, so kinda agree with you in general case.

    • @stevenhe3462
      @stevenhe3462 Год назад +2

      Haha Gradle daemon.

    • @avwie132
      @avwie132 27 дней назад

      You mean like the full V8 engine for JS?