-1

Stylecop seems inconsistent in naming parameters or perhaps I'm missing something?

I have

    Movement movement;

    public void SetMovement(Movement movement)
    {
        this.movement = movement;
    }

which complains about my parameter hiding a field, which is understandable. Then I try to name the parameter differently

    public void SetMovement(Movement _movement)
    {
        this.movement = _movement;
    }

which will complain about underscores and Hungarian notations, etc.

It seems the only way to satisfy stylecop in this case would be to name the parameter something different like

    public void SetMovement(Movement movementParameter)
    {
        this.movement = movementParameter;
    }

Which of these would be considered the best 'style'?

Popsucker
  • 3
  • 1
  • 2
    I think most people would do `this.movement = movement;`. If you're strictly following StyleCop's rule here, you would need to name your parameter something different (I'd choose something like `requestedMovement` rather than `movementParameter`) – canton7 Aug 14 '19 at 16:05

1 Answers1

0

In this case, I would did (and I actually do) just the same thing you did: calling the parameter just the same as private field.
That code is pretty clear to me, despite StyleCop judgement
In other situations I use different names for parameters and equivalent fields, e.g. when the meaning of the passed parameters (and so its name) changes when it is injected in a method.
I'm not a StyleCop guy, but I think you can say it to not bother you using an attribute, a special comment or so
Maybe like this: How to suppress a StyleCop warning?

Ferdinando Santacroce
  • 1,047
  • 3
  • 12
  • 31