Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Visual-Studio
Reading through a few books some authors recommend that each class gets its own .cs file. Along with each interface, enum, delegate, and struct.
 
As a group we use Resharper and Resharper even has a tool that will automatically separate all of the mentioned types above into their own files with the push of a button.
 
I believe this is better for maintainability, but in order to convince my group to adhere to this what other, if any, benefits does this accomplish?
Posted 11-Oct-12 8:14am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

There are no specific advantages or drawbacks.
 
It's only about readability of the code text; and it does not effect anything else. Perhaps if you put several classes in one file, you would like to have some comments delimiting them, in addition to other stuff, which could eat up some extra space. It also depends on total number of lines in the file. Some say one file per type is a must, but I think this would be pointless pedantism. As soon as you can easily find your code and manage files, all those detail don't matter.
 
Now, how to convince the group? Here is my idea: you need to relax everyone in terms of directory structure and file, but demand strict commenting style (and of course, correct project/solution structure, assembly signing procedure, no repeated artifacts, etc.). Most important stuff is the proper use of Revision Control System (and if you don't use a good one properly, consider you are not doing any development at all).
 
Even about the formatting. With Visual Studio, I invented a good rule to make if convenient for everyone:
 
Every developer can use her/his own formatting style, as soon as it is fully formed by auto-formatting, but the formatting rules should vary, even file to file. Now, in those relatively rare cases when one developer modifies the file owned by another developer, this person has a full right to reformat it to her/his liking and commit the code to the Revision Control System. The original author does not suffer, because she/he can reformat it back at any moment of time. My rules mostly apply to C# where the auto-formatting is done in a comprehensive way with Visual Studio.
 
[EDIT]
 
Many really good developers are overly sensitive to formatting and layout styles. It's very important not to hurt such people by enforcing redundant rules/policies. Be very careful!
 
[END EDIT]
 
—SA
  Permalink  
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 295
1 DamithSL 295
2 Sergey Alexandrovich Kryukov 197
3 Peter Leow 155
4 Afzaal Ahmad Zeeshan 154
0 OriginalGriff 7,510
1 DamithSL 5,494
2 Sergey Alexandrovich Kryukov 4,954
3 Maciej Los 4,936
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 11 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100