January 2020
Intermediate to advanced
532 pages
13h 31m
English
Let's first take a look at how a struct is defined and what constructor is provided. Consider the use case of text style configuration for a text editing application.
We may define a struct as follows:
struct TextStyle font_family font_size font_weight foreground_color background_color alignment rotationend
By default, Julia provides a constructor with positional arguments for all fields in the same order as how they are defined in the struct. So, the only way to create a TextStyle object is to do the following:
style = TextStyle("Arial", 11, "Bold", "black", "white", "left", 0)
There is nothing wrong here, but we could argue that the code is not very readable. Every time we have to write code ...
Read now
Unlock full access