Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 Does extract method work in C++ any more?

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
tlyons Posted - Apr 23 2017 : 03:58:03 AM
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.
3   L A T E S T    R E P L I E S    (Newest First)
accord Posted - Apr 23 2017 : 9:38:39 PM
*ah* Good point! Extract method should consider references after the selection:

case=91596
tlyons Posted - Apr 23 2017 : 5:58:07 PM
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).
accord Posted - Apr 23 2017 : 5:44:28 PM
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.

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