views:

48

answers:

2

I had read in another post here on SO that when possible you shouldn't Generate Member's for labels. I was wondering what some potential DRAWBACKS to this would be?

Am I correct in saying that the benefit is increased performance? Anything else?

I have a winform app with 100's of labels. Is there any benefit to not generating members or is it only in Web Apps that you see a gain?

Thanks!

+3  A: 

Readability. If you Generate Members for all your labels, but you aren't using them, then it makes your code harder to read. I know what most are thinking, it gets put in the designer file so it doesn't matter. Anyone who's done WinForms dev for any amount of time knows you WILL eventually have to go in there and find bugs (Fix the good ol' white screen of death).

Also, when you Generate Members for everything it will make your intellisense list very long, another negative.

This isn't only true for labels, this is true for any control you throw onto your Form. panels, grids, etc. If you never use them in your code base, consider changing the Generate Member to false since you don't use it anyway.

Joseph
+2  A: 

Label's have properties and other state that has to be held in memory. If your label never changes, you can save a little ram by not generating the member. Note that is not going to be the deciding factor in how your app performs, but that doesn't mean you shouldn't save a little ram now and then where you know you can.

It also keeps the label from uselessly cluttering the intellisense list for your form.

One big reason you should generate the member for your label is that it can make it easier to do localization.

Joel Coehoorn
localization? As in for different countries/spoken languages, correct?
Refracted Paladin
Yes. Depending on how you do it, you'll likely need a member to bind a resource or setting to.
Joel Coehoorn
Joel, would you care to emphasize the localization point of view. In which situations would it be more difficult to localize a label without a member variable? TIA.
Serge - appTranslator
Oops, sorry, you answered while I was typing. I don't think you need a member to localize the label: InitializeComponent() will pull the resources contents whether or not the label is a member or a local variable.
Serge - appTranslator
localization isn't something I've had to do much. If I go into specifics I'll just get it wrong. Let's just say that I'm not sure exactly where the border is or how much you can do with the built-in bindings. Though I suppose that places where you'd have trouble with localization are probably the same places where you'd want a member anyway: when the label might change on occasion
Joel Coehoorn
Thank you for following up! Lucky for me localization is not a concern here in Western Wisconsin... :)
Refracted Paladin