Why use properties instead of setters/getters?

Code size, mostly. Setters/getters have a small amount of PROGMEM and SRAM cost, and while a single one is small, many settable things can have a significant impact on code size. If I recall correctly, we’re talking about over a hundred bytes saved by using public properiets instead of accessors.

While accessors have a lot of uses, and I’d prefer them on code that runs on less constrained hardware, when resources are as limited as they are on the AVRs used in the Model01, practicality wins over doing things Right.

We could use macros as a compromise, but macros have the disadvantage of being global. I can’t make MouseKeys.setSpeed(x) a macro, and MOUSEKEYS_SETSPEED(x) feels wrong, and unintuitive.

(Moved the discussion to a new topic, this may very well end up being interesting later on too, and a separate discussion feels useful to have on it.)

1 Like