0

Better title suggestions are welcome.

I was working on a function that converts a world vector to a camera-local vector. It looks like this

Vector3 camAlignedMovementDirection = MovementDirectionToVector(movementDirection);

//We don't care about verticality.
camAlignedMovementDirection.y = 0;
camAlignedMovementDirection.Normalize();

return camAlignedMovementDirection;

Note that the actual code isn't that important. However I was conflicted with the naming of the particular function. At first I was using this:

private Vector3 GetCamAlignedVector()
{
    //Code
}

But I realised I could simply just do this:

private Vector3 CamAlignedVector
{
    get
    {
        //Code
    }
}

So I was wondering, which is the preferred style, and why, what are the pro and cons, are there any "common" rules to follow? Because (from my knowledge), both functions do exactly the same thing, and work exactly the same way.

One thing I realised myself is that by not using "Get" I will not clutter intellisense with a bunch of getter functions, and I'd personally say that's an "advantage", albeit minor.

PeppeJ
  • 603
  • 3
  • 11
  • 24
  • 3
    have a look at: [When to use properties instead of functions](http://stackoverflow.com/q/1374273/6400526) – Gilad Green Apr 15 '17 at 12:22
  • This is exactly what I was looking for, thanks! Post it as an answer so I can mark it :) – PeppeJ Apr 15 '17 at 12:28
  • Would have loved to post it as an answer but it is someone else's answer :) won't take the credit. Instead I'll make as a duplicate and it'll help others get to that question too – Gilad Green Apr 15 '17 at 12:29

0 Answers0