> > As for getters and setters, I've thought about them, but I'm really > inclined to say YAGNI here. C# added them, and they actually accrued a lot > of complexity over time (autogenerated getters and setters, etc). You can > pretty easily make a function opts() and set_opts(). Our complexity budget > is very strained as it is. > > Patrick > > > Yes you can easily make a function BUT - Your spending a lot of time making Rust brief yet hear you are writing a function for every field.. that's a lot of brain dead code.. When C# started , first they thought properties were a nice to have but later properties became a representation that means you want to export it . This allowed objects to control what was exported but without the internals being exported. So objects in the GUI bind to properties but not fields , likewise most serialization and ORMs used public properties to indicate the user wants to export this.. Since it became so common (and you would most certainly not write professional C# code without public properties and private fields , ) the new auto property was introduced to reduce it eg
int field { get ; set; } ; OR int field { get ; private set; } ; Which as most of you know generates a hidden field wrapped by public properties succinctly. This covers 80% of cases but in the other cases where you need to manipulate it you still need the field and property That said personally I think there is no point having properties and prop functions unless you can have "private" fields which im not sure Rust can do as you need a "this" pointer which then makes you an OO language . You are then on the bitc path and you get into a lot of confusion in whether to use a trait or a class for polymorphism ... I do however like something like the HasField constraint so you can hide the datastructure but expose the fact it has a particular field eg a count on a collection but you can hide everything else. Anyway so what is Rusts position on data encapsulation , how do you simply hide some of the data without something nasty like hiding it behind a external lookup function ? Ben
_______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev