Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8370291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:52:49+00:00 2026-06-09T13:52:49+00:00

I have used Style Cop for making sure people follow set code standards before

  • 0

I have used Style Cop for making sure people follow set code standards before but then configured it to our needs. For a few days now I have used Style Cop with its default setting to try it out and I’m a bit puzzled by some things. For instance, if I declare a variable I really like to state what type it is.

 int foo;

or

 Bar foo = new Bar();

Style Cop wants you to use the var keyword a lot.
I understand that you, the compiler and the IDE can figure out the type by the instantiation.

  var foo = 1; // Makes foo and int
  var foo = new Bar(); // Makes foo a Bar

When declaration and instantiation is done in one step it’s fairly visible whats going on.

There are a few more things that I’m not quite comfortable with that Style Cop seems to like so I basically just wanna know how common is the coding style enforced by the standard Style Cop configuration, and where does it originate from?

Note: This usage below of var is not valid as stated by hvd. Made me feel a bit better of var straight away ;). I leave it in since it was in the original question though

But if you have some obscure thing like

  var foo

     ... bunch of code ...

     foo = getLatestData();

It’s not obvious what foo becomes. But looking at the declaration of foo you won’t get any smarter. Instead you have to look at the declaration of the getLatestData function.

I feel that the var approach clouds everything a bit. There is no strict control like you get if you declare that foo is a int. Then you know that foo is always an int. It doesn’t depend what it get’s its data from. Something like this could very well give you two different types of foo.

var foo;

...

if(status == 0) {
  foo = getLatestData();
}
else {
  foo = getOtherData();
}

There’s nothing enforcing that the two functions have to return the same type and foo can thus become different things. When you code everything yourself and it’s contained like this it’s probably easy to keep track of. But if it’s an API or plugin library it would be a nightmare if external 3rd party developers cold dictate the type of foo since you could not be sure what to do with it in that case.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:52:50+00:00Added an answer on June 9, 2026 at 1:52 pm

    You question has some misconceptions about var which have been picked up in the comments and clarified in the linked MSDN reference.

    As to the actual question, I would infer that the code style enforced by the default Style Cop rule set is at least as common as the usage of the default Style Cop rule set. This answer is a tautology of course but, correct for the remnant of the question.

    If you have more concerns about the var keyword you could consult many of the existing answers on the subject, here on Stack Overflow.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used the twitter button resources to generate code for a follow button,
I have used input type image to display my custom style buttons, but for
I have used CSS before and I came across the below CSS style, don't
For a multi-langue site I have used the following code to automatically redirect people
I have used the following code to make a table but in the tag
I have the following markup that is used to produce a pop-up style mega-menu
Yesterday I have started developing my first Metro style App using JavaScript. I've used
I have used the silverlight control in CRM 2011.It also published on form but
I have used a plugin that uses prototype js, it's working fine but the
I have used NSSets many times in my apps, but I have never created

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.