June 2022
Intermediate to advanced
130 pages
2h 45m
English
When you’re building software that’s bigger than a side project, two language features often come into conflict: type safety and API design. When you’re building a structure with type safety, the idea is to give the compiler all of the data that you can so that the compiler can catch mistakes.
So, let’s think about the API for our SVG library. So far, the main output for our Shape will be an SVG string. That’s easy.
Add this function to your shape.ex file:
| | def to_svg(shape) do |
| | """ |
| | <polygon |
| | points="#{render_points(shape)}" |
| | style="#{render_style(shape)}" |
| | /> |
| | """ |
| | end |
That’s a simple function. The main syntactic trick is a feature called the heredoc, which uses """ to surround multiline ...
Read now
Unlock full access