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.
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
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.
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
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.
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.
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.
@@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.
With some basic understanding of functional programming, pattern matching, and Elixir style the code is shockingly understandable to even an intermediate Elixir programmer.
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.
Shy: *writes beautiful tail-call recursion*
Prime: "WHERES THE LOOP?!"
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.
thank you for this!
"why is it so weird"- it's a functional language. They all look like this
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
for oop user, i agree with you, so weird.
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.
I work in Elixir professionally. I haven't been happier since!
I bet if you called José (Creator of Elixir) to a chat, he would gladly accept it (He also streams)
do you know where? i just got into elixir
@@andredasilva6807 he is on twitch, www.twitch.tv/josevalim
There is a cool guy that teaches elixir on yt aswell www.youtube.com/@elixirmentor
@@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
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
Also the compiler will complain if you put a function with the same name anywhere else in the file other than with its buddies
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.
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.
Is this an analogy or do you have any reference to the "program-proof equivalence"?
finally, the primeagen write elixir!
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.
Try GOBOL
Real types are coming to Elixir core language, they are not just a superset like some other languages, and they are SOUNDED
Lovely
Pattern match with several functions is a good thing (tm).
Every time he says like, toggle like button. Then see at the end if you like the video or not 😂
It’s pretty amazing that you feel confident enough to review code in a language you know nothing about.
the lord himself as the wallpaper is the best thing i've seen is some time
can someone point me to the clojure clip they're talking about
I want to see it too haha
Me too!
here is the vod. www.twitch.tv/theprimeagen/v/1844433659?sr=a&t=5042s
ruclips.net/video/SGBuBSXdtLY/видео.html
love the tpope in the background
lexer? barely even know 'er
Obligatory
Is there any repo link? 👀
cond >> multiple function heads usually in Elixir
cmon where F# lexer?
I mean to be fair it would be almost identical to the ocaml one
There’s one in the repo, but idk if he’s covered it or plans to
BLAZINGLY FAST, FIRST!
This is harder to understand than I thought.
This is nice. Only would have been better with Erlang syntax.
This is painful
Why are they reviewing code they’re not familiar with?
Elexer
The hate in this video is unreal from tj
Why does it need to be so cryptic and Perl like.
This isn't really that cryptic if you've used any other functional languages. The only really weird thing here is the binary string.
then u better dont look at erlang haha
@@sullivan3503 Totally agree with you here. I understood it fine, and I haven't looked at Elixir in years.
ALexir
What the fuck is going on
Thanks, I hate this
They are reviewing how beautiful code can be.
I just thew up a little looking at that code.
it's beautiful code and you just have bad taste.
weak minded
@@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.
With some basic understanding of functional programming, pattern matching, and Elixir style the code is shockingly understandable to even an intermediate Elixir programmer.
I've seen a functional language before so there's not much weird here other than the specific literal syntax.
Imagine carrying the entire BEAM vm on ur back for a lexer. Elixir should not be used outside of distributed systems
It's a exercise my man, take it easy
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.
Haha Gradle daemon.
You mean like the full V8 engine for JS?