Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 Refactoring - extract free function

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
Suma Posted - Jul 30 2013 : 08:58:39 AM
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.

10   L A T E S T    R E P L I E S    (Newest First)
sean Posted - Sep 19 2014 : 12:33:16 AM
case=76113 is implemented in build 2047
feline Posted - Jan 30 2014 : 9:38:50 PM
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.
ceretullis Posted - Jan 28 2014 : 2:00:34 PM
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.
feline Posted - Aug 26 2013 : 8:11:40 PM
Thank you for the links. An interesting counter point to the make everything a class member.
jay.carlton Posted - Aug 26 2013 : 4:40:39 PM
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.
feline Posted - Aug 12 2013 : 8:47:29 PM
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
Suma Posted - Aug 12 2013 : 04:50:01 AM
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.
feline Posted - Jul 30 2013 : 11:27:47 AM
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.
Suma Posted - Jul 30 2013 : 10:22:56 AM
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
feline Posted - Jul 30 2013 : 09:40:56 AM
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.

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000