Stigma attached to "this"

Discussion in 'C++' started by gw7rib@aol.com, Apr 8, 2008.

  1. Guest

    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.
    , Apr 8, 2008
    #1
    1. Advertising

  2. Jim Langston Guest

    wrote:
    > 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; }


    --
    Jim Langston
    Jim Langston, Apr 8, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Deen
    Replies:
    2
    Views:
    502
    Gregory Toomey
    Jul 4, 2004
  2. Jason
    Replies:
    5
    Views:
    440
    Frank Mamone
    Sep 14, 2004
  3. =?Utf-8?B?RG9ydGU=?=
    Replies:
    4
    Views:
    6,509
    =?Utf-8?B?RG9ydGU=?=
    Nov 23, 2004
  4. Steve
    Replies:
    3
    Views:
    414
    Robert Smith
    Jul 16, 2005
  5. MasterChief

    Gridview attached to Drop-down

    MasterChief, Feb 27, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    462
    Christopher Reed
    Mar 3, 2006
Loading...

Share This Page