3 ms·
Personally I think if you need a builder, you did something wrong in the first place. If you have a struct with so many defaultable values, you should break it
by po1nt 5y ago
Personally I think if you need a builder, you did something wrong in the first place.
If you have a struct with so many defaultable values, you should break it into smaller pieces. Reasonable struct should not need more than 5 properties, unless it's something like ORM mapping of database table.
- skohan 5y agoIt's a nice rule of thumb, but it's not always practical. For instance, something like a vulkan compute pipeline has a ton of parameters just due to the complexity of the domain, and breaking it down into sub-objets to a greater extent than is already done would just add artificial hierarchy.
- hota_mazi 5y agoI don't know where you pulled that 5 number from but it seems to come out of thin air. Besides, breaking structures in smaller structures this way can lead to code that's much harder to follow, refactor, and maintain.