Thread: this pointer?

  1. #31
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by brewbuck View Post
    I still don't grok the argument. It sounds like you're saying that coding standards are dangerous because people might forget to use them. Okay... People also forget to update comments, they rely on undocumented and fragile behavior, they don't validate input, they don't check array bounds before accessing, etc. It seems like the safest practice is to just not write any code at all because somebody might make a mistake.

    Suppose there is a coding standard in place that says "Every variable must be initialized at the point of declaration." I suppose you take issue with this as well, because somebody may forget to adhere? And the answer is to deliberately not initialize variables?
    I said I don't like the fact that style-related "standards" dominate every standards doc I've ever seen, as opposed to those that encourage/enforce good programming practices. We *should* be looking for things like programming errors instead of wasting time dotting i's and crossing t's.
    Last edited by medievalelks; 03-25-2009 at 05:47 AM.

  2. #32
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by medievalelks View Post
    I said I don't like the fact that style-related "standards" dominate every standards doc I've ever seen, as opposed to those that encourage/enforce good programming practices. We *should* be looking for things like programming errors instead of wasting time dotting i's and crossing t's.
    The coding standards I had long ago were over 95% coding standards and only a few style guidelines such as always use tabs to indent (and set the IDE tab size to 4), use m_ for member variables, and start public functions with capital letters and private/protecteds with small letters.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  3. #33
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    I find the "this" pointer useful when working with arrays of class objects

    Code:
    class Example{
      private:
        int value;
      public:
        void dispValue(void);
    };
    
    int main()
    {
    
      Example stuff[10];
      int i;
    
      for (i = 0; i < 10; ++i)
        stuff[i].dispValue();
    }
    
    void Example::dispValue(void)
    {
      cout << this->value;
    }
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  4. #34
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    this-> is not necessary at all in this example.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #35
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by cpjust View Post
    The coding standards I had long ago were over 95% coding standards and only a few style guidelines such as always use tabs to indent (and set the IDE tab size to 4), use m_ for member variables, and start public functions with capital letters and private/protecteds with small letters.
    That sounds good. Maybe I'm jaded by numerous bad experiences. BTW, the C++ FAQ has a good section on this topic.

  6. #36
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by medievalelks View Post
    I said I don't like the fact that style-related "standards" dominate every standards doc I've ever seen, as opposed to those that encourage/enforce good programming practices. We *should* be looking for things like programming errors instead of wasting time dotting i's and crossing t's.
    I can agree with that.

    The standards document at my workplace specifically indicates NOT to use Hungarian notation, and gives some very good justifications for that (mostly in regard to its uselessness at preventing any real kind of problem). I've never been a fan of it, and would never use it myself unless forced. But an "m_" sort of prefix, in my mind, is not Hungarian notation but something different.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  7. #37
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    I hope Elysia doesn't work there :-)

    I agree that the m_ thing is a completely different animal than the innately evil, will-sapping Hungarian Notation. :-)

  8. #38
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I used to use Hungarian notation all the time when I started programming, but now I don't care. I might use a p prefix to indicate a pointer, but that's about it.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  9. #39
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    I wonder how much HN-infested code has changed when char * variables where changed to std::string and vice versa. And how much was not changed.
    Last edited by medievalelks; 03-25-2009 at 10:23 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  2. Quick Pointer Question
    By gwarf420 in forum C Programming
    Replies: 15
    Last Post: 06-01-2008, 03:47 PM
  3. Parameter passing with pointer to pointer
    By notsure in forum C++ Programming
    Replies: 15
    Last Post: 08-12-2006, 07:12 AM
  4. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM