Question about different coding approaches

I solved the enemy health script slightly differently. I didn’t bother creating a new variable for Health and just used method chaining. This way I didn’t have to include the RPG.Attributes namespace.

Just out of curiosity, which way is more professional/efficient?

image

While either method works, it does have a potential unintended consequence, in that you’re hiding a dependency. (In C++, this would actually fail, as it would require you to include Health.h). While in this case (UI), it doesn’t really matter, it can matter in other contexts. It’s easy to find yourself with circular dependencies.

In terms of technical efficiency, under the hood the compiler is doing pretty much the same thing, though it’s possible it may save a stack push/pop.

1 Like

Thanks Brian, this is really helpful to know! :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.