Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Feature Requests
 Improve "Create Implementation" - Member inits
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

peterchen
Tomato Guru

126 Posts

Posted - Jan 19 2010 :  12:53:04 PM  Show Profile  Reply with Quote
Suggestion (for when you absolutely don't know what else to do ): when we have

// .h
struct Foo
{
   int m_member;
   Foo(int member);
}


"Create Implementation" could give:

//.cpp
Foo:Foo(int member) : m_member(member)
{
}


i.e. automatically add member intialization when "matching" arguments are passed. Of course that should work as well for multiple parameters.

This should extend to other common naming patterns, e.g. member_ / member, member / this->member (I'm not sure if this is valid in an initializer list though...). IMO, match by name is sifficient.

If the initialization is unwanted or incorrect, it is easy to remove or modify - the "important parts" are already in place.


Benefits I hope for:
Member initialization requires repretetive code and - due to the similar symbols - error prone, writing them is fairly annoying. Incremental development and maintenance often add members needing constructor initialization.

What do others think?




"Fallout":
One could also desire automatic initialization of otherwise uninitialized POD members.

Users might argue about different layouts, requiring a format option (e.g. like the other refactoring autotexts)

This could be extended to methods, so that

// .h
// ...
void SetMember(int member)


yields

void Foo::SetMember(int member)
{
   m_member = member;
}


Again, if the initialization is unwanted, it is easy to remove. However, users might then want more elaborate assignments, calling for another autotext, such as

void Foo::SetMember(int member)
{
   if (m_member != member && QueryPropertyChanging(member))
   {
     m_member = member;
     NotifyPropertyChanged();
   }
}

feline
Whole Tomato Software

United Kingdom
18948 Posts

Posted - Jan 25 2010 :  12:38:35 PM  Show Profile  Reply with Quote
We are considering doing something similar:

case=14340

Is the idea of creating a class constructor that takes parameters for and initializes some of the class member variables. So you would select the member variables you wanted the constructor to initialize, probably via VA Outline, and then VA would generate the relevant constructor for you.

This bypasses the problems of matching the parameters with the members. Sometimes it should be "obvious", but I am always wary of words like that, since what is "obvious" to a person is not always so obvious to a program

zen is the art of being at one with the two'ness
Go to Top of Page

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - Jan 25 2010 :  1:31:18 PM  Show Profile  Reply with Quote
I've done a little unintentional parallel work here I've just put in a feature request for this:

case=38674

I'm basically agree with feline, this is not "obvious" and would require additional setup for the coding convention one uses.
quote:
for when you absolutely don't know what else to do )

Edited by - accord on Jan 25 2010 1:33:13 PM
Go to Top of Page

peterchen
Tomato Guru

126 Posts

Posted - Jan 26 2010 :  05:29:51 AM  Show Profile  Reply with Quote
Looking forward to it! :)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000