Muutke küpsiste eelistusi

Metaprogramming Elixir [Pehme köide]

  • Formaat: Paperback / softback, 120 pages, kõrgus x laius x paksus: 310x210x20 mm
  • Ilmumisaeg: 23-Apr-2015
  • Kirjastus: The Pragmatic Programmers
  • ISBN-10: 1680500414
  • ISBN-13: 9781680500417
Teised raamatud teemal:
  • Formaat: Paperback / softback, 120 pages, kõrgus x laius x paksus: 310x210x20 mm
  • Ilmumisaeg: 23-Apr-2015
  • Kirjastus: The Pragmatic Programmers
  • ISBN-10: 1680500414
  • ISBN-13: 9781680500417
Teised raamatud teemal:

Write code that writes code with Elixir macros. Macros make metaprogramming possible and define the language itself. In this book, you'll learn how to use macros to extend the language with fast, maintainable code and share functionality in ways you never thought possible. You'll discover how to extend Elixir with your own first-class features, optimize performance, and create domain-specific languages.

Metaprogramming is one of Elixir's greatest features. Maybe you've played with the basics or written a few macros. Now you want to take it to the next level. This book is a guided series of metaprogramming tutorials that take you step by step to metaprogramming mastery. You'll extend Elixir with powerful features and write faster, more maintainable programs in ways unmatched by other languages.

You'll start with the basics of Elixir's metaprogramming system and find out how macros interact with Elixir's abstract format. Then you'll extend Elixir with your own first-class features, write a testing framework, and discover how Elixir treats source code as building blocks, rather than rote lines of instructions. You'll continue your journey by using advanced code generation to create essential libraries in strikingly few lines of code. Finally, you'll create domain-specific languages and learn when and where to apply your skills effectively.

When you're done, you will have mastered metaprogramming, gained insights into Elixir's internals, and have the confidence to leverage macros to their full potential in your own projects.

Acknowledgements ix
Introduction xi
1 The Language of Macros
1(20)
The World Is Your Playground
1(6)
Macro Rules
7(1)
The Abstract Syntax Tree---Demystified
8(3)
Macros: The Building Blocks of Elixir
11(5)
Code Injection and the Caller's Context
16(4)
Further Exploration
20(1)
2 Extending Elixir with Metaprogramming
21(22)
Custom Language Constructs
21(6)
Smarter Testing with Macros
27(6)
Extending Modules
33(3)
Using Module Attributes for Code Generation
36(3)
Compile-Time Hooks
39(3)
Further Exploration
42(1)
3 Advanced Compile-Time Code Generation
43(22)
Generating Functions from External Data
43(2)
MIME-Type Conversion in Ten Lines of Code
45(4)
Building an Internationalization Library
49(9)
Code Generation from Remote APIs
58(5)
Further Exploration
63(2)
4 How to Test Macros
65(10)
Setting Up Your Test Suite
65(1)
Deciding What to Test
66(2)
Integration Testing
68(4)
Unit Tests
72(1)
Test Simple and Test Fast
73(1)
Further Exploration
74(1)
5 Creating an HTML Domain-Specific Language
75(20)
Getting Domain Specific
75(1)
Start by Defining the Minimum Viable API
76(6)
Support the Entire HTML Spec with Macros
82(2)
Enhance Your API with HTML Attribute Support
84(3)
Generate Less Code by Walking the AST
87(4)
To DSL or Not to DSL?
91(2)
Further Exploration
93(2)
6 With Great Power Comes Great Responsibility (and Fun!)
95
When and Where to Use Macros
95(3)
Avoiding Common Pitfalls
98(5)
Bending the Rules
103(3)
Build the Future
106
Chris McCord is a programmer with a passion for science and building things. He spends his free time crafting the Phoenix Web Framework, speaking at conferences, and teaching others the tools of the trade. He loves community outreach and helping to grow Elixir's wonderful community.