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
 Refactoring - extract free function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Suma
New Member

6 Posts

Posted - Jul 30 2013 :  08:58:39 AM  Show Profile  Reply with Quote
When the C++ snippet being extracted by Extract method does not reference any members, the function could be extracted as a free function. If this is not possible to detect automatically, user could be given an option to extract as a free functions. A free function would be extracted directly to the source in which extraction happens, as close above the extraction place as possible, i.e before the current function begins.

feline
Whole Tomato Software

United Kingdom
15980 Posts

Posted - Jul 30 2013 :  09:40:56 AM  Show Profile  Reply with Quote
Is this something you often want to do? Most people seem to want to put as much code as possible into functions, minimising the number of free functions.

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

Suma
New Member

6 Posts

Posted - Jul 30 2013 :  10:22:56 AM  Show Profile  Reply with Quote
Not often, but when I do, doing it with current functionality is a bit cumbersome.

A most common example is a small computation function, like in your example of AreaOfCircle in http://www.wholetomato.com/products/features/extractmethod.asp
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
15980 Posts

Posted - Jul 30 2013 :  11:27:47 AM  Show Profile  Reply with Quote
Which bit is cumbersome? VA Outline is designed to help you easily move functions around in the current file, via drag and drop, or cut and paste. Alt-G will take you to the function declaration in the header file, which can then be deleted, then its just Alt-O back to the cpp file to delete the class name on the function implementation.

A few steps, but I am not sure it is worth adding this to Extract Method for occasional use.

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

Suma
New Member

6 Posts

Posted - Aug 12 2013 :  04:50:01 AM  Show Profile  Reply with Quote
I have tried it again. Most cumbersome is that when the function is declared in the header file and I extract it from it, the header file is still "changed" and all dependencies need to be rebuilt.

I cannot use "Undo" to return the header into the unchanged state, after the implementation is moved to the source file, as this undos both files simulaneously.

Edited by - Suma on Aug 12 2013 04:54:01 AM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
15980 Posts

Posted - Aug 12 2013 :  8:47:29 PM  Show Profile  Reply with Quote
Ah, I see your problem now, thank you for the clear explanation. I have put in a feature request to allow Extract Method to create a free function. I had not thought of this problem, but its obvious when you point it out:

case=76113

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

jay.carlton
Ketchup Master

USA
65 Posts

Posted - Aug 26 2013 :  4:40:39 PM  Show Profile  Reply with Quote
FWIW, there are some authors who advise embracing the muilti-paradigm (as opposed to purely OOP) nature of C++:

Scott Meyers has advocated the technique of free functions to keep class sizes down:
http://stackoverflow.com/a/8144342/611672

Also, Lakos makes some arguments for static helper functions, typically to keep dependencies and class sizes in check: http://www.amazon.com/Large-Scale-Software-Design-John-Lakos/dp/0201633620

Maybe it's worth considering separate mechanisms for "extract static function to this implementation file" versus "extract free (API) function (and declare it in the header". It makes a big difference.

HTH.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
15980 Posts

Posted - Aug 26 2013 :  8:11:40 PM  Show Profile  Reply with Quote
Thank you for the links. An interesting counter point to the make everything a class member.

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

ceretullis
New Member

3 Posts

Posted - Jan 28 2014 :  2:00:34 PM  Show Profile  Reply with Quote
I would use extract method to free function very frequently.

In my job, we prefer to keep the class definitions as small as possible. We also practice "clean code" techniques, so we end up with many many functions because functions become labels for clarifying the purpose of the code. It is preferable these functions are free functions limited in scope to the translation unit so that class definitions don't become bloated with private helper functions. We usually prefer to put them in an anonymous namespaces in the .cpp so we know they can't be extern'd from elsewhere.

My typical use case for extract method is refactoring the code to make it cleaner. Generally, 95% of the time I'm wanting to extract method to source as a free function.

Commenting because I would love to see this feature added.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
15980 Posts

Posted - Jan 30 2014 :  9:38:50 PM  Show Profile  Reply with Quote
Thank you for the information and the perspective, its useful to know what people are doing. I have placed a note onto the case about this.

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

sean
Whole Tomato Software

USA
2640 Posts

Posted - Sep 19 2014 :  12:33:16 AM  Show Profile  Reply with Quote
case=76113 is implemented in build 2047
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2019 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000