In the world of programming, there’s often more than one way to do things. When writing code we often try to strike a balance between performance, readability, and maintainability. The priority given to these properties usually depends on the type of application.
With regard to the code you shared, I would encourage you to take a look at the actual implementations of the GetName
function in UObjectBaseUtility.h
. You can see that they essentially do the same thing - one version of the function returns an FString
, and another version of the same function (called overloading) takes in a reference to an FString that can be modified (notice that the parameter is not const
qualified). It is the latter version that you are calling with your code. Also notice that both functions are decorated with FORCEINLINE, meaning that they will be inlined at compile time (you can read about the pros and cons of inline functions here.
So, the short answer is: in this case it really comes down to personal preference. There’s nothing wrong with your code if it is more readable to you and it performs the intended task. At this stage I would say it is more important that you understand what the code does so you can apply that knowledge in the future.