Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upGet/set design guidelines #882
Comments
bvssvni
added
information
draft
discussion
labels
Apr 19, 2015
This was referenced Apr 19, 2015
Merged
bvssvni
removed
discussion
draft
labels
May 1, 2015
bvssvni
closed this
May 1, 2015
bvssvni
referenced this issue
May 1, 2015
Closed
Rename `Ui::get_widget` to `Ui::get_widget_mut` #408
bvssvni
referenced this issue
Mar 22, 2017
Open
Thread for discussing docs and better introduction to Piston #1160
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bvssvni commentedApr 19, 2015
When writing methods for getting and setting options, you can have
&mut self,self,&selfetc. which can lead to inconsistent usage across libraries. The conventions here are used in the piston core and piston-graphics, and I suggest them as guidelines for all Piston libraries.set_it should take&mut selfset_method and you need a get, it should start withget_selfand returnsSelfThis means that builder patterns doesn't need
set_prefixes, for example:The method without prefix never gets in the way for the read only version, because when a property is read only you do not need a builder version. It also makes it possible to add either a read only or builder method later without breaking the API.
For mutable references to the interior of an object:
get_foo_mutwhen there is aset_methodfoo_mutwhen there is noset_methodRust API guidelines
The Rust API guidelines distinguishes between Builder patterns and ordinary objects, so the
get_prefix is removed for ordinary objects. See https://aturon.github.io/style/naming/README.html#getter/setter-methods-[rfc-344].In several Piston libraries the distinction between builders and ordinary objects is blurry, so we use
get_to avoid breaking the API.