Question: Renaming windows forms?


I’m working on resolving an issue, and the way that we decide depends upon the prevalence
of a specific scenario. I’d like to know your opinion on the following Windows Forms
scenario.

How often do you rename the form class without renaming the file that holds the form
class? ie how often do you change “class EmployeeForm” to “class AddressForm” without
also renaming the form file?

Thanks

 


Comments (58)

  1. Ryan Farley says:

    I always rename the file when I rename the form. I can’t think of any time when I have renamed the form class and have not also renamed the file to match.

  2. Kurt says:

    Never! I’d be incredibly happy if I could simply change the name of the file and have the class and various constructors’ names change as well.

    My file and class names always match.

  3. Andy Smith says:

    I change the class name without changing the file name all the time because the vstudio/vss integration sucks.

    Sometimes it’s logical to change the class name, and it’s easy to do so. However, changing the file name is a huge hassle when working with a project under sourcesafe.

    Of course I would prefer to keep them in sync, but it’s just not going to happen until the VSS integration works better.

  4. Martin Crimes says:

    As Andy says, it’s annoying to have to mess around with Sourcesafe for filename changes, but I still make a point of always doing this whenever I change a classname.

    Once you start to slip even a little bit from the strict filename-class linkup, you’re inviting chaos 2 years down the line when the example has been followed and the whole project’s gone to hell.

  5. Stuart says:

    >>how often do you change "class EmployeeForm" to "class AddressForm" without also renaming the form file?

    Never

  6. Bruno Jouhier says:

    I always rename both.

    Actually, besides improving the IDE so that the class and files can be renamed together, it would be nice to have a project setting to enforce the match between public class names and file names (the way Java does it). I ‘d like to enforce this convention in my team because it helps locating classes when you work with big projects.

    Also, the Class1.cs or Form1.cs file that gets created automatically is just a pain. I always remove it because my classes are in subfolders. Would be nice to have a global setting to turn this "feature" off too.

  7. Andy Smith says:

    Just to give some background info. here is the url to the relevant MS KB article:
    http://support.microsoft.com/default.aspx?scid=kb;en-us;305516

    I’m sorry, but a 5 step process to rename a file is not acceptable.

  8. Sasha says:

    Never.

    Even with VSS issue, I simply copy the code from the file, delete it, create a new file with the correct name, and paste the code into it. Works like a charm for me.

  9. Chris says:

    Same as Andy, but I’m using CVS instead of VSS; I’ve not yet figured out how to rename files in CVS without messing up the whole version tree, so I rarely rename file names…

  10. Never, but we have to dance around SourceSafe. To do that, we: 1) create new WinForm with the correct name; 2) Copy all code from old form to new, changing the class name; 3) DEL old form from project.

  11. Never. It would be really nice to have them synchronized.

  12. Never. It would be really nice to have them synchronized.

  13. Eric says:

    Not since my first "medium sized" project that I had to go back and work on a couple of months late.! Do so is "evil" and causes many problems in the future.

  14. The only time it seems useful to rename the class and not the file is when you’re using version control. CVS especially makes it hard to rename files, but really it’s a pain in the neck for any version control system that doesn’t have great VS integration for renaming files.

  15. The only time it seems useful to rename the class and not the file is when you’re using version control. CVS especially makes it hard to rename files, but really it’s a pain in the neck for any version control system that doesn’t have great VS integration for renaming files.

  16. Addy Santo says:

    Sometimes I find myself using more than one form in a file, mainly when using visual inheritance. In some cases there is a base form and several specialized child forms. A factory returns either the base or a child, and the whole thing is stored in one source file (the child classes are ~10 lines of code each). It is simpler to manage, more VSS-friendly, and the difference between having 8 form files in the project instead of 50 is also a pretty big plus.

  17. Val Savvateev says:

    Renaming the file along with the class name is always a good idea, but it’s pain if your code is under source code control (SourceSafe, ClearCase etc). I find myself always changing the file name, but it’s kind of a surgery action and it should not be automatic unless it’s well integrated.

  18. Corrado Cavalli says:

    Never, I always keep them in sync.

  19. I always change the filename to match the class name. We have an entry in our company conding standards that says the two will always be in sync.

    Now… are you asking (as VC# PM) because you’re thinking about making this happen automagically in the IDE? I wouldn’t do that. Or if you do, at least give us the option to turn it off.

    Rules are meant to be broken.

  20. milbertus says:

    I too usually do my best to keep them in sync. This is only a challenge for the initial class/form in a project, which I’ll inevitably have to rename because Class1.cs or Form1.cs just won’t work.

    Is there any reason why we can’t choose the name of that initial file when the project is created? That would help to keep things more consistent with creating new files to add to the project, where they can be renamed.

  21. Chris Kinsman says:

    Always

  22. Steve Hiner says:

    Always

  23. Alan Dean says:

    I always keep the names of single-class files in sych, but as a number of other commentators have pointed out – I really hope that we get a VSS worthy of VS.NET. Also, when I refactor a class name I would like to see the other code in my solution reflect the change – hopefully we’ll see some of this in Whidbey?? can’t wait for the PDC IDE Session 🙂
    Bruno Jouhier has good points about convention enforcement and project templates.
    Addy Santo has an excellent point about multi-class files (but surely the IDE will know that there is more than one class in the file…)

  24. Frank Hileman says:

    Never. Please add the feature to keep them in sync.

  25. Andrew Coats says:

    I always keep the filename and the class name in sync.

  26. hsdo says:

    Never.
    If there are several classes in a single file, I use the name of *main* class as filename.

  27. Mark Hurley says:

    I always rename the file, but it is a pain. I highly prefer the "synch" option. Thanks for asking Eric!

  28. Klaus Probst says:

    Never. As others have said, it would be handy if the IDE renamed the type along with the file!

  29. Keith Hill says:

    I frankly don’t see why the filename should have a darn thing to do with any of the type names inside of it – WinForms or no. I sympathize with the folks who struggle with VS/SCCI integration issues. Renaming project items/projects/solutions really sucks but this should be addressed by the SCCI support. I also have personally helped at least 3 folks who have placed a class before their main form class delcaration. I believe this particular issue should also be fixed.

  30. De Preester Dieter says:

    I always rename te file to the same name as my class. I

  31. Paul Jackson says:

    I *always* rename the file as well, even with all the Visual Source Safe headaches.

  32. dan says:

    I always rename the file to the same name as my class
    this improve the redability and maintanability

  33. Aronne says:

    I always rename the file name to match the name of the class (not just on Forms). That’s because I use ONE file per class, enum or delegate.

  34. >how often do you change "class EmployeeForm" to "class AddressForm" without also renaming the form file?

    Never!

  35. Derek Lakin says:

    The class name and file name always match, though I rarely rename a class during development, but always rename the default Class Wizard generated Class1/Form1/etc. to something meaningful.

  36. Julien Adam says:

    Every once in a while when i’m in a real rush. But it’s only a matter of time before it starts to upset me and I set it straight again. Please make it an automatic, integrated with source control, easy one-step process.

  37. Sam Meldrum says:

    I would always rename the file, BUT, when working in a team environment, using VSS, you have to be really careful about how you do it, and then making sure everyone else in the team knows you’ve done it. Otherwise it ends up looking like they’ve got the old file checked out to them, so they check it back in. Aargh! One of my developers, who hates VSS, very rarely renames or deletes a file. He will then go back and do all the renaming etc when the project is complete.

  38. Simon says:

    I use CVS for source control (integrated into VS with CVS Proxy). I have to leave the filenames the same even if I change the name of the class or I lose the version history. Please don’t force a filename change – this will really irritate CVS users. And there are lots of us!

  39. The only time I’d change the class name without changing the file name is if the file is already under revision control. Surce Safe (and every other revision control system I’ve used) makes changing file names just too much trouble to bother.

  40. Carlo Cardella says:

    Never. It’s a lot easier to manage projects and files

  41. Always! Makes more sense… as things are in order.

  42. Jeramie Mercker says:

    I always keep the 2 in synch.

  43. Nikhil Krishna says:

    I always try to keep the filenames and classnames in synch.
    Sometimes however I find myself in a position of renaming the class. However renaming the file to synch with the new class name is cumbersome when the project is under source control to say the least
    I feel there must be a better integration between the sourcecontrol and the IDE for renaming files.

  44. Roberto says:

    I always rename the file when I rename the form.

  45. Cronos says:

    Always! I usually only change the class name without changing the file name for the main window. But if I add a new windows form to the project, I change both class name and file name.

  46. I always change the filename to match the class. I make the change manually in VSS.

  47. Maybe it’s my Java background, but I always keep my class- and file-names in sync.

    Does the fact that you’re asking this question mean that MSFT is working on adding refactoring support to VS.NET? If automated, I’d say that if the class- and file-name currently match, rename the file-name along with the class to keep them in-sync. If they don’t currently match, leave the file-name alone.

  48. Chris Jackson says:

    What everyone else said. I have never once wanted to change one name without changing the other, and I sure wish that it could sync up with VSS when a name does change.

  49. To your specific question: whether I have a form class in a file with a different name: not very often.

    However, what really irritates me is that I always have to rename Form1.cs to something descriptive and change Form1 to a real class name. If I change the form name through the property grid I still have to search for, and replace, the Form1 in the Main function. I have to do this whenever I start a new project, and it could easily be prevented if the project wizard asked me the name to use for the form.

  50. Jason Kaczor says:

    I always keep them manually in sync. Its’ a real pain in the ass when I am doing a demo/class.

  51. Ian Ringrose says:

    Renaming a file can be a big pain, if at all possible. E.g. what if I am not connected to the SCC system at the time I what to rename the form. How do a merge in changes that have been made to the code by someone that is offsite if all the file names have changed? How do a do a ‘back build’ if I do not even know what the file was called in the version of the software I am trying to merge the fix into?

    Remember source code control systems are often in place for decades and you have to get agreement of ALL the state holders before you change your corporate system, this include all the UNIX and mainframe programmers that are using the same source code control system.

  52. Eric,

    I ^always^ rename the file if I am renaming the class inside. I think you will find that to be the case 99.99% of the time.

    – Nick

  53. Ilya Ryzhenkov says:

    Class & file name are almost always in sync, except few cases:
    1. File BlahEvent contains BlahEventHandler and BlahEventArgs
    2. Some helper files may contain several enums and/or small structs

  54. Anonymous says:

    This sounds promising for new files where you type the wrong filename. For existing files, does it also mean that everyone is prepared to have VS going throughout all the project code changes places where it is instantiated? Or does the project just not compile? What about the files that get changed that aren’t checked out?

  55. Gavin Greig says:

    I agree with all the people requesting source-control-aware automated renaming. Although I think this should be the default behaviour, since it sounds like the source control integration might be tricky for some systems (such as CVS) it should also be possible to turn it off.