jalberse / shimmer

Physically based rendering in Rust
Apache License 2.0
33 stars 0 forks source link

Improve struct initialization choices #29

Open jalberse opened 8 months ago

jalberse commented 8 months ago

I tend to define a new() constructor pattern in many places, but I'm starting to think it's not the best fit in all situations. We might instead prefer to have plain struct initialization (which allows for some useful default syntax) or builder patterns.

I'd like to go through and examine struct initialization patterns in the code and clean them up if there's better approaches for each struct. I think it will vary on a case-by-case basis.

https://stackoverflow.com/questions/19650265/is-there-a-faster-shorter-way-to-initialize-variables-in-a-rust-struct https://xaeroxe.github.io/init-struct-pattern/

jalberse commented 8 months ago

For example, UVMapping has useful defaults (1, 1 for scaling and 0, 0 for offsets), so a struct initialization pattern with those being th edefaults, and users just specifying changes if they want, is likely better than a new() specifying all 4 values without defaults.