Default constructors
Hey all, The project i'm working on at the moment has some generated code from a tool called MyGeneration TOOL. It has marked the default constructors of the Data classes with: [Obsolete("For serialization only", false)] It would seem that they have ignored this and are using the default constructors and then populating the properties, rather than calling the overloads with parameters. In some cases it seems quite valid to just call the default constructor (ie a new data object yet to be populated for example). I've done some searching and can't find any justification for marking the default constructors Obsolete. Given that the code is generated and then manually pasted into the classes I'm tempted to just remove the Obsolete attributes. It would clean up the Warnings generated drastically. Just want to figure out if it might bite me for some reason down the track. flames, opinions, ideas, suggestions and feedback welcome :) cheers, Stephen
Re: Default constructors
Hi Stephen, The ObsoleteAttribute is a signal of intent. It basically tells developers "this will stop working in a future version so stop using it". The way it has been used in your case (from your description) it is also a declaration of intent. It's saying "this is in use by me but you shouldn't use it". I'd argue that the constructor is not obsolete (and probably never will be). This intent could be made clearer by changing the visibility on those constructors to internal (if possible). I'd remove those attributes and get back to a clean (0 warning) build. They're just noise. Regards, Mike Michael M. Minutillo Indiscriminate Information Sponge http://codermike.com On Wed, Mar 6, 2013 at 12:59 PM, Stephen Price wrote: > Hey all, > > The project i'm working on at the moment has some generated code from a > tool called MyGeneration TOOL. It has marked the default constructors of > the Data classes with: > > [Obsolete("For serialization only", false)] > > It would seem that they have ignored this and are using the default > constructors and then populating the properties, rather than calling the > overloads with parameters. In some cases it seems quite valid to just call > the default constructor (ie a new data object yet to be populated for > example). > > I've done some searching and can't find any justification for marking the > default constructors Obsolete. Given that the code is generated and then > manually pasted into the classes I'm tempted to just remove the Obsolete > attributes. It would clean up the Warnings generated drastically. Just want > to figure out if it might bite me for some reason down the track. > > flames, opinions, ideas, suggestions and feedback welcome :) > cheers, > Stephen >
Re: Default constructors
Hi Stephen, Just taking a stab at it. Are any of the parameters in the overloaded constructors dependencies of the object being constructed? If the object requires these dependencies that would be a good reason to force the paramaterized constructors, as using the default would potentially leave the object in an unworkable state. Cheers Dave On 6 March 2013 15:59, Stephen Price wrote: > Hey all, > > The project i'm working on at the moment has some generated code from a > tool called MyGeneration TOOL. It has marked the default constructors of > the Data classes with: > > [Obsolete("For serialization only", false)] > > It would seem that they have ignored this and are using the default > constructors and then populating the properties, rather than calling the > overloads with parameters. In some cases it seems quite valid to just call > the default constructor (ie a new data object yet to be populated for > example). > > I've done some searching and can't find any justification for marking the > default constructors Obsolete. Given that the code is generated and then > manually pasted into the classes I'm tempted to just remove the Obsolete > attributes. It would clean up the Warnings generated drastically. Just want > to figure out if it might bite me for some reason down the track. > > flames, opinions, ideas, suggestions and feedback welcome :) > cheers, > Stephen >
Re: Default constructors
Thanks guys, sounds like i'm on the right track. Dave, the objects look just like generated DTOs, so if they were passed about empty then its probably better covered with validation (client/server), but I get what you mean. They wouldn't be much use empty but I think there are other ways to indicate the intent than the Obsolete attribute. I like Mike's answer too, If only because it matched with my feelings about it. :) cheers! Stephen On Wed, Mar 6, 2013 at 1:09 PM, David Burstin wrote: > Hi Stephen, > > Just taking a stab at it. Are any of the parameters in the overloaded > constructors dependencies of the object being constructed? If the object > requires these dependencies that would be a good reason to force the > paramaterized constructors, as using the default would potentially leave > the object in an unworkable state. > > Cheers > Dave > > > On 6 March 2013 15:59, Stephen Price wrote: > >> Hey all, >> >> The project i'm working on at the moment has some generated code from a >> tool called MyGeneration TOOL. It has marked the default constructors of >> the Data classes with: >> >> [Obsolete("For serialization only", false)] >> >> It would seem that they have ignored this and are using the default >> constructors and then populating the properties, rather than calling the >> overloads with parameters. In some cases it seems quite valid to just call >> the default constructor (ie a new data object yet to be populated for >> example). >> >> I've done some searching and can't find any justification for marking the >> default constructors Obsolete. Given that the code is generated and then >> manually pasted into the classes I'm tempted to just remove the Obsolete >> attributes. It would clean up the Warnings generated drastically. Just want >> to figure out if it might bite me for some reason down the track. >> >> flames, opinions, ideas, suggestions and feedback welcome :) >> cheers, >> Stephen >> > >
Re: Default constructors
Hi I delete them, i first encountered them while doing nhibernate work. But it meant that i could not get the code coverage of my unit tests to where i wanted. So i deleted them and spent an hour writing coverage tests. .02c Davy Sent from my starfleet datapad. On 6 mars 2013, at 06:15, Stephen Price wrote: Thanks guys, sounds like i'm on the right track. Dave, the objects look just like generated DTOs, so if they were passed about empty then its probably better covered with validation (client/server), but I get what you mean. They wouldn't be much use empty but I think there are other ways to indicate the intent than the Obsolete attribute. I like Mike's answer too, If only because it matched with my feelings about it. :) cheers! Stephen On Wed, Mar 6, 2013 at 1:09 PM, David Burstin wrote: > Hi Stephen, > > Just taking a stab at it. Are any of the parameters in the overloaded > constructors dependencies of the object being constructed? If the object > requires these dependencies that would be a good reason to force the > paramaterized constructors, as using the default would potentially leave > the object in an unworkable state. > > Cheers > Dave > > > On 6 March 2013 15:59, Stephen Price wrote: > >> Hey all, >> >> The project i'm working on at the moment has some generated code from a >> tool called MyGeneration TOOL. It has marked the default constructors of >> the Data classes with: >> >> [Obsolete("For serialization only", false)] >> >> It would seem that they have ignored this and are using the default >> constructors and then populating the properties, rather than calling the >> overloads with parameters. In some cases it seems quite valid to just call >> the default constructor (ie a new data object yet to be populated for >> example). >> >> I've done some searching and can't find any justification for marking the >> default constructors Obsolete. Given that the code is generated and then >> manually pasted into the classes I'm tempted to just remove the Obsolete >> attributes. It would clean up the Warnings generated drastically. Just want >> to figure out if it might bite me for some reason down the track. >> >> flames, opinions, ideas, suggestions and feedback welcome :) >> cheers, >> Stephen >> > >