“As soon as I made the change I felt it needed comments as beforehand
it was self explanatory.”
That’s exactly it. If it makes you say that, then, if possible, you should
find another way to accomplish your original goal (in a clearer way). You
should always go with “self explanatory” if it doesn’t incur additional costs.
And the latter is also really important (the cost bit)
“So you think the use of a struct would be a good alternative - no
repeated code and a bit more clarity?”
Yeah, either return a struct, or make a function with two out parameters.
TBH, i don’t mind out parameters as much as others do. Seems like the
lecturer really dislikes them, and i can see that they can be a bit too
confusing and easy to miss, but as long as you label them properly in teh
function parameters (e.g. “float& OutPlayerPosition, float&
OutLineEndPosition”), i think it’s fine.
I think this is a good point to bring up that you need to keep in mind the
cost/efficiency of your code as well. In commercial game development cost
and efficiency always comes first, only then clarity and ease of
understanding. I don’t know how experienced you are with the programming,
and if not a lot, then you shouldn’t worry about this right now at
all, but I’ll mention it just for the sake of argument. So for example, if you combine
two (or more) functions into one that returns a struct that has bunch of
different values, but if every time you call the function you only need one
of those or two (or simply, if you dont need everything it returns every
time you call it), then you’re wasting space/memory/processing time and
power by creating the struct with bunch of values that you won’t need. In
your original example, you would need to call your function twice in a row,
once to get teh player position, and then again to get end line position.
Each function call will perform
"GetLocalPlayerController()->GetViewPointPsitionAndRotation(pos,rot)" each,
when you actually could just call it once, use the values it returns once
to calculate what you need and then return both at the same time (either in
a struct or out parameters).
In this particular example the extra cost is completely negligible, but it
illustrates the problem or a general idea, of where the cost goes, and it
could get really costly really fast when you start dealing with huge
objects that store a lot of things, or performance intensive functions
(bunch of loops done multiple times, etc.). Like i said, if you’re a
beginner, you shouldn’t worry about such things, but thought I’d explain it
if you’re interested in this kind of thing.