Chris McCord discusses his book and the appeal, challenges, and benefits of metaprogramming in Elixir. They explore examples of building a DSL for frameworks like Phoenix and the usage of macros in testing.
Meta programming in Elixir allows code to be written that writes code, making it easy to dip into Elixir's data structures and produce powerful code generation.
Macros in Elixir and Erlang provide opportunities for innovative testing approaches, enhancing code coverage, static analysis, and test generation.
Deep dives
Overview of Meta Programming in Elixir
Meta programming in Elixir allows code to be written that writes code. It offers a natural syntax over an abstract syntax tree (AST), enabling the generation of code by writing code. This AST allows code to be built like Lego building blocks, making it easy to dip into Elixir's data structures and produce powerful code generation. Unlike other languages with meta programming, Elixir's macros have a full programmable AST, simplifying the process and making it accessible to developers.
Use of Macros in Phoenix Framework
Macros in the Phoenix framework have proven to be highly effective. Examples include the routing layer, where macros generate functions at compile time, enabling efficient dispatching. The templating layer allows developers to use embedded Elixir syntax, but other templating engines can be used by providing the Elixir AST. Additionally, macros are used in the Plug composition layer to define transformations on connections.
Advantages and Considerations with Macros
The effective use of macros in the Elixir community demonstrates their versatility and potential. They simplify code constructs and generate performance optimizations by leveraging the Erlang virtual machine. While macros can be powerful, caution should be exercised, and they should only be used when necessary. However, macros have been seamlessly integrated into the Elixir language and frameworks, thanks to their natural syntax and extensive macro system.
Potential Applications for Macros in Testing and Concolic Testing
Macros in Elixir and Erlang provide opportunities for innovative testing approaches. The community has explored their usage in areas such as matcher libraries, testing frameworks, and concolic testing tools. Macros can help enhance code coverage, static analysis, and test generation by utilizing the compiler's knowledge of the AST. While these applications are still emerging, they showcase the potential for macros to improve testing practices.
Guest speaker Chris McCord discusses his book with Zach and Bruce
Panel
Chris McCord @chris_mccord
Bruce Tate @redrapids
Zachary Kessin @zkessin
Conferences
Erlang Factory San Francisco 26-27 March–some of our regulars are there now! http://www.erlang-factory.com/sfbay2015/
Elixir Conf EU 23-24 April in Krakow http://www.elixirconf.eu/
Stockholm Erlang User Conference 9-10 June in Stockholm http://www.erlang-factory.com/euc2015
Links
Metaprogramming Elixir by Chris McCord
Seven More Languages in Seven Weeks by Bruce Tate
Get the Snipd podcast app
Unlock the knowledge in podcasts with the podcast player of the future.
AI-powered podcast player
Listen to all your favourite podcasts with AI-powered features
Discover highlights
Listen to the best highlights from the podcasts you love and dive into the full episode
Save any moment
Hear something you like? Tap your headphones to save it with AI-generated key takeaways
Share & Export
Send highlights to Twitter, WhatsApp or export them to Notion, Readwise & more
AI-powered podcast player
Listen to all your favourite podcasts with AI-powered features
Discover highlights
Listen to the best highlights from the podcasts you love and dive into the full episode