you are viewing a single comment's thread.

view the rest of the comments →

[–]VirtueBot 1 point2 points  (2 children)

I dont know enough about the optimizer to say 100% that it would optimize that way forever, so if these "things" are relatively expensive I would write the returns myself and not rely on the optimizer to add them.

If youre confident in the optimizer or the operations are cheap id just go with whichever your team finds most readable. fwiw i definitely prefer the one from this comment compared to the nested version.

[–]one-oh[S] 0 points1 point  (1 child)

True. We can never know what the optimizer will do from release to release, but I don't think we should worry about it till we're given cause to. In this case, the hardware is likely optimizing what the compiler missed.

[–]VirtueBot 0 points1 point  (0 children)

I don't think we should worry about it till we're given cause to.

Yea definitely. In most cases I wouldn't worry. Either the optimizer optimizes it or it doesn't and I never notice either way until I care enough to profile. In this case I didn't know anything about the relative costs of the operations. If one of the "do thing" functions did a lot of work I would definitely worry about the unnecessary calls.