LIVE ON TWITCH: / theprimeagen Check out Teej!: / @teej_dv / teej_dv Get in on Discord: / discord Get in on Twitter: / theprimeagen Got Something For Me to Read or Watch??: / theprimeagenreact
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.