Summary

In this chapter, we have looked at several patterns related to improving the readability and maintainability of an application.

First, we learned about when a module becomes too large and when it should be considered for reorganization. We realized that coupling is an important consideration when splitting code into separate modules. Next, we discussed the problem of constructing objects that have many fields. We determined that using a keyword-based constructor can make the code more readable and can provide additional flexibility of supporting default values. We learned that the Julia Base module already provides a macro.

Then we explored how to do code generation, which is a convenient technique for dynamically defining many similar functions without having to repeat the code. We picked up a utility from CodeTracking to review the generated source code.

Finally, we went over details about how to develop DSLs. It is a good way to simplify code by mimicking the syntax with the original form of the domain concepts. We used an L-System as an example for developing a DSL. We picked up several utilities from the MacroTools package, where we can transform our source code by matching patterns. We learned how to use the postwalk function to examine and transform source code. And, pleasantly, we were able to complete the exercise with very little code.

In the next chapter, we will go over a set of patterns related to code safety. Enjoy reading!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.190.93