Why create GetReachLineStart when refactoring?

When I refactored, I created a GetReachLineEnd() since it was clearly needed.

However, I didn’t bother creating a GetReachLineStart() as I could accomplish the same thing with the following function call that could be used anywhere that the method was called: “GetOwner()->GetActorLocation()”

I added GetReachLineEnd() to keep my project in parity with the course (sometimes valuable lessons are non-obvious for future lectures, so I generally follow the instructions while preserving my own attempts commented out for future reference). In this case, my GetReachLineEnd() method simply returns “GetOwner()->GetActorLocation()”.

I understand the need for clarity, but “GetOwner()->GetActorLocation()” seems self-explanatory when used in-line. And it seems cleaner than using 2 variables to call a function with extraneous return data. I am using Unreal 4.17, so I don’t know if the GetActorLocation() function was added sometime after 4.10 (used to create these lectures).

Am I missing something? Or is this simply a difference of style/preference?

Thanks!

…anyone? I realize this is a bit of an esoteric programming question, but I’m here to learn. Is Ben or another instructor active on these forums?

I agree that extracting the GetReachLineStart() function is optional and that it may seem overkill for some, but I personally think it helps making the code a little easier to understand and more high-level.

Easier to understand: when someone later comes to take a look at the code, if they see a GetReachLineEnd() method and not a corresponding GetReachLineStart(), it will probably make them unnecessarily wonder for a moment about the reason for that. They will have to find the explanation by looking into the code and then going “oh, I get it, the start is the actor location itself”.

More high-level: The method gives a semantic meaning to the actor location, in the context of the Grabber class. We translate the concept from the problem domain to the solution domain, in a self-documenting way.

Thanks for the response, vbarata.

I follow you. It does seem like a good habit to get into, so maybe I’m just splitting hairs.

Privacy & Terms