Underscores are perfectly fine

I have noticed a stigma attached to underscores being used in method or variable names. For example, most people I have worked with prefer AMethodNameLikeThis() over a A_Method_Name_Like_This().

I suspect this is mostly due to tools like Resharper and Visual Studio “complaining” about underscores by default.

This default is silly, I believe. Long method names (as long as they are descriptive!) are a good thing, and underscores make them more readable. When I have the opportunity I always user underscores to make the code more readable, and thus more maintainable.

To change ReSharper’s (v10) default treatment of underscores, navigate to ReSharper -> Options -> Code Editing -> C# -> Naming Style. You will notice that each naming style has a “UnderscoresTolerant” equivalent.

Despite this, I think it is more important to stick to the team’s standards. So if the standards say “don’t use underscores”, then it’s best to stay clear.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.