Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I have the following:

   public class ContentsController : BaseController {
        private IContentService _content;
        private IPageService pageService;
        private IReferenceService _reference;
        private ISequenceService seqService;

        public ContentsController(
            IContentService contentService,
            IPageService pageService,
            IReferenceService referenceService,
            ISequenceService sequenceService) {
            this._content = contentService;
            this.pageService = pageService;
            this._reference = referenceService;
            this.seqService = sequenceService;
        }

Note that it's completely mixed up with different naming standards.

Is there anything recommended for the naming of services that are used by my controller?

share|improve this question
2  
belongs on code review. – Daniel A. White Sep 14 '12 at 13:02
1  
i wish code review was an option for where it should code in the flag menu. – Patricia Sep 14 '12 at 13:03
How can I change it to code review? Where is that? – Angela Sep 14 '12 at 13:12

migrated from stackoverflow.com Sep 14 '12 at 13:28

3 Answers

I don't think it matters as long as you are consistent. I personally prefer: _{servicename}Service format. ex. _referenceService

public class ContentsController : BaseController {
        private IContentService _contentService;
        private IPageService _pageService;
        private IReferenceService _referenceService;
        private ISequenceService _seqService;

        public ContentsController(
            IContentService contentService,
            IPageService pageService,
            IReferenceService referenceService,
            ISequenceService sequenceService) {
            this._contentService = contentService;
            this._pageService = pageService;
            this._referenceService = referenceService;
            this._seqService = sequenceService;
        }
share|improve this answer
yes, I use this same standard for naming. I would also remove the this. reference as another standard (albiet off topic from OP question) – dreza Sep 14 '12 at 20:11

IMHO, member variables should begin with an underscore and be descriptive

This is fine

private IContentService _content;

This is better

private IContentService _contentService;

BTW, using 'this.' in your constructor is redundant.

share|improve this answer
   
Using underscores is just one naming style and one that is not universally accepted. – svick Sep 14 '12 at 13:42
1  
@svick You are correct, edited my answer. I do like this convention best as it visually differentiates a member variable, and I can have the exact same name for my parameters (without the underscore), making the code very readable. Again, just MHO. – Forty-Two Sep 14 '12 at 13:59
@Forty-Two underscores or no underscores, this. or none these are a matter of style. One that makes minimal difference. What is more important is that there is a consistent style. – James Khoury Sep 18 '12 at 0:29
@james yes, huskey's answer above has already pointed that out, but thanks for your input. – Forty-Two Sep 18 '12 at 0:38

I'd recommend to use Microsoft's Guidelines for Names, so you can check your code with tools like FxCop.

Here are guidelines for your case:

  • Do not use underscores, hyphens, or any other nonalphanumeric characters (contentService instead of _contentService)

  • Spell out all words used in a field name. Use abbreviations only if developers generally understand them. Do not use uppercase letters for field names (sequenceService instead of _seqService)

  • Do use camel casing in parameter names (you did)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.