5

I find now that I work in a mostly solo environment that I actually type fully qualified methods calls more and more, instead of make use of the using directive. Previously, I just stayed consistent with the most prominent coding practice on the team.

Personally, I find it easier to read verbose code at a glance, I type fast especially with autocompletion and I find myself using Google more often as my source of documentation, which a fully qualified name returns a much narrower results set. These are obviously very arbitrary reasons to prefer fully qualifying over using the using directive.

In this day and age of refactoring tools, is there a concrete reason why using the using directive is superior to fully qualified or vice versa, or is this purely a personal discretion issue like comment spacing? Finally, which do you prefer and why?

Cade Roux
  • 88,164
  • 40
  • 182
  • 265
Serapth
  • 7,122
  • 4
  • 31
  • 39

4 Answers4

4

Probably could call this subjective.

Where I work/What I prefer is to use using statements. It keeps the names/lines short enough, which just makes day to day life easier. Plus, you can just hover over something for the fully qualified name.

Finglas
  • 15,518
  • 10
  • 56
  • 89
2

I use usings whenever possible. The less there is to read, the less I have to parse:

System.Windows.Form form = new System.Windows.Form();

is just way more work than

var form = new Form();

Please note that this does require that your entire shop commits to not doing something silly, such as creating your own super-duper Form class which causes ambiguity.

Stu
  • 15,675
  • 4
  • 43
  • 74
  • Using var here makes this worse to read. If it was explicit, that would be better. – Finglas Jun 09 '09 at 18:15
  • 1
    I have a feeling var is going to go down in C# history as the most misused feature. It can create some very hard to understand code very easily. – Serapth Jun 09 '09 at 18:42
  • I strongly disagree. Reading from left-to-right, I should know by the time I hit '=' what the variable is and what it is called. I prefer to accomplish both by giving the variable a meaningful name and making it as short as possible. Also, consistently using var makes it easy to swoop through code and picking out the variable declarations at a glance. – Stu Jun 09 '09 at 18:43
1

I generally prefer using/imports for real code and fully qualified code for examples/etc.

lance
  • 16,092
  • 19
  • 77
  • 136
1

Readability.

Think about yourself in 1 year, trying to read your code. You want it to be explicit and short and have only one point of information for each data (DRY principle).

Klaim
  • 67,274
  • 36
  • 133
  • 188