10 Macros and the outside world

 

This chapter covers

  • Using a single library to expose multiple macros
  • Adding or disabling functionality with features
  • Using attributes for control over what code will be generated
  • Documenting and publishing a macro library
  • Moving on to explore interesting macro subjects beyond this book

In previous chapters, we have often made excuses for taking shortcuts, explaining how “production-grade” macros would do things better or differently. In this, our last, chapter, we will create a macro for making available YAML config that tries to do everything right. While its functionality will be very limited, it will have proper testing, error handling, documentation, and the like, making it (almost) ready for use by other people.

And that is great because publishing a library means your macro might find use among other developers, enriching the ecosystem of the language you love. Even libraries written within a company, with a specific use case in mind, might benefit from being open source. People might discover bugs or send pull requests with fixes and improvements, helping you to improve the quality of your code, to everyone’s benefit. This chapter also offers an opportunity to bring together a few miscellaneous topics, like features, which can help you make your macro as lightweight as possible.

10.1 A function-like configuration macro

10.1.1 Macro project structure

10.1.2 Code overview

10.1.3 Using full paths

10.2 Adding another macro

10.3 Features

10.4 Documenting a macro

10.5 Publishing our macro

10.6 From the real world

10.7 Where to go from here

Exercises

Summary