Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Deprecating THISBACK (Post 2020.2 release)
Deprecating THISBACK [message #55122] Mon, 12 October 2020 22:31 Go to next message
Klugier is currently offline  Klugier
Messages: 795
Registered: September 2012
Location: Poland, Kraków
Contributor
Hello,

I had the discussion with Mirek about this article https://evileg.com/en/post/629/ he found that the user uses deprecated THISBACK construction. Well we deprecated it in the documentation in favor or lambdas or newer c++ constructions such as Function, Gate etc.

In c++14 which we targets on all platforms the solution is easy. We can deprecate it on compilation level, which means something. Just mark THISBACK with deprecated atribute like this:
[[deprecated("THISBACK is deprecated use lambda instead.")]]
const int thisbackd = 0;

#define THISBACK(x)                  callback(this  + thisbackd, &CLASSNAME::x)
#define THISBACK1(x, arg)            callback1(this + thisbackd, &CLASSNAME::x, arg)
#define THISBACK2(m, a, b)           callback2(this + thisbackd, &CLASSNAME::m, a, b)
#define THISBACK3(m, a, b, c)        callback3(this + thisbackd, &CLASSNAME::m, a, b, c)
#define THISBACK4(m, a, b, c, d)     callback4(this + thisbackd, &CLASSNAME::m, a, b, c, d)
#define THISBACK5(m, a, b, c, d, e)  callback5(this + thisbackd, &CLASSNAME::m, a, b, c, d,e)

Then in all places when THISBACK is used the warning pop up "/home/klugier/upp/uppsrc/CtrlLib/FileSel.h (239): warning: 'thisbackd' is deprecated: THISBACK is deprecated use lambda instead. [-Wdeprecated-declarations]".

If you are not aware how you should replace thisback. Example below:
void MyWidnow::ErrorMenu(Bar& bar)
    // bar.Add("Copy all", THISBACK1(CopyError, true));
    bar.Add("Copy all", [=] { CopyError(true); });

    // In the header file no need for "typedef MyWindow CLASSNAME" declaration...


I think we have multiple places when [[deprecated]] macro can be used. If you search for "deprecated" in uppsrc then there is around 52 entries... Definitely not the topic for 2020.2, but for 2021.1...

Klugier


Ultimate++ - one framework to rule them all.

[Updated on: Tue, 13 October 2020 11:29]

Report message to a moderator

Re: Deprecating THISBACK [message #55125 is a reply to message #55122] Mon, 12 October 2020 23:25 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12954
Registered: November 2005
Ultimate Member
Klugier wrote on Mon, 12 October 2020 22:31
Hello,

I had the discussion with Mirek about this article https://evileg.com/en/post/629/ he found that the user uses deprecated THISBACK construction. Well we deprecated it in the documentation in favor or lambdas or newer c++ constructions such as Function, Gate etc.

In c++14 which we targets on all platforms the solution is easy. We can deprecate it on compilation level, which means something. Just mark THISBACK with deprecated atribute like this:
[[deprecated("THISBACK is deprecated use lambda instead.")]]
const int thisbackd = 0;

#define THISBACK(x)                  callback(this  + thisbackd, &CLASSNAME::x)
#define THISBACK1(x, arg)            callback1(this + thisbackd, &CLASSNAME::x, arg)
#define THISBACK2(m, a, b)           callback2(this + thisbackd, &CLASSNAME::m, a, b)
#define THISBACK3(m, a, b, c)        callback3(this + thisbackd, &CLASSNAME::m, a, b, c)
#define THISBACK4(m, a, b, c, d)     callback4(this + thisbackd, &CLASSNAME::m, a, b, c, d)
#define THISBACK5(m, a, b, c, d, e)  callback5(this + thisbackd, &CLASSNAME::m, a, b, c, d,e)

Then in all places when THISBACK is used the warning pop up "/home/klugier/upp/uppsrc/CtrlLib/FileSel.h (239): warning: 'thisbackd' is deprecated: THISBACK is deprecated use lambda instead. [-Wdeprecated-declarations]".

I think we have multiple places when [[deprecated]] macro can be used. If you search for "deprecated" in uppsrc then there is around 52 entries... Definitely not the topic for 2020.2, but for 2021.1...

Klugier


I generally hate this. This would mean that I would have to fix a tons of code to avoid that warning for no good reason. Like a week of work...

Mirek
Re: Deprecating THISBACK [message #55128 is a reply to message #55125] Tue, 13 October 2020 00:28 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 795
Registered: September 2012
Location: Poland, Kraków
Contributor
Hello Mirek,

I like your message - it is funny Smile This is the task for student or someone who would like to help in terms of uppsrc. I can imagine first job in coputer software industry when you need to replace THISBACK with lambda Smile You are doing this for your tow weeks, but finally you are proud of yourself that you manage to do it.

From the high standards of software development process this is action in good direction. In the end we will have better code without THISBACK and typedef declaration and after 2/3 years we could completely remove THISBACK code base.

I compiled TheIDE with deprication for THISBACK and there are 1275 warnings...

Klugier


Ultimate++ - one framework to rule them all.
Re: Deprecating THISBACK [message #55129 is a reply to message #55128] Tue, 13 October 2020 00:36 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12954
Registered: November 2005
Ultimate Member
Klugier wrote on Tue, 13 October 2020 00:28
Hello Mirek,

I like your message - it is funny Smile This is the task for student or someone who would like to help in terms of uppsrc. I can imagine first job in coputer software industry when you need to replace THISBACK with lambda Smile You are doing this for your tow weeks, but finally you are proud of yourself that you manage to do it.


You do not understand. The problem is not the U++ sources.

I am currently maintaining 2 mission critical applications. The simpler one contains only 1800 THISBACKs. Think of all errors I would introduce by "fixing" it.

And this would be the same for every single user. I hate it when I am forced to rewrite perfectly good code for some stupid reason like somebody feels that some feature is not fancy anymore.

Attribute that produces warning is not a good path. Better is flag. Or maybe the attribute activated by flag. But then again, if it is flag, it can as well be compilation error.

Mirek

[Updated on: Tue, 13 October 2020 00:41]

Report message to a moderator

Re: Deprecating THISBACK [message #55158 is a reply to message #55129] Thu, 15 October 2020 00:10 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 795
Registered: September 2012
Location: Poland, Kraków
Contributor
Hello,

Backing to this problem. I see that several templates (.upt) have CLASSNAME declaration. From my perspective the good idea would be to remove that declaration. After that all new code shouldn't have dependency to THISBACK:

CtrlLib/Complex.upt:
...
class <:classname:> : public <:lay > 1 ? "With" + classname + "Layout<TopWindow>" : "TopWindow":> {
public:
	typedef <:classname:> CLASSNAME;
	<:classname:>();
};
...


Could be:
...
class <:classname:> : public <:lay > 1 ? "With" + classname + "Layout<TopWindow>" : "TopWindow":> {
public:
	<:classname:>();
};
...


Skylark and Tutrle templates are also affected...

Klugier


Ultimate++ - one framework to rule them all.

[Updated on: Thu, 15 October 2020 00:11]

Report message to a moderator

Re: Deprecating THISBACK [message #55160 is a reply to message #55158] Thu, 15 October 2020 01:01 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12954
Registered: November 2005
Ultimate Member
Klugier wrote on Thu, 15 October 2020 00:10
Hello,

Backing to this problem. I see that several templates (.upt) have CLASSNAME declaration. From my perspective the good idea would be to remove that declaration. After that all new code shouldn't have dependency to THISBACK:

CtrlLib/Complex.upt:
...
class <:classname:> : public <:lay > 1 ? "With" + classname + "Layout<TopWindow>" : "TopWindow":> {
public:
	typedef <:classname:> CLASSNAME;
	<:classname:>();
};
...


Could be:
...
class <:classname:> : public <:lay > 1 ? "With" + classname + "Layout<TopWindow>" : "TopWindow":> {
public:
	<:classname:>();
};
...


Skylark and Tutrle templates are also affected...

Klugier


Agreed. Will do.

Mirek
Re: Deprecating THISBACK [message #55161 is a reply to message #55160] Thu, 15 October 2020 01:14 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 791
Registered: August 2007
Contributor
Hi,

FYI, since you've agreed, I have removed the CLASSNAME declaration from the Turtle upt. Smile

Best regards,
Oblivion


Re: Deprecating THISBACK [message #55485 is a reply to message #55161] Sun, 15 November 2020 00:44 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 795
Registered: September 2012
Location: Poland, Kraków
Contributor
Hello Mirek,

We should also remove CLASSNAME from layout visgen for consistancy:
index.php?t=getfile&id=6280&private=0

Klugier


Ultimate++ - one framework to rule them all.
Re: Deprecating THISBACK [message #55487 is a reply to message #55485] Sun, 15 November 2020 00:58 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12954
Registered: November 2005
Ultimate Member
Good catch, yes!
Re: Deprecating THISBACK [message #55488 is a reply to message #55485] Sun, 15 November 2020 01:42 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12954
Registered: November 2005
Ultimate Member
Done.
Re: Deprecating THISBACK [message #55497 is a reply to message #55122] Mon, 16 November 2020 00:58 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 362
Registered: March 2007
Senior Member
Hi Klugier:

Thank you very much for all your effort!

As I go through current U++ document, in particular in this link
https://www.ultimatepp.org/srcdoc$CtrlLib$Tutorial$en-us.htm l#13

I still see references to THISBACK and CLASSNAME (just search in the webpage). I believe it should be revised to reflect current U++ trends and save some trouble for newcomers.

Thanks,
Lance
Re: Deprecating THISBACK [message #55501 is a reply to message #55497] Mon, 16 November 2020 23:37 Go to previous message
Klugier is currently offline  Klugier
Messages: 795
Registered: September 2012
Location: Poland, Kraków
Contributor
Hello Lance,

Thanks for reporting! I removed all THISBACK and CLASSNAME from GUI tutorial. Please see tomorrows version. There are probably other places, but GUI tutorial is the most significant one.

Klugier


Ultimate++ - one framework to rule them all.
Previous Topic: Change in <Core/Sort.h> breaks my code
Next Topic: Add compilable testcases for nontrivial problems!
Goto Forum:
  


Current Time: Sat Nov 28 23:47:52 CET 2020

Total time taken to generate the page: 0.02199 seconds