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
 Technical Support
 Does extract method work in C++ any more?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tlyons
New Member

United Kingdom
2 Posts

Posted - Apr 23 2017 :  03:58:03 AM  Show Profile  Reply with Quote
I have been using this software for years, and have always regarded "extract method" as one of the most useful features - as it allowed one to see at a glance, through the signature of the proposed method, the dependencies of a block of code. Often this was all that was needed to rewrite the code better.

Recently this really does not seem to be the case, and your software cannot be relied on to produce code that works after the extraction.

Here is a simple example:



// OrderedTreeTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <initializer_list>
#include "OrderedTreeLib/Tree.h"



typedef basic_tree<trivial, std::vector> BodyPart;

size_t myTree[] = { 123 , 54, 32, 53, 44, 66, 21, 5 };
int main()
{
for (auto& x : myTree)
{
std::cout << x << " ";
}
std::cout << std::endl;
BodyPart t1(std::begin(myTree), std::end(myTree));
std::cout << t1 << "\n";

auto&& heap = t1.max_heap();

for (auto& x : heap)
{
std::cout << x << " ";
}
std::cout << std::endl;
BodyPart t2(std::begin(heap), std::end(heap));
std::cout << t2 << "\n";

return 0;
}



I wanted to extract the duplicated code:

for (auto& x : myTree)
{
std::cout << x << " ";
}
std::cout << std::endl;
BodyPart t1(std::begin(myTree), std::end(myTree));
std::cout << t1 << "\n";

and it offered to create a method with no arguments! Clearly this cannot work.

A reference to myTree is required and returning t1 in some form to the main code is also required. A signature such as

BodyPart Method(const size_t* myTree)

and embedding in the code:

auto&& t1 = Method(myTree);

seem about right. I appreciate that with the rapidly changing language this must be quite a challenge to keep up with. But it is a functionality that was impressive and if you can no longer deliver it I think it would be helpful to have warnings and clarity as to what you cannot do.

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - Apr 23 2017 :  5:44:28 PM  Show Profile  Reply with Quote
Extract method only includes variables that aren't declared inside the selection you are about the extract. I think your code would still compile after extracting it without parameters.
Go to Top of Page

tlyons
New Member

United Kingdom
2 Posts

Posted - Apr 23 2017 :  5:58:07 PM  Show Profile  Reply with Quote
Thanks for the quick response. I agree that the myTree does not need to be a parameter; however the line

auto&& heap = t1.max_heap();

below the selection refers to the variable t1 declared in the selection; surely returning void will break the code.

So I understand now this is a limitation of the product. However, perhaps you could return the variable t1 and capture it for read and write with a && style reference (two ampersands to allow non-const access on exit).
Go to Top of Page

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - Apr 23 2017 :  9:38:39 PM  Show Profile  Reply with Quote
*ah* Good point! Extract method should consider references after the selection:

case=91596
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