juniperparsnips / rink-runtime

Rust implementation of inkle's open source scripting language runtime engine.
MIT License
1 stars 2 forks source link

Public struct fields vs getters/setters #12

Open IFcoltransG opened 1 year ago

IFcoltransG commented 1 year ago

@juniperparsnips commented on #8 that it would be useful to decide when to give a struct getter and setter methods for fields, and when to simply make the fields public.

Rink Runtime started as almost a direct translation of C#, so it used almost all of getters and setters. I thought many were unnecessary in the Rust version.

Some pros of getters:

Some pros of public fields:

My personal feeling for the cleanest code is to use as few getters and setters as possible, only when needed for doing extra logic, then restrict privacy for the fields only to the scopes they're needed.

LeCalicot commented 1 year ago

I would agree with you. Most of the fields are going to be internal to the crate, so there is no point in creating getter/setter everywhere. As you said, only if there is some complicated logic to set the fields it makes sens to have a setter.

IFcoltransG commented 1 year ago

It sounds like we should just proceed with mostly public fields for now, then do a pass over them all sometime, where we restrict visibility e.g. pub(crate) to only the parts of the codebase where it's needed.