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
 Create Implementation -> Sorting
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

MrDoomMaster
Tomato Guru

251 Posts

Posted - Mar 21 2007 :  12:52:14 PM  Show Profile  Reply with Quote
Suppose I have the following class with the following member functions:


namespace gui
{
	class ChainedAnimations
	{
	private:
		std::vector<Sprite*> m_sprites;
		bool m_paused;
		u32 m_activeSprite;

	public:
		ChainedAnimations();
		~ChainedAnimations();

		void Tick();
		void Draw( RenderContext& rc );
		void Reset();
		void Pause();
		void Resume();
	};
}


Lets say that I've went through all of the member function prototypes in this class, top to bottom, and used "Create Implementation" on each. In the CPP file we'll have empty function implementations for each member function prototype, all in order as they appear in the header.

Now, take the same class with one added member function (bolded below):


namespace gui
{
	class ChainedAnimations
	{
	private:
		std::vector<Sprite*> m_sprites;
		bool m_paused;
		u32 m_activeSprite;

	public:
		ChainedAnimations();
		~ChainedAnimations();

		void Tick();
		void Draw( RenderContext& rc );
		void Reset();
		void AddSprite( Sprite* spr );
		void Pause();
		void Resume();
	};
}


When I use "Create Implementation" on the new, bolded prototype above, the implementation should be placed in the CPP file below the implementation for "Reset()" but above the implementation for "Pause()". It would be nice if visual assist would sort these implementations for me, as I create them.

There are instances, however, where one programmer may attempt to "organize" the prototypes in the class. It would be nice to be able to open a refactoring menu over the class name in the header file and select something like "Sort Implementations" which would go to the CPP file and sort the implementations as they appear in the header.

This seems like an incredibly difficult feature to support, so I understand if you guys can't do it. But it's just a cool idea I thought I'd share.

Thanks for reading.

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - Mar 21 2007 :  1:14:34 PM  Show Profile  Reply with Quote
I asked about something similar shortly after I first got my hands on VA's refactoring

We are considering letting the user specify the location in the file, or just accepting the default.

case=2161

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

MrDoomMaster
Tomato Guru

251 Posts

Posted - Mar 21 2007 :  2:15:07 PM  Show Profile  Reply with Quote
quote:
Originally posted by feline

We are considering letting the user specify the location in the file, or just accepting the default.



Could you emphasize a little bit more on what you mean by that? If you're talking about letting them specify a line number or something at which to place it, that seems a little bit tedious wouldn't you agree?

Would it be possible to make it more automated? Why not give the user two options:

1) Place the implementation at the end of the file
2) Place the implementation in sequential order

No prompting required. Each option would be fully automated.

Again, I don't want to jump to conclusions. I'm still confused about your statement.

Thanks for the reply Feline.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - Mar 21 2007 :  2:20:40 PM  Show Profile  Reply with Quote
The current idea is to produce a dialog listing the existing methods, and you select the function you want the new implementation or declaration to go after.

Sequential sounds reasonable, but it assumes that the header and cpp file are currently in the same order. When you start working on existing code we cannot make this assumption, so this is not going to work very well

Currently VA does try to group overloads together, and classes together, which is a start.

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

MrDoomMaster
Tomato Guru

251 Posts

Posted - Mar 21 2007 :  3:09:33 PM  Show Profile  Reply with Quote
quote:
Originally posted by feline

The current idea is to produce a dialog listing the existing methods, and you select the function you want the new implementation or declaration to go after.

Sequential sounds reasonable, but it assumes that the header and cpp file are currently in the same order. When you start working on existing code we cannot make this assumption, so this is not going to work very well

Currently VA does try to group overloads together, and classes together, which is a start.



Very true that the initial code-base could be totally non sequential. It is for this reason I suggested the 2nd idea in my initial post, which was the ability to "Sort Implementations" via a refactoring menu specific to the class. If you're starting out in an existing code-base that has implementations out of order, this feature would provide VAX with a way to make them sequential so that create implementation will work.

However, now that I understand what you meant by a "prompt", I tend to like your idea better. However it does not allow the user to automatically sort unorganized implementations. To do this the user would be forced to cut/paste to order it properly.

Thanks :)
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - Mar 22 2007 :  09:20:44 AM  Show Profile  Reply with Quote
Sorting, or just re-ordering the implementations in a cpp file has come up before, but personally I am very wary of this idea, since it is so hard to define an "implementation". The actual block of code is clear enough, but what about associated comment blocks? If you jumble up the code and the comments you will end up with quite a mess, but there is no obvious and reliable method for VA to understand what comment is associated with which implementation.

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

sl@sh
Tomato Guru

Switzerland
204 Posts

Posted - Mar 22 2007 :  10:33:14 AM  Show Profile  Reply with Quote
Sorting might actually invalidate working code. For instance if the implementation file contains #define statements in between, or #ifdef blocks, automatically sorting parts of the code might lead to something that doesn't compile - or worse: it does compile to something different than intended.

Even if there are no preprocessor directives, typedefs and declarations in the middle of an implementation file might cause compiler errors if implementations are moved above them. Of course, those declarations shouldn't be there in the first place, but never make assumptions on existing code. As a matter of fact, Bjarne Stroustrup himself suggested the practice of putting declarations right at the position where they are needed, and not at the top! (ok, the book I'm referring to is 10 years old, maybe he has revised his opinion in the meantime)
Go to Top of Page

MrDoomMaster
Tomato Guru

251 Posts

Posted - Mar 22 2007 :  2:30:26 PM  Show Profile  Reply with Quote
All very good points. I had not thought of the "difficult" case when I made my proposal :)

I'm perfectly happy with the original presentation of ideas in the case listed above. A dialog prompt with a position to place implementations would be suitable enough for me :)

Thanks guys!
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