Chapter 2 of Metaprogramming Elixir by @chris_mccord

You can get a copy here:
pragprog.com/titles/cmelixi…

Summarizing so you can get the key takeaways! 🧵

#elixirnewbie #myelixirstatus

0/11
Macros can be used for powerful code generation. They can save time, reduce boilerplate, and produce elegant APIs. To realize the power of macros, remember that most of the Elixir Standard library is implemented as macros.

1/11
You have the freedom to extend the language and implement your own desired features. Macros allow you to create your own keywords and allow Elixir to be flexible for future requirements.

2/11
For example, you could create your own macro to run comprehensions in parallel! That might look like

para(for i <- 1..10 do: i * 10)

3/11
With access to the AST, macros gain insight into the meaning of each expression passed into it, not just the values, but the true meaning of the expression

4/11
For example: a typical testing framework given "assert 10 < 1" would simply print "expected true, got false". Which isn't useful. But with macros, you gain the ability to provide further insight. "expected 10 to be less than 1".

5/11
You accomplish this through a smart assert macro that has the ability to understand the left value, right value, and operator passed into it. You then leverage pattern matching to print a more comprehensive message "expected {lhs} to be less than #{rhs}"

6/11
bind_quoted unquotes arguments and prevents accidental reevaluations.

defmacro assert({operator, _, [lhs, rhs]}) do
quote bind_quoted: [lhs: lhs, rhs: rhs, operator: operator] do
...

bind_quoted disables unquote unless you pass the unquote: true option.

7/11
The core purpose of macros is to inject code into a module to extend their behavior. The `use` macro provides a common API for module extension. `use` is simply a macro that injects code from the __using__ macro definition from another module.

8/11
Module attributes allow data to be stored at compile-time. in a macro definition, you can use the accumulate: true option to keep a list of registrations during compile time.

import unquote(__MODULE__)
Module.register_attribute(__MODULE__, :example, accumulate: true)

9/11
Elixir provides a before_compile hook when you want to delay macro expansion until your module attributes have been registered. a __before__compile/1 macro must then be defined.

10/11
Hope you enjoyed this summary! As usual, I'm not affiliated. I just do these summaries for fun and to learn.

I recommend you pick up your own copy of Metaprogramming Elixir! pragprog.com/titles/cmelixi…

11/11

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Brooklin Myers

Brooklin Myers Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @BrooklinJMyers

26 Oct
Chapter 1 of Metaprogramming Elixir, Write Less Code, Get More Done (and Have Fun!) by @chris_mccord

You can get your copy here:
pragprog.com/titles/cmelixi…

Twitter summaries are back! 🧵

#myelixirstatus #elixirnewbie.

0/17
Ever dream of having that one cool feature in your language of choice? With luck, you might see it in a few years, more likely never. However, Elixir is different. Through metaprogramming, Elixir allows you to extend the language and create first-class features.

1/17
Most programming languages have an AST (Abstract Syntax Tree), but it's hidden from you. When compiled or interpreted, the program's source code is transformed into a tree structure before being turned into bytecode or machine code.

2/17
Read 18 tweets
22 Sep
Today's summary comes from the book Elixir in Action. by @sasajuric.

manning.com/books/elixir-i…

What is Erlang?🧵0/17

#myelixirstatus #elixirnewbie
Erlang is a general-purpose development platform that supports concurrency, scalability, fault-tolerance, distribution, and high availability. It was built in the 1980s by Ericcson, a Swedish telecom giant. However, it is not specialized for telecom systems.

1/17
Erlang powers large applications such as WhatsApp, the Riak distributed database, the Heroku cloud, the Chef deployment automation system, and the RabbitMQ message queue.

2/17
Read 18 tweets
16 Sep
Todays summary: Watched @lawik's LiveStream: Video: Nerves, Livebook & small displays (eInk, OLED)
underjord.io/livestream-ner…

How @NervesProject helps you get started with Elixir and IoT without needing to know a lot about the hardware.

🧵0/13

#myelixirstatus #elixirnewbie
Raspberry pi is a great way to get your start in IoT, and Nerves and Livebook take that even further. Cool enough: the first real Elixir code Lars wrote was for the Rasberry Pi Zero.

1/13
You can sandwich a Rasberry Pi and an eInk display together. The Rasberry Pi runs your application and your application can use The Libraries Inky and Chisel to write to the display.

2/13
Read 14 tweets
15 Sep
Listened to @ThinkingElixir with @cadebward @bernheisel and @brainlid and guest @voltonez

OTP Certificates Woes with Bram Verburg. spoti.fi/3luRtVs

On September 30, 2021, the root CA certificate DST Root CA X3 will expire. Here's how you stay safe. 🧵

#myelixirstatus
Bottom line, before the end of September, if you are on Elixir OTP 23 or 24 you should upgrade to the latest patch.

specifically OTP 23.3.4.5 or OTP 24.0.4
If you are on an OTP version older than 23, the good news is you will be unaffected so long as you do not upgrade your dependencies. You can freeze your dependencies in order to buy yourself time to upgrade to OTP 23 or 24.
Read 5 tweets
14 Sep
Today's summary thread! @ElixirOutlaws with @Adkron, and @ChrisKeathley. Episode 101: Bright and Tight.

open.spotify.com/episode/6YW6Qb…

This episode was packed with information on handling errors in Elixir.

#elixirstatus #elixirnewbie

🧵0/10
Error handling can be tricky, and can cause a task you would expect to take a single day to instead take a whole week!

1/10
This episode is focused on dealing with errors caused by working with external services. Anytime you're dealing with external dependency, you expose yourself to risk.

2/10
Read 11 tweets
13 Sep
Listened to @BeamRadio1 Episode 18: Code Heresy with Chris Keathley.

Today's panel: @lawik @akoutmos @_StevenNunez @redrapids, @sm_debenedetto, and special guest @ChrisKeathley.

Summarizing some interesting and controversial opinions today 🧵 0/24

#myelixirstatus #elixirnewbie
By far the most loved library on the Panel today was Telemetry. Telemetry powers monitoring and observability in elixir projects and provides a consistent interface to do so. Other mentions were OTP, Livebook, and site_encrypt.

1/24
When members of today's panel came into the Elixir Industry, they found opinions they like and trust from the Elixir community but also questioned established norms. Thus today's topic: Code Heresy.

2/24
Read 25 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(