Is accessing the fields of a struct a good julia-style?

Before getproperty & friends, I would have said that accessor functions are the cleanest, but now I think that it is OK to explore an API with property accessors (x.something instead of getsomething(x)). That said, property names live in a single namespace (equivalent to Symbol), so one does not need to export/import them etc. This has advantages and disadvantages, and should be taken into account in the API design.

Whatever the choice is, the key part is documenting the API very clearly, at least in the docstring of the type or an abstract type, so that the user should have not wonder whether property accessors are supported, or just happen to work and may break.

6 Likes