Stigma attached to "this"

G

gw7rib

I was modifying a program recently, and felt that I hadn't really got
the responsibilities of the various classes quite right. Consequently
I was having to use "this" a lot. It got me thinking - do people use
the presence of "this" to suggest that there might be problems? Do
they view it, like "goto", as something for which there are legitimate
uses but which in general indicates that a piece of code has not been
fully thought through? Or does it have no such stigma?

All thoughts welcome!
Paul.
 
J

Jim Langston

I was modifying a program recently, and felt that I hadn't really got
the responsibilities of the various classes quite right. Consequently
I was having to use "this" a lot. It got me thinking - do people use
the presence of "this" to suggest that there might be problems? Do
they view it, like "goto", as something for which there are legitimate
uses but which in general indicates that a piece of code has not been
fully thought through? Or does it have no such stigma?

All thoughts welcome!
Paul.

In my own code I almost never use this. Mainly because I don't have
parameters the same name as class variables.

There are a few schemes people use to make sure that class variables are not
the same as parameters, the one I use is suceeding all class variables with
an underscore. I.E.

class Foo
{
public:
void DoSomething( int Bar ) { Bar_ = Bar; }
private:
int Bar_;
};

If the class variable was the same as the parameter then I'd have to use
this:
void DoSomething( int Bar ) { this->Bar = Bar; }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top